# 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
            if files:
                boundary = '1234567890'
                headers['Content-Type'] = 'multipart/form-data; boundary=%s' % boundary
                L = []
                if data:
                    for k, v in data.items():
                        L.append('--' + boundary)
                        L.append('Content-Disposition: form-data; name="%s"' % k)
                        L.append('')
                        L.append(v)
                for k, f in files.items():
                    L.append('--' + boundary)
                    L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (k, f[0]))
                    L.append('Content-Type: %s' % mimetypes.guess_type(f[0])[0] or 'application/octet-stream')
                    L.append('')
                    L.append(f[1])
                L.append('--%s--' % boundary)
                L.append('')
                body = '\r\n'.join(L)
            else:
                if data:
                    if json:
                        body = json_encode(data)
                        headers['Content-Type'] = 'application/json'
                    else:
                        headers['Content-Type'] = 'application/x-www-form-urlencoded'
                        body = urlencode(data)
            kwgs['body'] = body
        else:
            if data:

# 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

            if files:
                boundary = '1234567890'
                headers['Content-Type'] = 'multipart/form-data; boundary=%s' % boundary
                L = []
                if data:
                    for k, v in data.items():
                        L.append('--' + boundary)
                        L.append('Content-Disposition: form-data; name="%s"' % k)
                        L.append('')
                        L.append(v)
                for k, f in files.items():
                    L.append('--' + boundary)
                    L.append('Content-Disposition: form-data; name="%s"; filename="%s"' % (k, f[0]))
                    L.append('Content-Type: %s' % mimetypes.guess_type(f[0])[0] or 'application/octet-stream')
                    L.append('')
                    L.append(f[1])
                L.append('--%s--' % boundary)
                L.append('')
                body = '\r\n'.join(L)
            else:
                if data:
                    if json:
                        body = json_encode(data)
                        headers['Content-Type'] = 'application/json'
                    else:
                        headers['Content-Type'] = 'application/x-www-form-urlencoded'
                        body = urlencode(data)
            kwgs['body'] = body
        else:
            if data:

                path = '%s?%s' % (path, urlencode(data))