# Path: airy/utils/encoding.py
# def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
#     """
#     Similar to smart_unicode, except that lazy instances are resolved to
#     strings, rather than kept as lazy objects.
# 
#     If strings_only is True, don't convert (some) non-string-like objects.
#     """
#     # Handle the common case first, saves 30-40% in performance when s
#     # is an instance of unicode. This function gets called often in that
#     # setting.
#     if isinstance(s, unicode):
#         return s
#     if strings_only and is_protected_type(s):
#         return s
#     try:
#         if not isinstance(s, basestring,):
#             if hasattr(s, '__unicode__'):
#                 s = unicode(s)
#             else:
#                 try:
#                     s = unicode(str(s), encoding, errors)
#                 except UnicodeEncodeError:
#                     if not isinstance(s, Exception):
#                         raise
#                     # If we get to here, the caller has passed in an Exception
#                     # subclass populated with non-ASCII data without special
#                     # handling to display as a string. We need to handle this
#                     # without raising a further exception. We do an
#                     # approximation to what the Exception's standard str()
#                     # output should be.
#                     s = ' '.join([force_unicode(arg, encoding, strings_only,
#                             errors) for arg in s])
#         elif not isinstance(s, unicode):
#             # Note: We use .decode() here, instead of unicode(s, encoding,
#             # errors), so that if s is a SafeString, it ends up being a
#             # SafeUnicode at the end.
#             s = s.decode(encoding, errors)
#     except UnicodeDecodeError, e:
#         if not isinstance(s, Exception):
#             raise DjangoUnicodeDecodeError(s, *e.args)
#         else:
#             # If we get to here, the caller has passed in an Exception
#             # subclass populated with non-ASCII bytestring data without a
#             # working unicode method. Try to handle this without raising a
#             # further exception by individually forcing the exception args
#             # to unicode.
#             s = ' '.join([force_unicode(arg, encoding, strings_only,
#                     errors) for arg in s])
#     return s


import os
import stat
from os.path import join, normcase, normpath, abspath, isabs, sep
from airy.utils.encoding import force_unicode
# Define our own abspath function that can handle joining 
# unicode paths to a current working directory that has non-ASCII
# characters in it.  This isn't necessary on Windows since the 
# Windows version of abspath handles this correctly.  The Windows
# abspath also handles drive letters differently than the pure 
# Python implementation, so it's best not to replace it.
if os.name == 'nt':
    abspathu = abspath
else:
    def abspathu(path):
        """
        Version of os.path.abspath that uses the unicode representation
        of the current working directory, thus avoiding a UnicodeDecodeError
        in join when the cwd has non-ASCII characters.
        """
        if not isabs(path):
            path = join(os.getcwdu(), path)
        return normpath(path)

def safe_join(base, *paths):
    """
    Joins one or more path components to the base path component intelligently.
    Returns a normalized, absolute version of the final path.

    The final path must be located inside of the base path component (otherwise
    a ValueError is raised).
    """
    # We need to use normcase to ensure we don't false-negative on case
    # insensitive operating systems (like Windows).
    base = force_unicode(base)

# Path: airy/utils/encoding.py
# def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
#     """
#     Similar to smart_unicode, except that lazy instances are resolved to
#     strings, rather than kept as lazy objects.
# 
#     If strings_only is True, don't convert (some) non-string-like objects.
#     """
#     # Handle the common case first, saves 30-40% in performance when s
#     # is an instance of unicode. This function gets called often in that
#     # setting.
#     if isinstance(s, unicode):
#         return s
#     if strings_only and is_protected_type(s):
#         return s
#     try:
#         if not isinstance(s, basestring,):
#             if hasattr(s, '__unicode__'):
#                 s = unicode(s)
#             else:
#                 try:
#                     s = unicode(str(s), encoding, errors)
#                 except UnicodeEncodeError:
#                     if not isinstance(s, Exception):
#                         raise
#                     # If we get to here, the caller has passed in an Exception
#                     # subclass populated with non-ASCII data without special
#                     # handling to display as a string. We need to handle this
#                     # without raising a further exception. We do an
#                     # approximation to what the Exception's standard str()
#                     # output should be.
#                     s = ' '.join([force_unicode(arg, encoding, strings_only,
#                             errors) for arg in s])
#         elif not isinstance(s, unicode):
#             # Note: We use .decode() here, instead of unicode(s, encoding,
#             # errors), so that if s is a SafeString, it ends up being a
#             # SafeUnicode at the end.
#             s = s.decode(encoding, errors)
#     except UnicodeDecodeError, e:
#         if not isinstance(s, Exception):
#             raise DjangoUnicodeDecodeError(s, *e.args)
#         else:
#             # If we get to here, the caller has passed in an Exception
#             # subclass populated with non-ASCII bytestring data without a
#             # working unicode method. Try to handle this without raising a
#             # further exception by individually forcing the exception args
#             # to unicode.
#             s = ' '.join([force_unicode(arg, encoding, strings_only,
#                     errors) for arg in s])
#     return s


# Path: airy/utils/_os.py
import os
import stat
from os.path import join, normcase, normpath, abspath, isabs, sep
from airy.utils.encoding import force_unicode

# Define our own abspath function that can handle joining 
# unicode paths to a current working directory that has non-ASCII
# characters in it.  This isn't necessary on Windows since the 
# Windows version of abspath handles this correctly.  The Windows
# abspath also handles drive letters differently than the pure 
# Python implementation, so it's best not to replace it.
if os.name == 'nt':
    abspathu = abspath
else:
    def abspathu(path):
        """
        Version of os.path.abspath that uses the unicode representation
        of the current working directory, thus avoiding a UnicodeDecodeError
        in join when the cwd has non-ASCII characters.
        """
        if not isabs(path):
            path = join(os.getcwdu(), path)
        return normpath(path)

def safe_join(base, *paths):
    """
    Joins one or more path components to the base path component intelligently.
    Returns a normalized, absolute version of the final path.

    The final path must be located inside of the base path component (otherwise
    a ValueError is raised).
    """
    # We need to use normcase to ensure we don't false-negative on case
    # insensitive operating systems (like Windows).
    base = force_unicode(base)

    paths = [force_unicode(p) for p in paths]