flex package¶
Subpackages¶
Submodules¶
flex.cli module¶
flex.context_managers module¶
-
class
flex.context_managers.ErrorCollection(*args, **kwargs)¶ Bases:
flex.exceptions.ErrorDict
flex.core module¶
-
flex.core.load(target)¶ Given one of the supported target formats, load a swagger schema into it’s python representation.
-
flex.core.load_source(source)¶ Common entry point for loading some form of raw swagger schema.
- Supports:
- python object (dictionary-like)
- path to yaml file
- path to json file
- file object (json or yaml).
- json string.
- yaml string.
-
flex.core.parse(raw_schema)¶
-
flex.core.validate(raw_schema, target=None, **kwargs)¶ Given the python representation of a JSONschema as defined in the swagger spec, validate that the schema complies to spec. If target is provided, that target will be validated against the provided schema.
-
flex.core.validate_api_call(schema, raw_request, raw_response)¶ Validate the request/response cycle of an api call against a swagger schema. Request/Response objects from the requests and urllib library are supported.
-
flex.core.validate_api_request(schema, raw_request)¶
-
flex.core.validate_api_response(schema, raw_response, request_method=u'get')¶ Validate the response of an api call against a swagger schema.
flex.datastructures module¶
flex.decorators module¶
-
flex.decorators.maybe_iterable(func)¶
-
flex.decorators.partial_safe_wraps(wrapped_func, *args, **kwargs)¶ A version of functools.wraps that is safe to wrap a partial in.
-
flex.decorators.pull_keys_from_obj(*keys)¶
-
flex.decorators.rewrite_reserved_words(func)¶ Given a function whos kwargs need to contain a reserved word such as in, allow calling that function with the keyword as in_, such that function kwargs are rewritten to use the reserved word.
-
flex.decorators.skip_if_any_kwargs_empty(*kwargs)¶
-
flex.decorators.skip_if_empty(func)¶ Decorator for validation functions which makes them pass if the value passed in is the EMPTY sentinal value.
-
flex.decorators.skip_if_not_of_type(*types)¶
-
flex.decorators.suffix_reserved_words(func)¶ Given a function that is called with a reseved word, rewrite the keyword with an underscore suffix.
flex.error_messages module¶
flex.exceptions module¶
-
class
flex.exceptions.ErrorDict(value=None)¶ Bases:
flex.exceptions.ErrorCollectionMixin,collections.defaultdict-
add_error(key, error)¶
-
-
class
flex.exceptions.ErrorList(value=None)¶ Bases:
flex.exceptions.ErrorCollectionMixin,list-
add_error(error)¶ In the case where a list/tuple is passed in this just extends the list rather than having nested lists.
Otherwise, the value is appended.
-
-
exception
flex.exceptions.MultipleParametersFound¶ Bases:
exceptions.ValueError
-
exception
flex.exceptions.MultiplePathsFound¶ Bases:
exceptions.ValueError
-
exception
flex.exceptions.NoParameterFound¶ Bases:
exceptions.ValueError
flex.formats module¶
-
flex.formats.date_time_format_validator(value, *args, **kwargs)¶
-
flex.formats.email_validator(value, *args, **kwargs)¶
-
flex.formats.int32_validator(value, *args, **kwargs)¶
-
flex.formats.int64_validator(value, *args, **kwargs)¶
-
flex.formats.number_of_bits(n)¶
-
flex.formats.register= <bound method FormatRegistry.register of <flex.formats.FormatRegistry object>>¶ (‘number’, ‘float’), (‘number’, ‘double’), (‘string’, ‘byte’), (‘string’, ‘date’),
-
flex.formats.uri_validator(value, *args, **kwargs)¶
-
flex.formats.uuid_format_validator(value, *args, **kwargs)¶
flex.functional module¶
-
flex.functional.apply_functions_to_key(key, *funcs)¶ Shortcut for the common pattern with chain_reduce_partial for applying a validator to some specified key in a mapping.
-
flex.functional.attrgetter(attr)¶ Upstream bug in python: https://bugs.python.org/issue26822
-
flex.functional.chain_reduce(value, functions, **kwargs)¶
-
flex.functional.chain_reduce_partial(*functions)¶ Given an iterable of functions, returns a callable that takes a value and passes it through all of the given functions in order.
- def a(x):
- ...
- def b(x):
- ...
c = chain_reduce_partial(a, b)
This is equivilent to
- def c(x):
- return b(a(x))
-
flex.functional.methodcaller(name, *args)¶ Upstream bug in python: https://bugs.python.org/issue26822
flex.http module¶
-
class
flex.http.Request(url, method, content_type=None, body=None, request=None, headers=None)¶ Bases:
flex.http.URLMixinGeneric request object. All supported requests are normalized to an instance of Request.
-
data¶ TODO: What is the right way to do this?
-
method= None¶
-
-
class
flex.http.Response(request, content, url, status_code, content_type, headers=None, response=None)¶ Bases:
flex.http.URLMixinGeneric response object. All supported responses are normalized to an instance of this Response.
-
data¶
-
path¶
-
status_code= None¶
-
-
flex.http.normalize_request(request)¶ Given a request, normalize it to the internal Request class.
-
flex.http.normalize_response(response, request=None)¶ Given a response, normalize it to the internal Response class. This also involves normalizing the associated request object.
flex.parameters module¶
-
flex.parameters.dereference_parameter_list(parameters, context)¶
-
flex.parameters.filter_parameters(*args, **kwargs)¶
-
flex.parameters.find_parameter(*args, **kwargs)¶ Given a list of parameters, find the one with the given name.
-
flex.parameters.is_match(*args, **kwargs)¶
-
flex.parameters.merge_parameter_lists(*parameter_definitions)¶ Merge multiple lists of parameters into a single list. If there are any duplicate definitions, the last write wins.
flex.paths module¶
-
flex.paths.construct_parameter_pattern(parameter)¶ Given a parameter definition returns a regex pattern that will match that part of the path.
-
flex.paths.escape_regex_special_chars(api_path)¶ Turns the non prametrized path components into strings subtable for using as a regex pattern. This primarily involves escaping special characters so that the actual character is matched in the regex.
-
flex.paths.extract_operation_parameters(path_definition)¶
-
flex.paths.extract_path_parameters(path_definition)¶
-
flex.paths.get_parameter_names_from_path(api_path)¶
-
flex.paths.match_path_to_api_path(path_definitions, target_path, base_path='', context=None)¶ Match a request or response path to one of the api paths.
Anything other than exactly one match is an error condition.
-
flex.paths.path_to_pattern(api_path, parameters)¶ Given an api path, possibly with parameter notation, return a pattern suitable for turing into a regular expression which will match request paths that conform to the parameter definitions and the api path.
-
flex.paths.path_to_regex(api_path, path_parameters, operation_parameters=None, context=None)¶
-
flex.paths.process_path_part(part, parameters)¶ - Given a part of a path either:
- If it is a parameter:
- parse it to a regex group
- Otherwise:
- escape any special regex characters
flex.utils module¶
-
flex.utils.cast_value_to_type(value, type_)¶
-
flex.utils.chain_reduce_partial(*args, **kwargs)¶
-
flex.utils.deep_equal(a, b)¶ - Because of things in python like:
>>> 1 == 1.0 True >>> 1 == True True >>> b'test' == 'test' # python3 False
-
flex.utils.dereference_reference(reference, context)¶
-
flex.utils.format_errors(errors, indent=0, prefix='', suffix='')¶ string: “example”
“example”- dict:
- “example”:
-
flex.utils.get_type_for_value(value)¶
-
flex.utils.indent_message(message, indent, prefix='', suffix='')¶
-
flex.utils.is_any_string_type(value)¶
-
flex.utils.is_non_string_iterable(value)¶
-
flex.utils.is_single_item_iterable(value)¶
-
flex.utils.is_value_of_any_type(value, types)¶
-
flex.utils.is_value_of_type(value, type_)¶
-
flex.utils.pluralize(value)¶
-
flex.utils.prettify_errors(errors)¶