# 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
        self.http_server.stop()
        if (not IOLoop.initialized() or
                self.http_client.io_loop is not IOLoop.instance()):
            self.http_client.close()
        # end::tornado.testing.AsyncHTTPTestCase

        # start::tornado.testing.AsyncTestCase
        if (not IOLoop.initialized() or
                self.io_loop is not IOLoop.instance()):
            # Try to clean up any file descriptors left open in the ioloop.
            # This avoids leaks, especially when tests are run repeatedly
            # in the same process with autoreload (because curl does not
            # set FD_CLOEXEC on its file descriptors)
            self.io_loop.close(all_fds=True)
        # end::tornado.testing.AsyncTestCase

    def _parse_cookies(self, resp):
        if COOKIE_HEADER_KEY in resp.headers:
            c = SimpleCookie(resp.headers.get(COOKIE_HEADER_KEY))
        elif COOKIE_HEADER_KEY.lower() in resp.headers:
            c = SimpleCookie(resp.headers.get(COOKIE_HEADER_KEY.lower()))
        else:
            c = None
        resp.cookies = c

    def _add_cookies(self, cookies, kwgs):
        # SimpleCookie is inherited from dict, so judge it first
        if isinstance(cookies, SimpleCookie):
            c = cookies
        elif isinstance(cookies, dict):

# 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

        self.http_server.stop()
        if (not IOLoop.initialized() or
                self.http_client.io_loop is not IOLoop.instance()):
            self.http_client.close()
        # end::tornado.testing.AsyncHTTPTestCase

        # start::tornado.testing.AsyncTestCase
        if (not IOLoop.initialized() or
                self.io_loop is not IOLoop.instance()):
            # Try to clean up any file descriptors left open in the ioloop.
            # This avoids leaks, especially when tests are run repeatedly
            # in the same process with autoreload (because curl does not
            # set FD_CLOEXEC on its file descriptors)
            self.io_loop.close(all_fds=True)
        # end::tornado.testing.AsyncTestCase

    def _parse_cookies(self, resp):
        if COOKIE_HEADER_KEY in resp.headers:
            c = SimpleCookie(resp.headers.get(COOKIE_HEADER_KEY))
        elif COOKIE_HEADER_KEY.lower() in resp.headers:
            c = SimpleCookie(resp.headers.get(COOKIE_HEADER_KEY.lower()))
        else:
            c = None
        resp.cookies = c

    def _add_cookies(self, cookies, kwgs):
        # SimpleCookie is inherited from dict, so judge it first
        if isinstance(cookies, SimpleCookie):
            c = cookies
        elif isinstance(cookies, dict):

            c = SimpleCookie()