#NEWLINE# def resource_factory( self , name , schema , resource_cls = None ) : #NEWLINE# #INDENT# '\n        Registers a new resource with a given schema. The schema must not have any unresolved references\n        (such as `{"$ref": "#"}` for self-references, or otherwise). A subclass of :class:`Resource`\n        may be provided to add specific functionality to the resulting :class:`Resource`.\n\n        :param str name:\n        :param dict schema:\n        :param Resource resource_cls: a subclass of :class:`Resource` or None\n        :return: The new :class:`Resource`.\n        ' #NEWLINE# cls = type ( str ( upper_camel_case ( name ) ) , ( ( resource_cls or Resource ) , collections . MutableMapping ) , { #NEWLINE# #INDENT# '__doc__' : schema . get ( 'description' , '' ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# cls . _schema = schema #NEWLINE# cls . _client = self #NEWLINE# cls . _links = links = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for link_schema in schema [ 'links' ] : #NEWLINE# #INDENT# link = Link ( self , rel = link_schema [ 'rel' ] , href = link_schema [ 'href' ] , method = link_schema [ 'method' ] , schema = link_schema . get ( 'schema' , None ) , target_schema = link_schema . get ( 'targetSchema' , None ) ) #NEWLINE# if ( link . rel in ( 'self' , 'instances' , 'create' , 'update' , 'destroy' ) ) : #NEWLINE# #INDENT# setattr ( cls , '_{}' . format ( link . rel ) , link ) #NEWLINE# #UNINDENT# links [ link . rel ] = link #NEWLINE# if ( link . rel != 'update' ) : #NEWLINE# #INDENT# setattr ( cls , snake_case ( link . rel ) , link ) #NEWLINE# #UNINDENT# #UNINDENT# for ( property_name , property_schema ) in schema [ 'properties' ] . items ( ) : #NEWLINE# #INDENT# if property_name . startswith ( '$' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if property_schema . get ( 'readOnly' , False ) : #NEWLINE# #INDENT# setattr ( cls , property_name , property ( fget = partial ( ( lambda name , obj : getitem ( obj , name ) ) , property_name ) , doc = property_schema . get ( 'description' , None ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# setattr ( cls , property_name , property ( fget = partial ( ( lambda name , obj : getitem ( obj , name ) ) , property_name ) , fset = partial ( ( lambda name , obj , value : setitem ( obj , name , value ) ) , property_name ) , fdel = partial ( ( lambda name , obj : delitem ( obj , name ) ) , property_name ) , doc = property_schema . get ( 'description' , None ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# root = None #NEWLINE# if ( 'instances' in links ) : #NEWLINE# #INDENT# root = cls . _instances . href #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'self' in links ) : #NEWLINE# #INDENT# root = cls . _self . href [ : cls . _self . href . rfind ( '/' ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# root = ( ( self . _root_path + '/' ) + name . replace ( '_' , '-' ) ) #NEWLINE# #UNINDENT# #UNINDENT# self . _resources [ root ] = cls #NEWLINE# return cls