<s> from __future__ import absolute_import <EOL> import os <EOL> import re <EOL> import sys <EOL> if sys . version_info [ <NUM_LIT:0> ] < <NUM_LIT:3> : <EOL> from StringIO import StringIO <EOL> string_types = basestring , <EOL> text_type = unicode <EOL> from types import FileType as file_type <EOL> import __builtin__ as builtins <EOL> import ConfigParser as configparser <EOL> from . _backport import shutil <EOL> from urlparse import urlparse , urlunparse , urljoin , urlsplit , urlunsplit <EOL> from urllib import ( urlretrieve , quote as _quote , unquote , url2pathname , <EOL> pathname2url , ContentTooShortError , splittype ) <EOL> def quote ( s ) : <EOL> if isinstance ( s , unicode ) : <EOL> s = s . encode ( '<STR_LIT:utf-8>' ) <EOL> return _quote ( s ) <EOL> import urllib2 <EOL> from urllib2 import ( Request , urlopen , URLError , HTTPError , <EOL> HTTPBasicAuthHandler , HTTPPasswordMgr , <EOL> HTTPSHandler , HTTPHandler , HTTPRedirectHandler , <EOL> build_opener ) <EOL> import httplib <EOL> import xmlrpclib <EOL> import Queue as queue <EOL> from HTMLParser import HTMLParser <EOL> import htmlentitydefs <EOL> raw_input = raw_input <EOL> from itertools import ifilter as filter <EOL> from itertools import ifilterfalse as filterfalse <EOL> _userprog = None <EOL> def splituser ( host ) : <EOL> """<STR_LIT>""" <EOL> global _userprog <EOL> if _userprog is None : <EOL> import re <EOL> _userprog = re . compile ( '<STR_LIT>' ) <EOL> match = _userprog . match ( host ) <EOL> if match : return match . group ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> return None , host <EOL> else : <EOL> from io import StringIO <EOL> string_types = str , <EOL> text_type = str <EOL> from io import TextIOWrapper as file_type <EOL> import builtins <EOL> import configparser <EOL> import shutil <EOL> from urllib . parse import ( urlparse , urlunparse , urljoin , splituser , quote , <EOL> unquote , urlsplit , urlunsplit , splittype ) <EOL> from urllib . request import ( urlopen , urlretrieve , Request , url2pathname , <EOL> pathname2url , <EOL> HTTPBasicAuthHandler , HTTPPasswordMgr , <EOL> HTTPSHandler , HTTPHandler , HTTPRedirectHandler , <EOL> build_opener ) <EOL> from urllib . error import HTTPError , URLError , ContentTooShortError <EOL> import http . client as httplib <EOL> import urllib . request as urllib2 <EOL> import xmlrpc . client as xmlrpclib <EOL> import queue <EOL> from html . parser import HTMLParser <EOL> import html . entities as htmlentitydefs <EOL> raw_input = input <EOL> from itertools import filterfalse <EOL> filter = filter <EOL> try : <EOL> from ssl import match_hostname , CertificateError <EOL> except ImportError : <EOL> class CertificateError ( ValueError ) : <EOL> pass <EOL> def _dnsname_match ( dn , hostname , max_wildcards = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> pats = [ ] <EOL> if not dn : <EOL> return False <EOL> parts = dn . split ( '<STR_LIT:.>' ) <EOL> leftmost , remainder = parts [ <NUM_LIT:0> ] , parts [ <NUM_LIT:1> : ] <EOL> wildcards = leftmost . count ( '<STR_LIT:*>' ) <EOL> if wildcards > max_wildcards : <EOL> raise CertificateError ( <EOL> "<STR_LIT>" + repr ( dn ) ) <EOL> if not wildcards : <EOL> return dn . lower ( ) == hostname . lower ( ) <EOL> if leftmost == '<STR_LIT:*>' : <EOL> pats . append ( '<STR_LIT>' ) <EOL> elif leftmost . startswith ( '<STR_LIT>' ) or hostname . startswith ( '<STR_LIT>' ) : <EOL> pats . append ( re . escape ( leftmost ) ) <EOL> else : <EOL> pats . append ( re . escape ( leftmost ) . replace ( r'<STR_LIT>' , '<STR_LIT>' ) ) <EOL> for frag in remainder : <EOL> pats . append ( re . escape ( frag ) ) <EOL> pat = re . compile ( r'<STR_LIT>' + r'<STR_LIT>' . join ( pats ) + r'<STR_LIT>' , re . IGNORECASE ) <EOL> return pat . match ( hostname ) <EOL> def match_hostname ( cert , hostname ) : <EOL> """<STR_LIT>""" <EOL> if not cert : <EOL> raise ValueError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> dnsnames = [ ] <EOL> san = cert . get ( '<STR_LIT>' , ( ) ) <EOL> for key , value in san : <EOL> if key == '<STR_LIT>' : <EOL> if _dnsname_match ( value , hostname ) : <EOL> return <EOL> dnsnames . append ( value ) <EOL> if not dnsnames : <EOL> for sub in cert . get ( '<STR_LIT>' , ( ) ) : <EOL> for key , value in sub : <EOL> if key == '<STR_LIT>' : <EOL> if _dnsname_match ( value , hostname ) : <EOL> return <EOL> dnsnames . append ( value ) <EOL> if len ( dnsnames ) > <NUM_LIT:1> : <EOL> raise CertificateError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( hostname , '<STR_LIT:U+002CU+0020>' . join ( map ( repr , dnsnames ) ) ) ) <EOL> elif len ( dnsnames ) == <NUM_LIT:1> : <EOL> raise CertificateError ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> % ( hostname , dnsnames [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> raise CertificateError ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> try : <EOL> from types import SimpleNamespace as Container <EOL> except ImportError : <EOL> class Container ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> self . __dict__ . update ( kwargs ) <EOL> try : <EOL> from shutil import which <EOL> except ImportError : <EOL> def which ( cmd , mode = os . F_OK | os . X_OK , path = None ) : <EOL> """<STR_LIT>""" <EOL> def _access_check ( fn , mode ) : <EOL> return ( os . path . exists ( fn ) and os . access ( fn , mode ) <EOL> and not os . path . isdir ( fn ) ) <EOL> if os . path . dirname ( cmd ) : <EOL> if _access_check ( cmd , mode ) : <EOL> return cmd <EOL> return None <EOL> if path is None : <EOL> path = os . environ . get ( "<STR_LIT>" , os . defpath ) <EOL> if not path : <EOL> return None <EOL> path = path . split ( os . pathsep ) <EOL> if sys . platform == "<STR_LIT:win32>" : <EOL> if not os . curdir in path : <EOL> path . insert ( <NUM_LIT:0> , os . curdir ) <EOL> pathext = os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) . split ( os . pathsep ) <EOL> if any ( cmd . lower ( ) . endswith ( ext . lower ( ) ) for ext in pathext ) : <EOL> files = [ cmd ] <EOL> else : <EOL> files = [ cmd + ext for ext in pathext ] <EOL> else : <EOL> files = [ cmd ] <EOL> seen = set ( ) <EOL> for dir in path : <EOL> normdir = os . path . normcase ( dir ) <EOL> if not normdir in seen : <EOL> seen . add ( normdir ) <EOL> for thefile in files : <EOL> name = os . path . join ( dir , thefile ) <EOL> if _access_check ( name , mode ) : <EOL> return name <EOL> return None <EOL> from zipfile import ZipFile as BaseZipFile <EOL> if hasattr ( BaseZipFile , '<STR_LIT>' ) : <EOL> ZipFile = BaseZipFile <EOL> else : <EOL> from zipfile import ZipExtFile as BaseZipExtFile <EOL> class ZipExtFile ( BaseZipExtFile ) : <EOL> def __init__ ( self , base ) : <EOL> self . __dict__ . update ( base . __dict__ ) <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , * exc_info ) : <EOL> self . close ( ) <EOL> class ZipFile ( BaseZipFile ) : <EOL> def __enter__ ( self ) : <EOL> return self <EOL> def __exit__ ( self , * exc_info ) : <EOL> self . close ( ) <EOL> def open ( self , * args , ** kwargs ) : <EOL> base = BaseZipFile . open ( self , * args , ** kwargs ) <EOL> return ZipExtFile ( base ) <EOL> try : <EOL> from platform import python_implementation <EOL> except ImportError : <EOL> def python_implementation ( ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in sys . version : <EOL> return '<STR_LIT>' <EOL> if os . name == '<STR_LIT>' : <EOL> return '<STR_LIT>' <EOL> if sys . version . startswith ( '<STR_LIT>' ) : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' <EOL> try : <EOL> import sysconfig <EOL> except ImportError : <EOL> from . _backport import sysconfig <EOL> try : <EOL> callable = callable <EOL> except NameError : <EOL> from collections import Callable <EOL> def callable ( obj ) : <EOL> return isinstance ( obj , Callable ) <EOL> try : <EOL> fsencode = os . fsencode <EOL> fsdecode = os . fsdecode <EOL> except AttributeError : <EOL> _fsencoding = sys . getfilesystemencoding ( ) <EOL> if _fsencoding == '<STR_LIT>' : <EOL> _fserrors = '<STR_LIT:strict>' <EOL> else : <EOL> _fserrors = '<STR_LIT>' <EOL> def fsencode ( filename ) : <EOL> if isinstance ( filename , bytes ) : <EOL> return filename <EOL> elif isinstance ( filename , text_type ) : <EOL> return filename . encode ( _fsencoding , _fserrors ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % <EOL> type ( filename ) . __name__ ) <EOL> def fsdecode ( filename ) : <EOL> if isinstance ( filename , text_type ) : <EOL> return filename <EOL> elif isinstance ( filename , bytes ) : <EOL> return filename . decode ( _fsencoding , _fserrors ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % <EOL> type ( filename ) . __name__ ) <EOL> try : <EOL> from tokenize import detect_encoding <EOL> except ImportError : <EOL> from codecs import BOM_UTF8 , lookup <EOL> import re <EOL> cookie_re = re . compile ( "<STR_LIT>" ) <EOL> def _get_normal_name ( orig_enc ) : <EOL> """<STR_LIT>""" <EOL> enc = orig_enc [ : <NUM_LIT:12> ] . lower ( ) . replace ( "<STR_LIT:_>" , "<STR_LIT:->" ) <EOL> if enc == "<STR_LIT:utf-8>" or enc . startswith ( "<STR_LIT>" ) : <EOL> return "<STR_LIT:utf-8>" <EOL> if enc in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) or enc . startswith ( ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> return "<STR_LIT>" <EOL> return orig_enc <EOL> def detect_encoding ( readline ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> filename = readline . __self__ . name <EOL> except AttributeError : <EOL> filename = None <EOL> bom_found = False <EOL> encoding = None <EOL> default = '<STR_LIT:utf-8>' <EOL> def read_or_stop ( ) : <EOL> try : <EOL> return readline ( ) <EOL> except StopIteration : <EOL> return b'<STR_LIT>' <EOL> def find_cookie ( line ) : <EOL> try : <EOL> line_string = line . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError : <EOL> msg = "<STR_LIT>" <EOL> if filename is not None : <EOL> msg = '<STR_LIT>' . format ( msg , filename ) <EOL> raise SyntaxError ( msg ) <EOL> matches = cookie_re . findall ( line_string ) <EOL> if not matches : <EOL> return None <EOL> encoding = _get_normal_name ( matches [ <NUM_LIT:0> ] ) <EOL> try : <EOL> codec = lookup ( encoding ) <EOL> except LookupError : <EOL> if filename is None : <EOL> msg = "<STR_LIT>" + encoding <EOL> else : <EOL> msg = "<STR_LIT>" . format ( filename , <EOL> encoding ) <EOL> raise SyntaxError ( msg ) <EOL> if bom_found : <EOL> if codec . name != '<STR_LIT:utf-8>' : <EOL> if filename is None : <EOL> msg = '<STR_LIT>' <EOL> else : <EOL> msg = '<STR_LIT>' . format ( filename ) <EOL> raise SyntaxError ( msg ) <EOL> encoding += '<STR_LIT>' <EOL> return encoding <EOL> first = read_or_stop ( ) <EOL> if first . startswith ( BOM_UTF8 ) : <EOL> bom_found = True <EOL> first = first [ <NUM_LIT:3> : ] <EOL> default = '<STR_LIT>' <EOL> if not first : <EOL> return default , [ ] <EOL> encoding = find_cookie ( first ) <EOL> if encoding : <EOL> return encoding , [ first ] <EOL> second = read_or_stop ( ) <EOL> if not second : <EOL> return default , [ first ] <EOL> encoding = find_cookie ( second ) <EOL> if encoding : <EOL> return encoding , [ first , second ] <EOL> return default , [ first , second ] <EOL> try : <EOL> from html import escape <EOL> except ImportError : <EOL> from cgi import escape <EOL> if sys . version_info [ : <NUM_LIT:2> ] < ( <NUM_LIT:3> , <NUM_LIT:4> ) : <EOL> unescape = HTMLParser ( ) . unescape <EOL> else : <EOL> from html import unescape <EOL> try : <EOL> from collections import ChainMap <EOL> except ImportError : <EOL> from collections import MutableMapping <EOL> try : <EOL> from reprlib import recursive_repr as _recursive_repr <EOL> except ImportError : <EOL> def _recursive_repr ( fillvalue = '<STR_LIT>' ) : <EOL> '''<STR_LIT>''' <EOL> def decorating_function ( user_function ) : <EOL> repr_running = set ( ) <EOL> def wrapper ( self ) : <EOL> key = id ( self ) , get_ident ( ) <EOL> if key in repr_running : <EOL> return fillvalue <EOL> repr_running . add ( key ) <EOL> try : <EOL> result = user_function ( self ) <EOL> finally : <EOL> repr_running . discard ( key ) <EOL> return result <EOL> wrapper . __module__ = getattr ( user_function , '<STR_LIT>' ) <EOL> wrapper . __doc__ = getattr ( user_function , '<STR_LIT>' ) <EOL> wrapper . __name__ = getattr ( user_function , '<STR_LIT>' ) <EOL> wrapper . __annotations__ = getattr ( user_function , '<STR_LIT>' , { } ) <EOL> return wrapper <EOL> return decorating_function <EOL> class ChainMap ( MutableMapping ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , * maps ) : <EOL> '''<STR_LIT>''' <EOL> self . maps = list ( maps ) or [ { } ] <EOL> def __missing__ ( self , key ) : <EOL> raise KeyError ( key ) <EOL> def __getitem__ ( self , key ) : <EOL> for mapping in self . maps : <EOL> try : <EOL> return mapping [ key ] <EOL> except KeyError : <EOL> pass <EOL> return self . __missing__ ( key ) <EOL> def get ( self , key , default = None ) : <EOL> return self [ key ] if key in self else default <EOL> def __len__ ( self ) : <EOL> return len ( set ( ) . union ( * self . maps ) ) <EOL> def __iter__ ( self ) : <EOL> return iter ( set ( ) . union ( * self . maps ) ) <EOL> def __contains__ ( self , key ) : <EOL> return any ( key in m for m in self . maps ) <EOL> def __bool__ ( self ) : <EOL> return any ( self . maps ) <EOL> @ _recursive_repr ( ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' . format ( <EOL> self , '<STR_LIT:U+002CU+0020>' . join ( map ( repr , self . maps ) ) ) <EOL> @ classmethod <EOL> def fromkeys ( cls , iterable , * args ) : <EOL> '<STR_LIT>' <EOL> return cls ( dict . fromkeys ( iterable , * args ) ) <EOL> def copy ( self ) : <EOL> '<STR_LIT>' <EOL> return self . __class__ ( self . maps [ <NUM_LIT:0> ] . copy ( ) , * self . maps [ <NUM_LIT:1> : ] ) <EOL> __copy__ = copy <EOL> def new_child ( self ) : <EOL> '<STR_LIT>' <EOL> return self . __class__ ( { } , * self . maps ) <EOL> @ property <EOL> def parents ( self ) : <EOL> '<STR_LIT>' <EOL> return self . __class__ ( * self . maps [ <NUM_LIT:1> : ] ) <EOL> def __setitem__ ( self , key , value ) : <EOL> self . maps [ <NUM_LIT:0> ] [ key ] = value <EOL> def __delitem__ ( self , key ) : <EOL> try : <EOL> del self . maps [ <NUM_LIT:0> ] [ key ] <EOL> except KeyError : <EOL> raise KeyError ( '<STR_LIT>' . format ( key ) ) <EOL> def popitem ( self ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> return self . maps [ <NUM_LIT:0> ] . popitem ( ) <EOL> except KeyError : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> def pop ( self , key , * args ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> return self . maps [ <NUM_LIT:0> ] . pop ( key , * args ) <EOL> except KeyError : <EOL> raise KeyError ( '<STR_LIT>' . format ( key ) ) <EOL> def clear ( self ) : <EOL> '<STR_LIT>' <EOL> self . maps [ <NUM_LIT:0> ] . clear ( ) <EOL> try : <EOL> from imp import cache_from_source <EOL> except ImportError : <EOL> def cache_from_source ( path , debug_override = None ) : <EOL> assert path . endswith ( '<STR_LIT>' ) <EOL> if debug_override is None : <EOL> debug_override = __debug__ <EOL> if debug_override : <EOL> suffix = '<STR_LIT:c>' <EOL> else : <EOL> suffix = '<STR_LIT:o>' <EOL> return path + suffix <EOL> try : <EOL> from collections import OrderedDict <EOL> except ImportError : <EOL> try : <EOL> from thread import get_ident as _get_ident <EOL> except ImportError : <EOL> from dummy_thread import get_ident as _get_ident <EOL> try : <EOL> from _abcoll import KeysView , ValuesView , ItemsView <EOL> except ImportError : <EOL> pass <EOL> class OrderedDict ( dict ) : <EOL> '<STR_LIT>' <EOL> def __init__ ( self , * args , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> if len ( args ) > <NUM_LIT:1> : <EOL> raise TypeError ( '<STR_LIT>' % len ( args ) ) <EOL> try : <EOL> self . __root <EOL> except AttributeError : <EOL> self . __root = root = [ ] <EOL> root [ : ] = [ root , root , None ] <EOL> self . __map = { } <EOL> self . __update ( * args , ** kwds ) <EOL> def __setitem__ ( self , key , value , dict_setitem = dict . __setitem__ ) : <EOL> '<STR_LIT>' <EOL> if key not in self : <EOL> root = self . __root <EOL> last = root [ <NUM_LIT:0> ] <EOL> last [ <NUM_LIT:1> ] = root [ <NUM_LIT:0> ] = self . __map [ key ] = [ last , root , key ] <EOL> dict_setitem ( self , key , value ) <EOL> def __delitem__ ( self , key , dict_delitem = dict . __delitem__ ) : <EOL> '<STR_LIT>' <EOL> dict_delitem ( self , key ) <EOL> link_prev , link_next , key = self . __map . pop ( key ) <EOL> link_prev [ <NUM_LIT:1> ] = link_next <EOL> link_next [ <NUM_LIT:0> ] = link_prev <EOL> def __iter__ ( self ) : <EOL> '<STR_LIT>' <EOL> root = self . __root <EOL> curr = root [ <NUM_LIT:1> ] <EOL> while curr is not root : <EOL> yield curr [ <NUM_LIT:2> ] <EOL> curr = curr [ <NUM_LIT:1> ] <EOL> def __reversed__ ( self ) : <EOL> '<STR_LIT>' <EOL> root = self . __root <EOL> curr = root [ <NUM_LIT:0> ] <EOL> while curr is not root : <EOL> yield curr [ <NUM_LIT:2> ] <EOL> curr = curr [ <NUM_LIT:0> ] <EOL> def clear ( self ) : <EOL> '<STR_LIT>' <EOL> try : <EOL> for node in self . __map . itervalues ( ) : <EOL> del node [ : ] <EOL> root = self . __root <EOL> root [ : ] = [ root , root , None ] <EOL> self . __map . clear ( ) <EOL> except AttributeError : <EOL> pass <EOL> dict . clear ( self ) <EOL> def popitem ( self , last = True ) : <EOL> '''<STR_LIT>''' <EOL> if not self : <EOL> raise KeyError ( '<STR_LIT>' ) <EOL> root = self . __root <EOL> if last : <EOL> link = root [ <NUM_LIT:0> ] <EOL> link_prev = link [ <NUM_LIT:0> ] <EOL> link_prev [ <NUM_LIT:1> ] = root <EOL> root [ <NUM_LIT:0> ] = link_prev <EOL> else : <EOL> link = root [ <NUM_LIT:1> ] <EOL> link_next = link [ <NUM_LIT:1> ] <EOL> root [ <NUM_LIT:1> ] = link_next <EOL> link_next [ <NUM_LIT:0> ] = root <EOL> key = link [ <NUM_LIT:2> ] <EOL> del self . __map [ key ] <EOL> value = dict . pop ( self , key ) <EOL> return key , value <EOL> def keys ( self ) : <EOL> '<STR_LIT>' <EOL> return list ( self ) <EOL> def values ( self ) : <EOL> '<STR_LIT>' <EOL> return [ self [ key ] for key in self ] <EOL> def items ( self ) : <EOL> '<STR_LIT>' <EOL> return [ ( key , self [ key ] ) for key in self ] <EOL> def iterkeys ( self ) : <EOL> '<STR_LIT>' <EOL> return iter ( self ) <EOL> def itervalues ( self ) : <EOL> '<STR_LIT>' <EOL> for k in self : <EOL> yield self [ k ] <EOL> def iteritems ( self ) : <EOL> '<STR_LIT>' <EOL> for k in self : <EOL> yield ( k , self [ k ] ) <EOL> def update ( * args , ** kwds ) : <EOL> '''<STR_LIT>''' <EOL> if len ( args ) > <NUM_LIT:2> : <EOL> raise TypeError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( len ( args ) , ) ) <EOL> elif not args : <EOL> raise TypeError ( '<STR_LIT>' ) <EOL> self = args [ <NUM_LIT:0> ] <EOL> other = ( ) <EOL> if len ( args ) == <NUM_LIT:2> : <EOL> other = args [ <NUM_LIT:1> ] <EOL> if isinstance ( other , dict ) : <EOL> for key in other : <EOL> self [ key ] = other [ key ] <EOL> elif hasattr ( other , '<STR_LIT>' ) : <EOL> for key in other . keys ( ) : <EOL> self [ key ] = other [ key ] <EOL> else : <EOL> for key , value in other : <EOL> self [ key ] = value <EOL> for key , value in kwds . items ( ) : <EOL> self [ key ] = value <EOL> __update = update <EOL> __marker = object ( ) <EOL> def pop ( self , key , default = __marker ) : <EOL> '''<STR_LIT>''' <EOL> if key in self : <EOL> result = self [ key ] <EOL> del self [ key ] <EOL> return result <EOL> if default is self . __marker : <EOL> raise KeyError ( key ) <EOL> return default <EOL> def setdefault ( self , key , default = None ) : <EOL> '<STR_LIT>' <EOL> if key in self : <EOL> return self [ key ] <EOL> self [ key ] = default <EOL> return default <EOL> def __repr__ ( self , _repr_running = None ) : <EOL> '<STR_LIT>' <EOL> if not _repr_running : _repr_running = { } <EOL> call_key = id ( self ) , _get_ident ( ) <EOL> if call_key in _repr_running : <EOL> return '<STR_LIT>' <EOL> _repr_running [ call_key ] = <NUM_LIT:1> <EOL> try : <EOL> if not self : <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , ) <EOL> return '<STR_LIT>' % ( self . __class__ . __name__ , self . items ( ) ) <EOL> finally : <EOL> del _repr_running [ call_key ] <EOL> def __reduce__ ( self ) : <EOL> '<STR_LIT>' <EOL> items = [ [ k , self [ k ] ] for k in self ] <EOL> inst_dict = vars ( self ) . copy ( ) <EOL> for k in vars ( OrderedDict ( ) ) : <EOL> inst_dict . pop ( k , None ) <EOL> if inst_dict : <EOL> return ( self . __class__ , ( items , ) , inst_dict ) <EOL> return self . __class__ , ( items , ) <EOL> def copy ( self ) : <EOL> '<STR_LIT>' <EOL> return self . __class__ ( self ) <EOL> @ classmethod <EOL> def fromkeys ( cls , iterable , value = None ) : <EOL> '''<STR_LIT>''' <EOL> d = cls ( ) <EOL> for key in iterable : <EOL> d [ key ] = value <EOL> return d <EOL> def __eq__ ( self , other ) : <EOL> '''<STR_LIT>''' <EOL> if isinstance ( other , OrderedDict ) : <EOL> return len ( self ) == len ( other ) and self . items ( ) == other . items ( ) <EOL> return dict . __eq__ ( self , other ) <EOL> def __ne__ ( self , other ) : <EOL> return not self == other <EOL> def viewkeys ( self ) : <EOL> "<STR_LIT>" <EOL> return KeysView ( self ) <EOL> def viewvalues ( self ) : <EOL> "<STR_LIT>" <EOL> return ValuesView ( self ) <EOL> def viewitems ( self ) : <EOL> "<STR_LIT>" <EOL> return ItemsView ( self ) <EOL> try : <EOL> from logging . config import BaseConfigurator , valid_ident <EOL> except ImportError : <EOL> IDENTIFIER = re . compile ( '<STR_LIT>' , re . I ) <EOL> def valid_ident ( s ) : <EOL> m = IDENTIFIER . match ( s ) <EOL> if not m : <EOL> raise ValueError ( '<STR_LIT>' % s ) <EOL> return True <EOL> class ConvertingDict ( dict ) : <EOL> """<STR_LIT>""" <EOL> def __getitem__ ( self , key ) : <EOL> value = dict . __getitem__ ( self , key ) <EOL> result = self . configurator . convert ( value ) <EOL> if value is not result : <EOL> self [ key ] = result <EOL> if type ( result ) in ( ConvertingDict , ConvertingList , <EOL> ConvertingTuple ) : <EOL> result . parent = self <EOL> result . key = key <EOL> return result <EOL> def get ( self , key , default = None ) : <EOL> value = dict . get ( self , key , default ) <EOL> result = self . configurator . convert ( value ) <EOL> if value is not result : <EOL> self [ key ] = result <EOL> if type ( result ) in ( ConvertingDict , ConvertingList , <EOL> ConvertingTuple ) : <EOL> result . parent = self <EOL> result . key = key <EOL> return result <EOL> def pop ( self , key , default = None ) : <EOL> value = dict . pop ( self , key , default ) <EOL> result = self . configurator . convert ( value ) <EOL> if value is not result : <EOL> if type ( result ) in ( ConvertingDict , ConvertingList , <EOL> ConvertingTuple ) : <EOL> result . parent = self <EOL> result . key = key <EOL> return result <EOL> class ConvertingList ( list ) : <EOL> """<STR_LIT>""" <EOL> def __getitem__ ( self , key ) : <EOL> value = list . __getitem__ ( self , key ) <EOL> result = self . configurator . convert ( value ) <EOL> if value is not result : <EOL> self [ key ] = result <EOL> if type ( result ) in ( ConvertingDict , ConvertingList , <EOL> ConvertingTuple ) : <EOL> result . parent = self <EOL> result . key = key <EOL> return result <EOL> def pop ( self , idx = - <NUM_LIT:1> ) : <EOL> value = list . pop ( self , idx ) <EOL> result = self . configurator . convert ( value ) <EOL> if value is not result : <EOL> if type ( result ) in ( ConvertingDict , ConvertingList , <EOL> ConvertingTuple ) : <EOL> result . parent = self <EOL> return result <EOL> class ConvertingTuple ( tuple ) : <EOL> """<STR_LIT>""" <EOL> def __getitem__ ( self , key ) : <EOL> value = tuple . __getitem__ ( self , key ) <EOL> result = self . configurator . convert ( value ) <EOL> if value is not result : <EOL> if type ( result ) in ( ConvertingDict , ConvertingList , <EOL> ConvertingTuple ) : <EOL> result . parent = self <EOL> result . key = key <EOL> return result <EOL> class BaseConfigurator ( object ) : <EOL> """<STR_LIT>""" <EOL> CONVERT_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> WORD_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> DOT_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> INDEX_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> DIGIT_PATTERN = re . compile ( r'<STR_LIT>' ) <EOL> value_converters = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> importer = staticmethod ( __import__ ) <EOL> def __init__ ( self , config ) : <EOL> self . config = ConvertingDict ( config ) <EOL> self . config . configurator = self <EOL> def resolve ( self , s ) : <EOL> """<STR_LIT>""" <EOL> name = s . split ( '<STR_LIT:.>' ) <EOL> used = name . pop ( <NUM_LIT:0> ) <EOL> try : <EOL> found = self . importer ( used ) <EOL> for frag in name : <EOL> used += '<STR_LIT:.>' + frag <EOL> try : <EOL> found = getattr ( found , frag ) <EOL> except AttributeError : <EOL> self . importer ( used ) <EOL> found = getattr ( found , frag ) <EOL> return found <EOL> except ImportError : <EOL> e , tb = sys . exc_info ( ) [ <NUM_LIT:1> : ] <EOL> v = ValueError ( '<STR_LIT>' % ( s , e ) ) <EOL> v . __cause__ , v . __traceback__ = e , tb <EOL> raise v <EOL> def ext_convert ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return self . resolve ( value ) <EOL> def cfg_convert ( self , value ) : <EOL> """<STR_LIT>""" <EOL> rest = value <EOL> m = self . WORD_PATTERN . match ( rest ) <EOL> if m is None : <EOL> raise ValueError ( "<STR_LIT>" % value ) <EOL> else : <EOL> rest = rest [ m . end ( ) : ] <EOL> d = self . config [ m . groups ( ) [ <NUM_LIT:0> ] ] <EOL> while rest : <EOL> m = self . DOT_PATTERN . match ( rest ) <EOL> if m : <EOL> d = d [ m . groups ( ) [ <NUM_LIT:0> ] ] <EOL> else : <EOL> m = self . INDEX_PATTERN . match ( rest ) <EOL> if m : <EOL> idx = m . groups ( ) [ <NUM_LIT:0> ] <EOL> if not self . DIGIT_PATTERN . match ( idx ) : <EOL> d = d [ idx ] <EOL> else : <EOL> try : <EOL> n = int ( idx ) <EOL> d = d [ n ] <EOL> except TypeError : <EOL> d = d [ idx ] <EOL> if m : <EOL> rest = rest [ m . end ( ) : ] <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' % ( value , rest ) ) <EOL> return d <EOL> def convert ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( value , ConvertingDict ) and isinstance ( value , dict ) : <EOL> value = ConvertingDict ( value ) <EOL> value . configurator = self <EOL> elif not isinstance ( value , ConvertingList ) and isinstance ( value , list ) : <EOL> value = ConvertingList ( value ) <EOL> value . configurator = self <EOL> elif not isinstance ( value , ConvertingTuple ) and isinstance ( value , tuple ) : <EOL> value = ConvertingTuple ( value ) <EOL> value . configurator = self <EOL> elif isinstance ( value , string_types ) : <EOL> m = self . CONVERT_PATTERN . match ( value ) <EOL> if m : <EOL> d = m . groupdict ( ) <EOL> prefix = d [ '<STR_LIT>' ] <EOL> converter = self . value_converters . get ( prefix , None ) <EOL> if converter : <EOL> suffix = d [ '<STR_LIT>' ] <EOL> converter = getattr ( self , converter ) <EOL> value = converter ( suffix ) <EOL> return value <EOL> def configure_custom ( self , config ) : <EOL> """<STR_LIT>""" <EOL> c = config . pop ( '<STR_LIT>' ) <EOL> if not callable ( c ) : <EOL> c = self . resolve ( c ) <EOL> props = config . pop ( '<STR_LIT:.>' , None ) <EOL> kwargs = dict ( [ ( k , config [ k ] ) for k in config if valid_ident ( k ) ] ) <EOL> result = c ( ** kwargs ) <EOL> if props : <EOL> for name , value in props . items ( ) : <EOL> setattr ( result , name , value ) <EOL> return result <EOL> def as_tuple ( self , value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , list ) : <EOL> value = tuple ( value ) <EOL> return value </s>
