<s> import sys <EOL> import os <EOL> import errno <EOL> import warnings <EOL> import functools <EOL> PY2 = sys . version_info [ <NUM_LIT:0> ] == <NUM_LIT:2> <EOL> PY3K = sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> <EOL> PY33 = sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> if PY2 : <EOL> import imp <EOL> long = long <EOL> unicode = unicode <EOL> basestring = basestring <EOL> reduce = reduce <EOL> from urllib import quote_plus , unquote_plus , quote , unquote <EOL> from urlparse import parse_qsl <EOL> def load_module ( module , path ) : <EOL> with open ( path , '<STR_LIT:rb>' ) as fh : <EOL> mod = imp . load_source ( module , path , fh ) <EOL> return mod <EOL> else : <EOL> long = int <EOL> unicode = str <EOL> basestring = str <EOL> from functools import reduce <EOL> from urllib . parse import ( quote_plus , unquote_plus , <EOL> parse_qsl , quote , unquote ) <EOL> if PY33 : <EOL> from importlib import machinery <EOL> def load_module ( module , path ) : <EOL> return machinery . SourceFileLoader ( <EOL> module , path <EOL> ) . load_module ( module ) <EOL> else : <EOL> import imp <EOL> def load_module ( module , path ) : <EOL> with open ( path , '<STR_LIT:rb>' ) as fh : <EOL> mod = imp . load_source ( module , path , fh ) <EOL> return mod <EOL> class Null ( object ) : <EOL> def __bool__ ( self ) : <EOL> return False <EOL> def __eq__ ( self , other ) : <EOL> return other is None <EOL> def deprecated ( func ) : <EOL> '''<STR_LIT>''' <EOL> @ functools . wraps ( func ) <EOL> def new_func ( * args , ** kwargs ) : <EOL> if PY3K : <EOL> func_code = func . __code__ <EOL> else : <EOL> func_code = func . func_code <EOL> warnings . warn_explicit ( <EOL> "<STR_LIT>" . format ( func . __name__ ) , <EOL> category = DeprecationWarning , <EOL> filename = func_code . co_filename , <EOL> lineno = func_code . co_firstlineno + <NUM_LIT:1> <EOL> ) <EOL> return func ( * args , ** kwargs ) <EOL> return new_func <EOL> def decode ( string , encodings = None ) : <EOL> if not PY2 and not isinstance ( string , bytes ) : <EOL> return string <EOL> if PY2 and isinstance ( string , unicode ) : <EOL> return string <EOL> if encodings is None : <EOL> encodings = [ '<STR_LIT:utf-8>' , '<STR_LIT>' , '<STR_LIT:ascii>' ] <EOL> for encoding in encodings : <EOL> try : <EOL> return string . decode ( encoding ) <EOL> except ( UnicodeEncodeError , UnicodeDecodeError ) : <EOL> pass <EOL> return string . decode ( encodings [ <NUM_LIT:0> ] , errors = '<STR_LIT:ignore>' ) <EOL> def encode ( string , encodings = None ) : <EOL> if not PY2 and isinstance ( string , bytes ) : <EOL> return string <EOL> if PY2 and isinstance ( string , str ) : <EOL> return string <EOL> if encodings is None : <EOL> encodings = [ '<STR_LIT:utf-8>' , '<STR_LIT>' , '<STR_LIT:ascii>' ] <EOL> for encoding in encodings : <EOL> try : <EOL> return string . encode ( encoding ) <EOL> except ( UnicodeEncodeError , UnicodeDecodeError ) : <EOL> pass <EOL> return string . encode ( encodings [ <NUM_LIT:0> ] , errors = '<STR_LIT:ignore>' ) <EOL> def mkdir_p ( path , mode = <NUM_LIT> ) : <EOL> try : <EOL> os . makedirs ( path , mode ) <EOL> except OSError as exc : <EOL> if exc . errno == errno . EEXIST and os . path . isdir ( path ) : <EOL> pass <EOL> else : <EOL> raise <EOL> def value ( val ) : <EOL> if callable ( val ) : <EOL> return val ( ) <EOL> return val <EOL> def data_get ( target , key , default = None ) : <EOL> """<STR_LIT>""" <EOL> from . . support import Collection <EOL> if key is None : <EOL> return target <EOL> if not isinstance ( key , list ) : <EOL> key = key . split ( '<STR_LIT:.>' ) <EOL> for segment in key : <EOL> if isinstance ( target , ( list , tuple ) ) : <EOL> try : <EOL> target = target [ segment ] <EOL> except IndexError : <EOL> return value ( default ) <EOL> elif isinstance ( target , dict ) : <EOL> try : <EOL> target = target [ segment ] <EOL> except IndexError : <EOL> return value ( default ) <EOL> elif isinstance ( target , Collection ) : <EOL> try : <EOL> target = target [ segment ] <EOL> except IndexError : <EOL> return value ( default ) <EOL> else : <EOL> try : <EOL> target = getattr ( target , segment ) <EOL> except AttributeError : <EOL> return value ( default ) <EOL> return target </s>
