<s> """<STR_LIT>""" <EOL> try : <EOL> from simplejson import dumps <EOL> except ImportError : <EOL> try : <EOL> from json import dumps <EOL> except ImportError : <EOL> def dumps ( * args ) : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> from inspect import getmro <EOL> from werkzeug . routing import NumberConverter <EOL> from werkzeug . _compat import iteritems <EOL> def render_template ( name_parts , rules , converters ) : <EOL> result = u'<STR_LIT>' <EOL> if name_parts : <EOL> for idx in range ( <NUM_LIT:0> , len ( name_parts ) - <NUM_LIT:1> ) : <EOL> name = u'<STR_LIT:.>' . join ( name_parts [ : idx + <NUM_LIT:1> ] ) <EOL> result += u"<STR_LIT>" % ( name , name ) <EOL> result += '<STR_LIT>' % '<STR_LIT:.>' . join ( name_parts ) <EOL> result += """<STR_LIT>""" % { '<STR_LIT>' : u'<STR_LIT:U+002CU+0020>' . join ( converters ) , <EOL> '<STR_LIT>' : rules } <EOL> return result <EOL> def generate_map ( map , name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> from warnings import warn <EOL> warn ( DeprecationWarning ( '<STR_LIT>' ) ) <EOL> map . update ( ) <EOL> rules = [ ] <EOL> converters = [ ] <EOL> for rule in map . iter_rules ( ) : <EOL> trace = [ { <EOL> '<STR_LIT>' : is_dynamic , <EOL> '<STR_LIT:data>' : data <EOL> } for is_dynamic , data in rule . _trace ] <EOL> rule_converters = { } <EOL> for key , converter in iteritems ( rule . _converters ) : <EOL> js_func = js_to_url_function ( converter ) <EOL> try : <EOL> index = converters . index ( js_func ) <EOL> except ValueError : <EOL> converters . append ( js_func ) <EOL> index = len ( converters ) - <NUM_LIT:1> <EOL> rule_converters [ key ] = index <EOL> rules . append ( { <EOL> u'<STR_LIT>' : rule . endpoint , <EOL> u'<STR_LIT>' : list ( rule . arguments ) , <EOL> u'<STR_LIT>' : rule_converters , <EOL> u'<STR_LIT>' : trace , <EOL> u'<STR_LIT>' : rule . defaults <EOL> } ) <EOL> return render_template ( name_parts = name and name . split ( '<STR_LIT:.>' ) or [ ] , <EOL> rules = dumps ( rules ) , <EOL> converters = converters ) <EOL> def generate_adapter ( adapter , name = '<STR_LIT>' , map_name = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> values = { <EOL> u'<STR_LIT>' : dumps ( adapter . server_name ) , <EOL> u'<STR_LIT>' : dumps ( adapter . script_name ) , <EOL> u'<STR_LIT>' : dumps ( adapter . subdomain ) , <EOL> u'<STR_LIT>' : dumps ( adapter . url_scheme ) , <EOL> u'<STR_LIT:name>' : name , <EOL> u'<STR_LIT>' : map_name <EOL> } <EOL> return u'''<STR_LIT>''' % values <EOL> def js_to_url_function ( converter ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( converter , '<STR_LIT>' ) : <EOL> data = converter . js_to_url_function ( ) <EOL> else : <EOL> for cls in getmro ( type ( converter ) ) : <EOL> if cls in js_to_url_functions : <EOL> data = js_to_url_functions [ cls ] ( converter ) <EOL> break <EOL> else : <EOL> return '<STR_LIT>' <EOL> return '<STR_LIT>' % data <EOL> def NumberConverter_js_to_url ( conv ) : <EOL> if conv . fixed_digits : <EOL> return u'''<STR_LIT>''' % conv . fixed_digits <EOL> return u'<STR_LIT>' <EOL> js_to_url_functions = { <EOL> NumberConverter : NumberConverter_js_to_url <EOL> } </s>
