Various utilities that ripozo uses. More or less a junk drawer
Converts a string from CamelCase to underscore.
>>> convert_to_underscore('CamelCase') 'camel_case'
Parameters: toconvert (str) – The string to convert from CamelCase to underscore (i.e. camel_case) Returns: The converted string Return type: str
get_or_pop(dictionary, key, default=None, pop=False)¶
A simple helper for getting or popping a property from a dictionary depending on the
This is a helper method for relationships to easily update whether they keep or remove items from the parent
The value of the requested object or the default if it was not found.
Joins each of the parts with a ‘/’. Additionally, it prevents something like ‘something/’ and ‘/another’ from turning into ‘something//another’ instead it will return ‘something/another’.
>>> join_url_parts('first', 'second', 'last') 'first/second/last'
Parameters: parts (list[unicode|str|int]) – a list of strings to join together with a ‘/’ Returns: The url Return type: unicode
Makes an object json serializable. This is designed to take a list or dictionary, and is fairly limited. This is primarily for the managers when creating objects.
Parameters: obj (object) – Returns: The json safe dictionary. Return type: object|six.text_type|list|dict
picky_processor(processor, include=None, exclude=None)¶
A wrapper for pre and post processors that selectively runs pre and post processors. If the include keyword argument is set, then any method on the Resource that has the same name as the processor will be run. Otherwise it will not be run. On the other hand, if the exclude keyword argument is set then any method on then this preprocessor will not be run for any method on the resource that does have the same name as the strings in the exclude list
def my_preprocessor(resource_class, func_name, request): # Do something class MyResource(CRUD): # Only gets run on create and delete _preprocessors = [picky_processor(my_preprocessor, include=['create', 'delete'])]
The wrapped function that only runs if the include and exclude parameters are fulfilled.
Capitalizes the endpoint and makes it look like a title Just to prettify the output of the actions. It capitalizes the first letter of every word and replaces underscores with spaces. It is opinionated in how it determines words. It simply looks for underscores and splits based on that.
Parameters: endpoint (unicode) – The endpoint name on the resource Returns: The prettified endpoint name Return type: unicode