def get_resource_method(name, template):
def rsr_meth(self, **kwargs):<EOL><INDENT>http_method = template['<STR_LIT>']<EOL>extra_path = template.get('<STR_LIT>')<EOL>if extra_path:<EOL><INDENT>fills = {'<STR_LIT>': kwargs.pop('<STR_LIT>', '<STR_LIT>')}<EOL>path = self.path + (extra_path % fills)<EOL><DEDENT>else:<EOL><INDENT>path = self.path<EOL><DEDENT>response = self.client.request(http_method, path, **kwargs)<EOL>loc = response.headers.get('<STR_LIT:location>', None)<EOL>if loc:<EOL><INDENT>loc = response.headers.get('<STR_LIT:location>')<EOL>response = self.client.get(loc, **kwargs)<EOL><DEDENT>try:<EOL><INDENT>obj = response.json()<EOL><DEDENT>except:<EOL><INDENT>return<EOL><DEDENT>if COLLECTION_TYPE in response.content_type:<EOL><INDENT>ret = HookList(<EOL>[Resource(r, path, response, self.client) for r in obj],<EOL>response=response<EOL>)<EOL><DEDENT>else:<EOL><INDENT>ret = Resource(obj, path, response, self.client)<EOL><DEDENT>return ret<EOL><DEDENT>rsr_meth.__name__ = name<EOL>return rsr_meth<EOL>
Creates a function that is suitable as a method for ResourceCollection.