4 py3k
= sys
.version_info
>= (3, 0)
5 py33
= sys
.version_info
>= (3, 3)
6 py2k
= sys
.version_info
< (3,)
7 py26
= sys
.version_info
>= (2, 6)
8 jython
= sys
.platform
.startswith('java')
9 win32
= sys
.platform
.startswith('win')
10 pypy
= hasattr(sys
, 'pypy_version_info')
13 from io
import StringIO
14 import builtins
as compat_builtins
15 from urllib
.parse
import quote_plus
, unquote_plus
16 from html
.entities
import codepoint2name
, name2codepoint
21 from io
import BytesIO
as byte_buffer
27 return s
.encode("latin-1")
30 return eval("0o" + lit
)
33 import __builtin__
as compat_builtins
35 from cStringIO
import StringIO
37 from StringIO
import StringIO
39 byte_buffer
= StringIO
41 from urllib
import quote_plus
, unquote_plus
42 from htmlentitydefs
import codepoint2name
, name2codepoint
43 string_types
= basestring
,
48 return unicode(s
, "utf-8")
54 return eval("0" + lit
)
58 from importlib
import machinery
59 def load_module(module_id
, path
):
60 return machinery
.SourceFileLoader(module_id
, path
).load_module()
63 def load_module(module_id
, path
):
66 return imp
.load_source(module_id
, path
, fp
)
72 def reraise(tp
, value
, tb
=None, cause
=None):
74 value
.__cause
__ = cause
75 if value
.__traceback
__ is not tb
:
76 raise value
.with_traceback(tb
)
79 exec("def reraise(tp, value, tb=None, cause=None):\n"
80 " raise tp, value, tb\n")
84 return sys
.exc_info()[1]
89 import _thread
as thread
93 import dummy_threading
as threading
95 import _dummy_thread
as thread
97 import dummy_thread
as thread
100 time_func
= time
.clock
102 time_func
= time
.time
105 from functools
import partial
107 def partial(func
, *args
, **keywords
):
108 def newfunc(*fargs
, **fkeywords
):
109 newkeywords
= keywords
.copy()
110 newkeywords
.update(fkeywords
)
111 return func(*(args
+ fargs
), **newkeywords
)
118 def exception_name(exc
):
119 return exc
.__class
__.__name
__
122 from inspect
import CO_VARKEYWORDS
, CO_VARARGS
123 def inspect_func_args(fn
):
129 nargs
= co
.co_argcount
130 names
= co
.co_varnames
131 args
= list(names
[:nargs
])
134 if co
.co_flags
& CO_VARARGS
:
135 varargs
= co
.co_varnames
[nargs
]
138 if co
.co_flags
& CO_VARKEYWORDS
:
139 varkw
= co
.co_varnames
[nargs
]
142 return args
, varargs
, varkw
, fn
.__defaults
__
144 return args
, varargs
, varkw
, fn
.func_defaults
147 def inspect_func_args(fn
):
148 return inspect
.getargspec(fn
)
152 return hasattr(fn
, '__call__')
157 ################################################
158 # cross-compatible metaclass implementation
159 # Copyright (c) 2010-2012 Benjamin Peterson
160 def with_metaclass(meta
, base
=object):
161 """Create a base class with a metaclass."""
162 return meta("%sBase" % meta
.__name
__, (base
,), {})
163 ################################################
166 def arg_stringname(func_arg
):
167 """Gets the string name of a kwarg or vararg
168 In Python3.4 a function's args are
169 of _ast.arg type not _ast.name
171 if hasattr(func_arg
, 'arg'):