<s> """<STR_LIT>""" <EOL> import new <EOL> import re <EOL> import sys <EOL> import urllib <EOL> import urllib2 <EOL> import urlparse <EOL> from string import Template <EOL> from pyactiveresource import connection <EOL> from pyactiveresource import element_containers <EOL> from pyactiveresource import formats <EOL> from pyactiveresource import util <EOL> VALID_NAME = re . compile ( '<STR_LIT>' ) <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Errors ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , base ) : <EOL> """<STR_LIT>""" <EOL> self . base = base <EOL> self . errors = { } <EOL> @ property <EOL> def size ( self ) : <EOL> return len ( self . errors ) <EOL> def __len__ ( self ) : <EOL> return len ( self . errors ) <EOL> def add ( self , attribute , error ) : <EOL> """<STR_LIT>""" <EOL> self . errors . setdefault ( attribute , [ ] ) . append ( error ) <EOL> def add_to_base ( self , error ) : <EOL> """<STR_LIT>""" <EOL> self . add ( '<STR_LIT>' , error ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> self . errors = { } <EOL> def from_xml ( self , xml_string ) : <EOL> """<STR_LIT>""" <EOL> attribute_keys = self . base . attributes . keys ( ) <EOL> try : <EOL> messages = util . xml_to_dict ( <EOL> xml_string ) [ '<STR_LIT>' ] [ '<STR_LIT:error>' ] <EOL> if not isinstance ( messages , list ) : <EOL> messages = [ messages ] <EOL> except util . Error : <EOL> messages = [ ] <EOL> for message in messages : <EOL> attr_name = message . split ( ) [ <NUM_LIT:0> ] <EOL> key = util . underscore ( attr_name ) <EOL> if key in attribute_keys : <EOL> self . add ( key , message [ len ( attr_name ) + <NUM_LIT:1> : ] ) <EOL> else : <EOL> self . add_to_base ( message ) <EOL> def on ( self , attribute ) : <EOL> """<STR_LIT>""" <EOL> errors = self . errors . get ( attribute , [ ] ) <EOL> if len ( errors ) == <NUM_LIT:1> : <EOL> return errors [ <NUM_LIT:0> ] <EOL> return errors <EOL> def full_messages ( self ) : <EOL> """<STR_LIT>""" <EOL> messages = [ ] <EOL> for key , errors in self . errors . items ( ) : <EOL> for error in errors : <EOL> if key == '<STR_LIT>' : <EOL> messages . append ( error ) <EOL> else : <EOL> messages . append ( '<STR_LIT:U+0020>' . join ( ( key , error ) ) ) <EOL> return messages <EOL> class ClassAndInstanceMethod ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , class_method , instance_method ) : <EOL> self . class_method = class_method <EOL> self . instance_method = instance_method <EOL> def __get__ ( self , instance , owner ) : <EOL> if instance : <EOL> return getattr ( instance , self . instance_method ) <EOL> return getattr ( owner , self . class_method ) <EOL> class ResourceMeta ( type ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( mcs , name , bases , new_attrs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' not in new_attrs or not new_attrs [ '<STR_LIT>' ] : <EOL> new_attrs [ '<STR_LIT>' ] = util . underscore ( name ) <EOL> if '<STR_LIT>' not in new_attrs or not new_attrs [ '<STR_LIT>' ] : <EOL> new_attrs [ '<STR_LIT>' ] = util . pluralize ( new_attrs [ '<STR_LIT>' ] ) <EOL> klass = type . __new__ ( mcs , name , bases , new_attrs ) <EOL> if '<STR_LIT>' in new_attrs : <EOL> klass . site = new_attrs [ '<STR_LIT>' ] <EOL> return klass <EOL> @ property <EOL> def connection ( cls ) : <EOL> """<STR_LIT>""" <EOL> super_class = cls . __mro__ [ <NUM_LIT:1> ] <EOL> if super_class == object or '<STR_LIT>' in cls . __dict__ : <EOL> if cls . _connection is None : <EOL> cls . _connection = connection . Connection ( <EOL> cls . site , cls . user , cls . password , cls . timeout , cls . format ) <EOL> return cls . _connection <EOL> else : <EOL> return super_class . connection <EOL> def get_user ( cls ) : <EOL> return cls . _user <EOL> def set_user ( cls , value ) : <EOL> cls . _connection = None <EOL> cls . _user = value <EOL> user = property ( get_user , set_user , None , <EOL> '<STR_LIT>' ) <EOL> def get_password ( cls ) : <EOL> return cls . _password <EOL> def set_password ( cls , value ) : <EOL> cls . _connection = None <EOL> cls . _password = value <EOL> password = property ( get_password , set_password , None , <EOL> '<STR_LIT>' ) <EOL> def get_site ( cls ) : <EOL> return cls . _site <EOL> def set_site ( cls , value ) : <EOL> if value is not None : <EOL> host = urlparse . urlsplit ( value ) [ <NUM_LIT:1> ] <EOL> auth_info , host = urllib2 . splituser ( host ) <EOL> if auth_info : <EOL> user , password = urllib2 . splitpasswd ( auth_info ) <EOL> if user : <EOL> cls . _user = urllib . unquote ( user ) <EOL> if password : <EOL> cls . _password = urllib . unquote ( password ) <EOL> cls . _connection = None <EOL> cls . _site = value <EOL> site = property ( get_site , set_site , None , <EOL> '<STR_LIT>' ) <EOL> def get_headers ( cls ) : <EOL> return cls . _headers <EOL> def set_headers ( cls , value ) : <EOL> cls . _headers = value <EOL> headers = property ( get_headers , set_headers , None , <EOL> '<STR_LIT>' ) <EOL> def get_timeout ( cls ) : <EOL> return cls . _timeout <EOL> def set_timeout ( cls , value ) : <EOL> cls . _connection = None <EOL> cls . _timeout = value <EOL> timeout = property ( get_timeout , set_timeout , None , <EOL> '<STR_LIT>' ) <EOL> def get_format ( cls ) : <EOL> return cls . _format <EOL> def set_format ( cls , value ) : <EOL> cls . _connection = None <EOL> cls . _format = value <EOL> format = property ( get_format , set_format , None , <EOL> '<STR_LIT>' ) <EOL> def get_plural ( cls ) : <EOL> return cls . _plural <EOL> def set_plural ( cls , value ) : <EOL> cls . _plural = value <EOL> plural = property ( get_plural , set_plural , None , <EOL> '<STR_LIT>' ) <EOL> def get_singular ( cls ) : <EOL> return cls . _singular <EOL> def set_singular ( cls , value ) : <EOL> cls . _singular = value <EOL> singular = property ( get_singular , set_singular , None , <EOL> '<STR_LIT>' ) <EOL> def get_prefix_source ( cls ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( cls , '<STR_LIT>' ) : <EOL> return cls . _prefix_source <EOL> else : <EOL> return urlparse . urlsplit ( cls . site ) [ <NUM_LIT:2> ] <EOL> def set_prefix_source ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> cls . _prefix_source = value <EOL> prefix_source = property ( get_prefix_source , set_prefix_source , None , <EOL> '<STR_LIT>' ) <EOL> def prefix ( cls , options = None ) : <EOL> """<STR_LIT>""" <EOL> return cls . _prefix ( options ) <EOL> def get_primary_key ( cls ) : <EOL> return cls . _primary_key <EOL> def set_primary_key ( cls , value ) : <EOL> cls . _primary_key = value <EOL> primary_key = property ( get_primary_key , set_primary_key , None , <EOL> '<STR_LIT>' ) <EOL> class ActiveResource ( object ) : <EOL> """<STR_LIT>""" <EOL> __metaclass__ = ResourceMeta <EOL> _connection = None <EOL> _format = formats . XMLFormat <EOL> _headers = None <EOL> _password = None <EOL> _site = None <EOL> _timeout = None <EOL> _user = None <EOL> _primary_key = "<STR_LIT:id>" <EOL> def __init__ ( self , attributes = None , prefix_options = None ) : <EOL> """<STR_LIT>""" <EOL> if attributes is None : <EOL> attributes = { } <EOL> self . klass = self . __class__ <EOL> self . attributes = { } <EOL> if prefix_options : <EOL> self . _prefix_options = prefix_options <EOL> else : <EOL> self . _prefix_options = { } <EOL> self . _update ( attributes ) <EOL> self . errors = Errors ( self ) <EOL> self . _initialized = True <EOL> @ classmethod <EOL> def find ( cls , id_ = None , from_ = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if id_ : <EOL> return cls . _find_single ( id_ , ** kwargs ) <EOL> return cls . _find_every ( from_ = from_ , ** kwargs ) <EOL> @ classmethod <EOL> def find_first ( cls , from_ = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> resources = cls . _find_every ( from_ = from_ , ** kwargs ) <EOL> if resources : <EOL> return resources [ <NUM_LIT:0> ] <EOL> @ classmethod <EOL> def find_one ( cls , from_ , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return cls . _find_one ( from_ , kwargs ) <EOL> @ classmethod <EOL> def exists ( cls , id_ , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> prefix_options , query_options = cls . _split_options ( kwargs ) <EOL> path = cls . _element_path ( id_ , prefix_options , query_options ) <EOL> try : <EOL> _ = cls . connection . head ( path , cls . headers ) <EOL> return True <EOL> except connection . Error : <EOL> return False <EOL> @ classmethod <EOL> def create ( cls , attributes ) : <EOL> """<STR_LIT>""" <EOL> resource = cls ( attributes ) <EOL> resource . save ( ) <EOL> return resource <EOL> @ classmethod <EOL> def _split_options ( cls , options ) : <EOL> """<STR_LIT>""" <EOL> prefix_options = { } <EOL> query_options = { } <EOL> for key , value in options . iteritems ( ) : <EOL> if key in cls . _prefix_parameters ( ) : <EOL> prefix_options [ key ] = value <EOL> else : <EOL> query_options [ key ] = value <EOL> return [ prefix_options , query_options ] <EOL> @ classmethod <EOL> def _find_single ( cls , id_ , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> prefix_options , query_options = cls . _split_options ( kwargs ) <EOL> path = cls . _element_path ( id_ , prefix_options , query_options ) <EOL> return cls . _build_object ( cls . connection . get ( path , cls . headers ) , <EOL> prefix_options ) <EOL> @ classmethod <EOL> def _find_one ( cls , from_ , query_options ) : <EOL> """<STR_LIT>""" <EOL> path = from_ + cls . _query_string ( query_options ) <EOL> return cls . _build_object ( cls . connection . get ( path , cls . headers ) ) <EOL> @ classmethod <EOL> def _find_every ( cls , from_ = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> prefix_options , query_options = cls . _split_options ( kwargs ) <EOL> if from_ : <EOL> query_options . update ( prefix_options ) <EOL> path = from_ + cls . _query_string ( query_options ) <EOL> prefix_options = None <EOL> else : <EOL> path = cls . _collection_path ( prefix_options , query_options ) <EOL> return cls . _build_list ( cls . connection . get ( path , cls . headers ) , <EOL> prefix_options ) <EOL> @ classmethod <EOL> def _build_object ( cls , attributes , prefix_options = None ) : <EOL> """<STR_LIT>""" <EOL> return cls ( attributes , prefix_options ) <EOL> @ classmethod <EOL> def _build_list ( cls , elements , prefix_options = None ) : <EOL> """<STR_LIT>""" <EOL> resources = [ ] <EOL> if isinstance ( elements , dict ) : <EOL> elements = [ elements ] <EOL> for element in elements [ : ] : <EOL> resources . append ( cls ( element , prefix_options ) ) <EOL> return resources <EOL> @ classmethod <EOL> def _query_string ( cls , query_options ) : <EOL> """<STR_LIT>""" <EOL> if query_options : <EOL> return '<STR_LIT:?>' + util . to_query ( query_options ) <EOL> else : <EOL> return '<STR_LIT>' <EOL> @ classmethod <EOL> def _element_path ( cls , id_ , prefix_options = None , query_options = None ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % { <EOL> '<STR_LIT>' : cls . _prefix ( prefix_options ) , <EOL> '<STR_LIT>' : cls . _plural , <EOL> '<STR_LIT:id>' : id_ , <EOL> '<STR_LIT>' : cls . format . extension , <EOL> '<STR_LIT>' : cls . _query_string ( query_options ) } <EOL> @ classmethod <EOL> def _collection_path ( cls , prefix_options = None , query_options = None ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' % { <EOL> '<STR_LIT>' : cls . _prefix ( prefix_options ) , <EOL> '<STR_LIT>' : cls . _plural , <EOL> '<STR_LIT>' : cls . _format . extension , <EOL> '<STR_LIT>' : cls . _query_string ( query_options ) } <EOL> @ classmethod <EOL> def _custom_method_collection_url ( cls , method_name , options ) : <EOL> """<STR_LIT>""" <EOL> prefix_options , query_options = cls . _split_options ( options ) <EOL> path = ( <EOL> '<STR_LIT>' % <EOL> { '<STR_LIT>' : cls . _prefix ( prefix_options ) , <EOL> '<STR_LIT>' : cls . _plural , <EOL> '<STR_LIT>' : method_name , <EOL> '<STR_LIT>' : cls . format . extension , <EOL> '<STR_LIT>' : cls . _query_string ( query_options ) } ) <EOL> return path <EOL> @ classmethod <EOL> def _class_get ( cls , method_name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = cls . _custom_method_collection_url ( method_name , kwargs ) <EOL> return cls . connection . get ( url , cls . headers ) <EOL> @ classmethod <EOL> def _class_post ( cls , method_name , body = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = cls . _custom_method_collection_url ( method_name , kwargs ) <EOL> return cls . connection . post ( url , cls . headers , body ) <EOL> @ classmethod <EOL> def _class_put ( cls , method_name , body = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = cls . _custom_method_collection_url ( method_name , kwargs ) <EOL> return cls . connection . put ( url , cls . headers , body ) <EOL> @ classmethod <EOL> def _class_delete ( cls , method_name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = cls . _custom_method_collection_url ( method_name , kwargs ) <EOL> return cls . connection . delete ( url , cls . headers ) <EOL> @ classmethod <EOL> def _class_head ( cls , method_name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = cls . _custom_method_collection_url ( method_name , kwargs ) <EOL> return cls . connection . head ( url , cls . headers ) <EOL> @ classmethod <EOL> def _prefix_parameters ( cls ) : <EOL> """<STR_LIT>""" <EOL> path = cls . prefix_source <EOL> template = Template ( path ) <EOL> keys = set ( ) <EOL> for match in template . pattern . finditer ( path ) : <EOL> for match_type in '<STR_LIT>' , '<STR_LIT>' : <EOL> if match . groupdict ( ) [ match_type ] : <EOL> keys . add ( match . groupdict ( ) [ match_type ] ) <EOL> return keys <EOL> @ classmethod <EOL> def _prefix ( cls , options = None ) : <EOL> """<STR_LIT>""" <EOL> if options is None : <EOL> options = { } <EOL> path = re . sub ( '<STR_LIT>' , '<STR_LIT>' , cls . prefix_source ) <EOL> template = Template ( path ) <EOL> keys = cls . _prefix_parameters ( ) <EOL> options = dict ( [ ( k , options . get ( k , '<STR_LIT>' ) ) for k in keys ] ) <EOL> return template . safe_substitute ( options ) <EOL> def to_dict ( self ) : <EOL> """<STR_LIT>""" <EOL> values = { } <EOL> for key , value in self . attributes . iteritems ( ) : <EOL> if isinstance ( value , list ) : <EOL> new_value = [ ] <EOL> for i in value : <EOL> if isinstance ( i , dict ) : <EOL> new_value . append ( i ) <EOL> else : <EOL> new_value . append ( i . to_dict ( ) ) <EOL> values [ key ] = new_value <EOL> elif isinstance ( value , ActiveResource ) : <EOL> values [ key ] = value . to_dict ( ) <EOL> else : <EOL> values [ key ] = value <EOL> return values <EOL> def to_xml ( self , root = None , header = True , pretty = False , dasherize = True ) : <EOL> """<STR_LIT>""" <EOL> if not root : <EOL> root = self . _singular <EOL> return util . to_xml ( self . to_dict ( ) , root = root , <EOL> header = header , pretty = pretty , <EOL> dasherize = dasherize ) <EOL> def reload ( self ) : <EOL> """<STR_LIT>""" <EOL> attributes = self . klass . connection . get ( <EOL> self . _element_path ( self . id , self . _prefix_options ) , <EOL> self . klass . headers ) <EOL> self . _update ( attributes ) <EOL> def save ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . errors . clear ( ) <EOL> if self . id : <EOL> response = self . klass . connection . put ( <EOL> self . _element_path ( self . id , self . _prefix_options ) , <EOL> self . klass . headers , <EOL> data = self . to_xml ( ) ) <EOL> else : <EOL> response = self . klass . connection . post ( <EOL> self . _collection_path ( self . _prefix_options ) , <EOL> self . klass . headers , <EOL> data = self . to_xml ( ) ) <EOL> new_id = self . _id_from_response ( response ) <EOL> if new_id : <EOL> self . id = new_id <EOL> except connection . ResourceInvalid , err : <EOL> self . errors . from_xml ( err . response . body ) <EOL> return False <EOL> try : <EOL> attributes = self . klass . format . decode ( response . body ) <EOL> except formats . Error : <EOL> return True <EOL> if attributes : <EOL> self . _update ( attributes ) <EOL> return True <EOL> def is_valid ( self ) : <EOL> """<STR_LIT>""" <EOL> return not len ( self . errors ) <EOL> def _id_from_response ( self , response ) : <EOL> """<STR_LIT>""" <EOL> match = re . search ( r'<STR_LIT>' , <EOL> response . get ( '<STR_LIT>' , <EOL> response . get ( '<STR_LIT:location>' , '<STR_LIT>' ) ) ) <EOL> if match : <EOL> try : <EOL> return int ( match . group ( <NUM_LIT:1> ) ) <EOL> except ValueError : <EOL> return match . group ( <NUM_LIT:1> ) <EOL> def destroy ( self ) : <EOL> """<STR_LIT>""" <EOL> self . klass . connection . delete ( <EOL> self . _element_path ( self . id , self . _prefix_options ) , <EOL> self . klass . headers ) <EOL> def get_id ( self ) : <EOL> return self . attributes . get ( self . klass . primary_key ) <EOL> def set_id ( self , value ) : <EOL> self . attributes [ self . klass . primary_key ] = value <EOL> id = property ( get_id , set_id , None , '<STR_LIT>' ) <EOL> def __getattr__ ( self , name ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> if name in self . attributes : <EOL> return self . attributes [ name ] <EOL> raise AttributeError ( name ) <EOL> def __setattr__ ( self , name , value ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in self . __dict__ : <EOL> if name in self . __dict__ or getattr ( self . __class__ , name , None ) : <EOL> object . __setattr__ ( self , name , value ) <EOL> else : <EOL> self . attributes [ name ] = value <EOL> else : <EOL> object . __setattr__ ( self , name , value ) <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % ( self . _singular , self . id ) <EOL> def __cmp__ ( self , other ) : <EOL> if isinstance ( other , self . __class__ ) : <EOL> return cmp ( self . id , other . id ) <EOL> else : <EOL> return cmp ( self . id , other ) <EOL> def __hash__ ( self ) : <EOL> return hash ( tuple ( self . attributes . items ( ) ) ) <EOL> def _update ( self , attributes ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( attributes , dict ) : <EOL> return <EOL> for key , value in attributes . items ( ) : <EOL> if isinstance ( value , dict ) : <EOL> klass = self . _find_class_for ( key ) <EOL> attr = klass ( value ) <EOL> elif isinstance ( value , list ) : <EOL> klass = self . _find_class_for_collection ( key ) <EOL> attr = [ klass ( child ) for child in value ] <EOL> else : <EOL> attr = value <EOL> self . attributes [ key ] = attr <EOL> @ classmethod <EOL> def _find_class_for_collection ( cls , collection_name ) : <EOL> """<STR_LIT>""" <EOL> return cls . _find_class_for ( util . singularize ( collection_name ) ) <EOL> @ classmethod <EOL> def _find_class_for ( cls , element_name = None , <EOL> class_name = None , create_missing = True ) : <EOL> """<STR_LIT>""" <EOL> if not element_name and not class_name : <EOL> raise Error ( '<STR_LIT>' ) <EOL> elif not element_name : <EOL> element_name = util . underscore ( class_name ) <EOL> elif not class_name : <EOL> class_name = util . camelize ( element_name ) <EOL> module_path = cls . __module__ . split ( '<STR_LIT:.>' ) <EOL> for depth in range ( len ( module_path ) , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> try : <EOL> __import__ ( '<STR_LIT:.>' . join ( module_path [ : depth ] ) ) <EOL> module = sys . modules [ '<STR_LIT:.>' . join ( module_path [ : depth ] ) ] <EOL> except ImportError : <EOL> continue <EOL> try : <EOL> klass = getattr ( module , class_name ) <EOL> return klass <EOL> except AttributeError : <EOL> try : <EOL> __import__ ( '<STR_LIT:.>' . join ( [ module . __name__ , element_name ] ) ) <EOL> submodule = sys . modules [ '<STR_LIT:.>' . join ( [ module . __name__ , <EOL> element_name ] ) ] <EOL> except ImportError : <EOL> continue <EOL> try : <EOL> klass = getattr ( submodule , class_name ) <EOL> return klass <EOL> except AttributeError : <EOL> continue <EOL> if create_missing : <EOL> return new . classobj ( class_name , ( cls , ) , <EOL> { '<STR_LIT>' : cls . __module__ } ) <EOL> def _custom_method_element_url ( self , method_name , options ) : <EOL> """<STR_LIT>""" <EOL> prefix_options , query_options = self . _split_options ( options ) <EOL> prefix_options . update ( self . _prefix_options ) <EOL> path = ( <EOL> '<STR_LIT>' % <EOL> { '<STR_LIT>' : self . klass . prefix ( prefix_options ) , <EOL> '<STR_LIT>' : self . _plural , <EOL> '<STR_LIT:id>' : self . id , <EOL> '<STR_LIT>' : method_name , <EOL> '<STR_LIT>' : self . _format . extension , <EOL> '<STR_LIT>' : self . _query_string ( query_options ) } ) <EOL> return path <EOL> def _custom_method_new_element_url ( self , method_name , options ) : <EOL> """<STR_LIT>""" <EOL> prefix_options , query_options = self . _split_options ( options ) <EOL> prefix_options . update ( self . _prefix_options ) <EOL> path = ( <EOL> '<STR_LIT>' % <EOL> { '<STR_LIT>' : self . klass . prefix ( prefix_options ) , <EOL> '<STR_LIT>' : self . _plural , <EOL> '<STR_LIT>' : method_name , <EOL> '<STR_LIT>' : self . _format . extension , <EOL> '<STR_LIT>' : self . _query_string ( query_options ) } ) <EOL> return path <EOL> def _instance_get ( self , method_name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = self . _custom_method_element_url ( method_name , kwargs ) <EOL> return self . klass . connection . get ( url , self . klass . headers ) <EOL> def _instance_post ( self , method_name , body = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if self . id : <EOL> url = self . _custom_method_element_url ( method_name , kwargs ) <EOL> else : <EOL> if not body : <EOL> body = self . to_xml ( ) <EOL> url = self . _custom_method_new_element_url ( method_name , kwargs ) <EOL> return self . klass . connection . post ( url , self . klass . headers , body ) <EOL> def _instance_put ( self , method_name , body = '<STR_LIT>' , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = self . _custom_method_element_url ( method_name , kwargs ) <EOL> return self . klass . connection . put ( url , self . klass . headers , body ) <EOL> def _instance_delete ( self , method_name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = self . _custom_method_element_url ( method_name , kwargs ) <EOL> return self . klass . connection . delete ( url , self . klass . headers ) <EOL> def _instance_head ( self , method_name , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> url = self . _custom_method_element_url ( method_name , kwargs ) <EOL> return self . klass . connection . head ( url , self . klass . headers ) <EOL> get = ClassAndInstanceMethod ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> post = ClassAndInstanceMethod ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> put = ClassAndInstanceMethod ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> delete = ClassAndInstanceMethod ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> head = ClassAndInstanceMethod ( '<STR_LIT>' , '<STR_LIT>' ) </s>
