Navigation

Source code for pyramid.compat

importinspectimportplatformimportsysimporttypesifplatform.system()=='Windows':# pragma: no coverWIN=Trueelse:# pragma: no coverWIN=Falsetry:# pragma: no coverimport__pypy__PYPY=Trueexcept:# pragma: no cover__pypy__=NonePYPY=Falsetry:importcPickleaspickleexceptImportError:# pragma: no coverimportpickle# True if we are running on Python 3.PY3=sys.version_info[0]==3ifPY3:# pragma: no coverstring_types=str,integer_types=int,class_types=type,text_type=strbinary_type=byteslong=intelse:string_types=basestring,integer_types=(int,long)class_types=(type,types.ClassType)text_type=unicodebinary_type=strlong=long

[docs]defexec_(code,globs=None,locs=None):"""Execute code in a namespace."""ifglobsisNone:frame=sys._getframe(1)globs=frame.f_globalsiflocsisNone:locs=frame.f_localsdelframeeliflocsisNone:locs=globsexec("""exec code in globs, locs""")

ifPY3:# pragma: no coverim_func='__func__'im_self='__self__'else:im_func='im_func'im_self='im_self'try:# pragma: no coverimportconfigparserexceptImportError:# pragma: no coverimportConfigParserasconfigparsertry:fromCookieimportSimpleCookieexceptImportError:# pragma: no coverfromhttp.cookiesimportSimpleCookieifPY3:# pragma: no coverfromhtmlimportescapeelse:fromcgiimportescapetry:# pragma: no coverinput_=raw_inputexceptNameError:# pragma: no coverinput_=inputtry:fromStringIOimportStringIOasNativeIOexceptImportError:# pragma: no coverfromioimportStringIOasNativeIO# "json" is not an API; it's here to support older pyramid_debugtoolbar# versions which attempt to import itimportjsonifPY3:# pragma: no cover# see PEP 3333 for why we encode WSGI PATH_INFO to latin-1 before# decoding it to utf-8defdecode_path_info(path):returnpath.encode('latin-1').decode('utf-8')else:defdecode_path_info(path):returnpath.decode('utf-8')ifPY3:# pragma: no cover# see PEP 3333 for why we decode the path to latin-1 fromurllib.parseimportunquote_to_bytesdefunquote_bytes_to_wsgi(bytestring):returnunquote_to_bytes(bytestring).decode('latin-1')else:fromurlparseimportunquoteasunquote_to_bytesdefunquote_bytes_to_wsgi(bytestring):returnunquote_to_bytes(bytestring)defis_bound_method(ob):returninspect.ismethod(ob)andgetattr(ob,im_self,None)isnotNone