<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> from rest_framework . routers import SimpleRouter , DefaultRouter <EOL> class LookupMixin ( object ) : <EOL> """<STR_LIT>""" <EOL> class NestedSimpleRouter ( SimpleRouter ) : <EOL> def __init__ ( self , parent_router , parent_prefix , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . parent_router = parent_router <EOL> self . parent_prefix = parent_prefix <EOL> self . nest_count = getattr ( parent_router , '<STR_LIT>' , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> self . nest_prefix = kwargs . pop ( '<STR_LIT>' , '<STR_LIT>' % self . nest_count ) + '<STR_LIT:_>' <EOL> super ( NestedSimpleRouter , self ) . __init__ ( * args , ** kwargs ) <EOL> parent_registry = [ registered for registered in self . parent_router . registry if registered [ <NUM_LIT:0> ] == self . parent_prefix ] <EOL> try : <EOL> parent_registry = parent_registry [ <NUM_LIT:0> ] <EOL> parent_prefix , parent_viewset , parent_basename = parent_registry <EOL> except : <EOL> raise RuntimeError ( '<STR_LIT>' ) <EOL> nested_routes = [ ] <EOL> parent_lookup_regex = parent_router . get_lookup_regex ( parent_viewset , self . nest_prefix ) <EOL> self . parent_regex = '<STR_LIT>' . format ( <EOL> parent_prefix = parent_prefix , <EOL> parent_lookup_regex = parent_lookup_regex <EOL> ) <EOL> if hasattr ( parent_router , '<STR_LIT>' ) : <EOL> self . parent_regex = parent_router . parent_regex + self . parent_regex <EOL> for route in self . routes : <EOL> route_contents = route . _asdict ( ) <EOL> escaped_parent_regex = self . parent_regex . replace ( '<STR_LIT:{>' , '<STR_LIT>' ) . replace ( '<STR_LIT:}>' , '<STR_LIT>' ) <EOL> route_contents [ '<STR_LIT:url>' ] = route . url . replace ( '<STR_LIT>' , '<STR_LIT>' + escaped_parent_regex ) <EOL> nested_routes . append ( type ( route ) ( ** route_contents ) ) <EOL> self . routes = nested_routes </s>
