Checks of user-supplied arguments

Several methods share arguments, so it made sense to have a set of functions designed to validate the in the same place. These functions are all in pymangal.checks, and are used internally only by the different methods.

Documentation

pymangal.checks.check_resource_arg(api, resource)[source]

Checks that the resource argument is correct

Parameters:
  • api – A mangal instance
  • resource – A user-supplied argument (tentatively, a string)
Returns:

Nothing, but fails if resource is not valid

So as to be valid, a resource argument must

  • be of type str
  • be included in api.resources, which is collected from the API root
pymangal.checks.check_upload_res(api, resource, data)[source]

Checks that the data to be uploaded are in the proper format

Parameters:
  • api – A mangal instance
  • resource – A resource argument
  • data – The data to be uploaded. This is supposed to be a dict.
Returns:

data, with corrections applied if need be.

The first checks are basic:

  • the user must provide authentication
  • the data must be given as a dict

The next check concers data validity, i.e. they must conform to the data schema in json, as obtained from the API root when calling __init__.

pymangal.checks.check_filters(filters)[source]

Checks that the filters are valid

Parameters:filters – A string of filters
Returns:Nothing, but can modify filters in place, and raises ``ValueError``s if the filters are badly formatted.

This functions conducts minimal parsing, to make sure that the relationship exists, and that the filter is generally well formed.

The filters string is modified in place if it contains space.