def import_object(name, arg=None):
    if '.' not in name:
        return __import__(name)
    parts = name.split('.')
    obj = __import__('.'.join(parts[:-1]), None, None, [parts[-1]], 0)
    return getattr(obj, parts[-1], arg)

@@ -1,8 +1,162 @@
+import logging%0Aimport time%0Aimport base64%0Aimport hmac%0Aimport hashlib%0A%0A%0Aif str is unicode:%0A    b = lambda s: s.encode('latin1')%0Aelse:%0A    b = lambda s: s%0A%0A%0A
 def impo
@@ -377,8 +377,2392 @@
 %5D, arg)%0A
+%0A%0Adef utf8(value):%0A    %22%22%22Converts a string argument to a byte string.%0A%0A    If the argument is already a byte string or None, it is returned unchanged.%0A    Otherwise it must be a unicode string and is encoded as utf8.%0A    %22%22%22%0A    if isinstance(value, bytes, type(None)):%0A        return value%0A    assert isinstance(value, unicode)%0A    return value.encode(%22utf-8%22)%0A%0A%0Adef _time_independent_equals(a, b):%0A    if len(a) != len(b):%0A        return False%0A    result = 0%0A    if type(a%5B0%5D) is int:  # python3 byte strings%0A        for x, y in zip(a, b):%0A            result %7C= x %5E y%0A    else:  # python2%0A        for x, y in zip(a, b):%0A            result %7C= ord(x) %5E ord(y)%0A    return result == 0%0A%0A%0Adef create_signed_value(secret, name, value):%0A    timestamp = utf8(str(int(time.time())))%0A    value = base64.b64encode(utf8(value))%0A    signature = _create_signature(secret, name, value, timestamp)%0A    value = b(%22%7C%22).join(%5Bvalue, timestamp, signature%5D)%0A    return value%0A%0A%0Adef decode_signed_value(secret, name, value, max_age_days=31):%0A    if not value:%0A        return None%0A    parts = utf8(value).split(b(%22%7C%22))%0A    if len(parts) != 3:%0A        return None%0A    signature = _create_signature(secret, name, parts%5B0%5D, parts%5B1%5D)%0A    if not _time_independent_equals(parts%5B2%5D, signature):%0A        logging.warning(%22Invalid cookie signature %25r%22, value)%0A        return None%0A    timestamp = int(parts%5B1%5D)%0A    if timestamp %3C time.time() - max_age_days * 86400:%0A        logging.warning(%22Expired cookie %25r%22, value)%0A        return None%0A    if timestamp %3E time.time() + 31 * 86400:%0A        # _cookie_signature does not hash a delimiter between the%0A        # parts of the cookie, so an attacker could transfer trailing%0A        # digits from the payload to the timestamp without altering the%0A        # signature.  For backwards compatibility, sanity-check timestamp%0A        # here instead of modifying _cookie_signature.%0A        logging.warning(%0A            %22Cookie timestamp in future; possible tampering %25r%22, value%0A        )%0A        return None%0A    if parts%5B1%5D.startswith(b(%220%22)):%0A        logging.warning(%22Tampered cookie %25r%22, value)%0A    try:%0A        return base64.b64decode(parts%5B0%5D)%0A    except Exception:%0A        return None%0A%0A%0Adef _create_signature(secret, *parts):%0A    hash = hmac.new(utf8(secret), digestmod=hashlib.sha1)%0A    for part in parts:%0A        hash.update(utf8(part))%0A    return utf8(hash.hexdigest())%0A

copy from tornado