# Path: ronin/utils/strings.py
# def stringify(value):
#     """
#     Casts the value to a Unicode string. If the value is a function, calls it using
#     :func:`ronin.contexts.current_context` as its only argument, and recurses until a
#     non-FunctionType value is returned.
#     
#     None values are preserved, whether None is directly sent to this function or is the return
#     value of function argument.
#     
#     This function is the heart of Rōnin's deferred value capability, as it allows lambdas to be
#     passed around instead of strings.
#     
#     :param value: value or None
#     :type value: str|FunctionType
#     :returns: stringified value or None
#     :rtype: str
#     """
#     
#     if value is None:
#         return None
#     elif hasattr(value, '__call__'):
#         with current_context() as ctx:
#             value = value(ctx)
#         return stringify(value)
#     else:
#         try:
#             return to_str(value)
#         except UnicodeDecodeError:
#             return str(value).decode(_ENCODING)
# 
# def stringify_list(values):
#     """
#     Calls :func:`stringify` on all elements. Return values of None are preserved.
#     
#     :param values: values
#     :type values: []
#     :returns: values
#     :rtype: [str]
#     """
#     
#     return [stringify(v) for v in values]
# 
# Path: ronin/contexts.py
# def current_context(immutable=True):
#     """
#     Returns the current context if there is one, otherwise raises :class:`NoContextException`.
#     
#     By default, the context will be treated as immutable.
#     
#     :param immutable: set to False in order to allow changes to the context
#     :type immutable: bool
#     :returns: current context
#     :rtype: :class:`Context`
#     """
# 
#     ctx = Context._peek_thread_local()
#     if ctx is None:
#         raise NoContextException()
#     return Context(ctx, True) if immutable else ctx


from .strings import stringify, stringify_list
from ..contexts import current_context
from glob2 import glob as glob2
import os
    
    with current_context() as ctx:
        return join_path(ctx.get('paths.input'), *segments)


def glob(pattern, path=None, hidden=False, dirs=False):
    """
    Returns a list of real path strings matching the pattern. If ``path`` is not specified,
    the pattern is implicitly joined to the context's ``paths.input``.
    
    Use "?" to match a single character, "\*" to match zero or more characters, and "\*\*" to match
    zero or more path segments.
    
    Note that this implementation improves on Python's standard :func:`glob.glob` by supporting
    "\*\*" correctly.
    
    :param pattern: pattern; calls :func:`ronin.utils.strings.stringify` on it
    :type pattern: str|FunctionType
    :param path: join the pattern to this path (when None, defaults to the context's
     ``paths.input``); calls :func:`ronin.utils.strings.stringify` on it
    :type path: str|FunctionType
    :param hidden: set to True to include hidden files
    :type hidden: bool
    :param dirs: set to True to include directories
    :type dirs: bool
    :returns: zero or more full paths to files (and optionally directories) matching the pattern
    :rtype: [str]
    """

    if path is None:

# Path: ronin/utils/strings.py
# def stringify(value):
#     """
#     Casts the value to a Unicode string. If the value is a function, calls it using
#     :func:`ronin.contexts.current_context` as its only argument, and recurses until a
#     non-FunctionType value is returned.
#     
#     None values are preserved, whether None is directly sent to this function or is the return
#     value of function argument.
#     
#     This function is the heart of Rōnin's deferred value capability, as it allows lambdas to be
#     passed around instead of strings.
#     
#     :param value: value or None
#     :type value: str|FunctionType
#     :returns: stringified value or None
#     :rtype: str
#     """
#     
#     if value is None:
#         return None
#     elif hasattr(value, '__call__'):
#         with current_context() as ctx:
#             value = value(ctx)
#         return stringify(value)
#     else:
#         try:
#             return to_str(value)
#         except UnicodeDecodeError:
#             return str(value).decode(_ENCODING)
# 
# def stringify_list(values):
#     """
#     Calls :func:`stringify` on all elements. Return values of None are preserved.
#     
#     :param values: values
#     :type values: []
#     :returns: values
#     :rtype: [str]
#     """
#     
#     return [stringify(v) for v in values]
# 
# Path: ronin/contexts.py
# def current_context(immutable=True):
#     """
#     Returns the current context if there is one, otherwise raises :class:`NoContextException`.
#     
#     By default, the context will be treated as immutable.
#     
#     :param immutable: set to False in order to allow changes to the context
#     :type immutable: bool
#     :returns: current context
#     :rtype: :class:`Context`
#     """
# 
#     ctx = Context._peek_thread_local()
#     if ctx is None:
#         raise NoContextException()
#     return Context(ctx, True) if immutable else ctx


# Path: ronin/utils/paths.py
from .strings import stringify, stringify_list
from ..contexts import current_context
from glob2 import glob as glob2
import os

    
    with current_context() as ctx:
        return join_path(ctx.get('paths.input'), *segments)


def glob(pattern, path=None, hidden=False, dirs=False):
    """
    Returns a list of real path strings matching the pattern. If ``path`` is not specified,
    the pattern is implicitly joined to the context's ``paths.input``.
    
    Use "?" to match a single character, "\*" to match zero or more characters, and "\*\*" to match
    zero or more path segments.
    
    Note that this implementation improves on Python's standard :func:`glob.glob` by supporting
    "\*\*" correctly.
    
    :param pattern: pattern; calls :func:`ronin.utils.strings.stringify` on it
    :type pattern: str|FunctionType
    :param path: join the pattern to this path (when None, defaults to the context's
     ``paths.input``); calls :func:`ronin.utils.strings.stringify` on it
    :type path: str|FunctionType
    :param hidden: set to True to include hidden files
    :type hidden: bool
    :param dirs: set to True to include directories
    :type dirs: bool
    :returns: zero or more full paths to files (and optionally directories) matching the pattern
    :rtype: [str]
    """

    if path is None:

        with current_context() as ctx: