# Path: torext/utils.py
# def generate_cookie_secret():
# def timesince(t):
# def pprint(o):
#     def instance(cls, *args, **kwgs):
# def split_kwargs(kwgs_tuple, kwgs):
#     def __getattr__(self, key):
#     def __setattr__(self, key, value):
#     def __delattr__(self, key):
#     def __str__(self):
# def _resolve_name(name, package, level):
# def import_module(name, package=None):
# def add_to_syspath(pth, relative_to=None):
# def start_shell(extra_vars=None):
#         def complete(self, text, state):
# def fix_request_arguments(arguments):
#     def __init__(self, local, name=None):
#     def get_current_object(self):
#     def __dict__(self):
#     def __repr__(self):
#     def __bool__(self):
#     def __unicode__(self):
#     def __dir__(self):
#     def __getattr__(self, name):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __setslice__(self, i, j, seq):
#     def __delslice__(self, i, j):
# class SingletonMixin(object):
# class ObjectDict(dict):
#     class CustomCompleter(rlcompleter.Completer):
# class LocalProxy(object):
# 
# Path: torext/compat.py
# PY3 = sys.version_info.major == 3
# PY2 = sys.version_info.major == 2
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):


import sys
import time
import unittest
import logging
import mimetypes
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado.stack_context import NullContext
from tornado.escape import json_encode
from tornado import web
from tornado.web import HTTPError
from torext.utils import raise_exc_info
from torext.compat import SimpleCookie, quote, urlencode, httplib
    "0123456789-._~")


def unquote_unreserved(uri):
    """Un-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
    """
    parts = uri.split('%')
    for i in range(1, len(parts)):
        h = parts[i][0:2]
        if len(h) == 2 and h.isalnum():
            c = chr(int(h, 16))
            if c in UNRESERVED_SET:
                parts[i] = c + parts[i][2:]
            else:
                parts[i] = '%' + parts[i]
        else:
            parts[i] = '%' + parts[i]
    return ''.join(parts)


def requote_uri(uri):
    """Re-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.
    """
    # Unquote only the unreserved characters
    # Then quote only illegal characters (do not quote reserved, unreserved,
    # or '%')

# Path: torext/utils.py
# def generate_cookie_secret():
# def timesince(t):
# def pprint(o):
#     def instance(cls, *args, **kwgs):
# def split_kwargs(kwgs_tuple, kwgs):
#     def __getattr__(self, key):
#     def __setattr__(self, key, value):
#     def __delattr__(self, key):
#     def __str__(self):
# def _resolve_name(name, package, level):
# def import_module(name, package=None):
# def add_to_syspath(pth, relative_to=None):
# def start_shell(extra_vars=None):
#         def complete(self, text, state):
# def fix_request_arguments(arguments):
#     def __init__(self, local, name=None):
#     def get_current_object(self):
#     def __dict__(self):
#     def __repr__(self):
#     def __bool__(self):
#     def __unicode__(self):
#     def __dir__(self):
#     def __getattr__(self, name):
#     def __setitem__(self, key, value):
#     def __delitem__(self, key):
#     def __setslice__(self, i, j, seq):
#     def __delslice__(self, i, j):
# class SingletonMixin(object):
# class ObjectDict(dict):
#     class CustomCompleter(rlcompleter.Completer):
# class LocalProxy(object):
# 
# Path: torext/compat.py
# PY3 = sys.version_info.major == 3
# PY2 = sys.version_info.major == 2
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):
#     def unicode_(s, *args):
#     def decode_(s, *args):
#     def bytes_(s):
#     def str_(s):


# Path: torext/testing.py
import sys
import time
import unittest
import logging
import mimetypes
from tornado.httpclient import AsyncHTTPClient
from tornado.ioloop import IOLoop
from tornado.stack_context import NullContext
from tornado.escape import json_encode
from tornado import web
from tornado.web import HTTPError
from torext.utils import raise_exc_info
from torext.compat import SimpleCookie, quote, urlencode, httplib

    "0123456789-._~")


def unquote_unreserved(uri):
    """Un-escape any percent-escape sequences in a URI that are unreserved
    characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
    """
    parts = uri.split('%')
    for i in range(1, len(parts)):
        h = parts[i][0:2]
        if len(h) == 2 and h.isalnum():
            c = chr(int(h, 16))
            if c in UNRESERVED_SET:
                parts[i] = c + parts[i][2:]
            else:
                parts[i] = '%' + parts[i]
        else:
            parts[i] = '%' + parts[i]
    return ''.join(parts)


def requote_uri(uri):
    """Re-quote the given URI.

    This function passes the given URI through an unquote/quote cycle to
    ensure that it is fully and consistently quoted.
    """
    # Unquote only the unreserved characters
    # Then quote only illegal characters (do not quote reserved, unreserved,
    # or '%')

    return quote(unquote_unreserved(uri), safe="!#$%&'()*+,/:;=?@[]~")