# Path: airy/utils/safestring.py
# class SafeData(object):
#     pass
# 
# def mark_safe(s):
#     """
#     Explicitly mark a string as safe for (HTML) output purposes. The returned
#     object can be used everywhere a string or unicode object is appropriate.
# 
#     Can be called multiple times on a single string.
#     """
#     if isinstance(s, SafeData):
#         return s
#     if isinstance(s, str) or (isinstance(s, Promise) and s._delegate_str):
#         return SafeString(s)
#     if isinstance(s, (unicode, Promise)):
#         return SafeUnicode(s)
#     return SafeString(str(s))
# 
# 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/functional.py
# def allow_lazy(func, *resultclasses):
#     """
#     A decorator that allows a function to be called with one or more lazy
#     arguments. If none of the args are lazy, the function is evaluated
#     immediately, otherwise a __proxy__ is returned that will evaluate the
#     function when needed.
#     """
#     def wrapper(*args, **kwargs):
#         for arg in list(args) + kwargs.values():
#             if isinstance(arg, Promise):
#                 break
#         else:
#             return func(*args, **kwargs)
#         return lazy(func, *resultclasses)(*args, **kwargs)
#     return wraps(func)(wrapper)
# 
# Path: airy/utils/http.py
# def urlquote(url, safe='/'):
#     """
#     A version of Python's urllib.quote() function that can operate on unicode
#     strings. The url is first UTF-8 encoded before quoting. The returned string
#     can safely be used as part of an argument to a subsequent iri_to_uri() call
#     without double-quoting occurring.
#     """
#     return force_unicode(urllib.quote(smart_str(url), smart_str(safe)))


import re
import string
from airy.utils.safestring import SafeData, mark_safe
from airy.utils.encoding import force_unicode
from airy.utils.functional import allow_lazy
from airy.utils.http import urlquote
    from airy.utils.text import normalize_newlines
del x # Temporary variable

def escape(html):
    """
    Returns the given HTML with ampersands, quotes and angle brackets encoded.
    """
    return mark_safe(force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;'))
escape = allow_lazy(escape, unicode)

_base_js_escapes = (
    ('\\', r'\u005C'),
    ('\'', r'\u0027'),
    ('"', r'\u0022'),
    ('>', r'\u003E'),
    ('<', r'\u003C'),
    ('&', r'\u0026'),
    ('=', r'\u003D'),
    ('-', r'\u002D'),
    (';', r'\u003B'),
    (u'\u2028', r'\u2028'),
    (u'\u2029', r'\u2029')
)

# Escape every ASCII character with a value less than 32.
_js_escapes = (_base_js_escapes +
               tuple([('%c' % z, '\\u%04X' % z) for z in range(32)]))

def escapejs(value):
    """Hex encodes characters for use in JavaScript strings."""
    for bad, good in _js_escapes:

# Path: airy/utils/safestring.py
# class SafeData(object):
#     pass
# 
# def mark_safe(s):
#     """
#     Explicitly mark a string as safe for (HTML) output purposes. The returned
#     object can be used everywhere a string or unicode object is appropriate.
# 
#     Can be called multiple times on a single string.
#     """
#     if isinstance(s, SafeData):
#         return s
#     if isinstance(s, str) or (isinstance(s, Promise) and s._delegate_str):
#         return SafeString(s)
#     if isinstance(s, (unicode, Promise)):
#         return SafeUnicode(s)
#     return SafeString(str(s))
# 
# 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/functional.py
# def allow_lazy(func, *resultclasses):
#     """
#     A decorator that allows a function to be called with one or more lazy
#     arguments. If none of the args are lazy, the function is evaluated
#     immediately, otherwise a __proxy__ is returned that will evaluate the
#     function when needed.
#     """
#     def wrapper(*args, **kwargs):
#         for arg in list(args) + kwargs.values():
#             if isinstance(arg, Promise):
#                 break
#         else:
#             return func(*args, **kwargs)
#         return lazy(func, *resultclasses)(*args, **kwargs)
#     return wraps(func)(wrapper)
# 
# Path: airy/utils/http.py
# def urlquote(url, safe='/'):
#     """
#     A version of Python's urllib.quote() function that can operate on unicode
#     strings. The url is first UTF-8 encoded before quoting. The returned string
#     can safely be used as part of an argument to a subsequent iri_to_uri() call
#     without double-quoting occurring.
#     """
#     return force_unicode(urllib.quote(smart_str(url), smart_str(safe)))


# Path: airy/utils/html.py
import re
import string
from airy.utils.safestring import SafeData, mark_safe
from airy.utils.encoding import force_unicode
from airy.utils.functional import allow_lazy
from airy.utils.http import urlquote
    from airy.utils.text import normalize_newlines

del x # Temporary variable

def escape(html):
    """
    Returns the given HTML with ampersands, quotes and angle brackets encoded.
    """
    return mark_safe(force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;'))
escape = allow_lazy(escape, unicode)

_base_js_escapes = (
    ('\\', r'\u005C'),
    ('\'', r'\u0027'),
    ('"', r'\u0022'),
    ('>', r'\u003E'),
    ('<', r'\u003C'),
    ('&', r'\u0026'),
    ('=', r'\u003D'),
    ('-', r'\u002D'),
    (';', r'\u003B'),
    (u'\u2028', r'\u2028'),
    (u'\u2029', r'\u2029')
)

# Escape every ASCII character with a value less than 32.
_js_escapes = (_base_js_escapes +
               tuple([('%c' % z, '\\u%04X' % z) for z in range(32)]))

def escapejs(value):
    """Hex encodes characters for use in JavaScript strings."""
    for bad, good in _js_escapes:

        value = mark_safe(force_unicode(value).replace(bad, good))