RBTLIB: A Client-Side Library for Review Board

Resource Module

The resource module provides the basis for accessing all Review Board resources.

class rbtlib.resource.Resource(session, name)[source]

Generalized resource.

Provide uniform getter and setter methods over HTTP to Review Board. To achieve this, the methods are decorated to handle the response at different levels:

  • sending HTTP commands (e.g, GET and POST)
  • handling the HTTP response (e.g., content type and status code)
  • payload conversion to a whole-part hierarchy

The whole-part hierarchy is contained a nested named tuple containing the response returned by Review Board.

The composite contains a copy of the JSON response from Review Board. This permits clients to access the response using a named tuple or dictionary.

session

HTTP session.

name

Resource name.

component(name, response, extra_args={})[source]

Build the whole-part hierarchy making up the composite object.

Recursively create a whole-part hierarchy of the response. Extra arguments can be embedded within the whole-part hierarchy at this level only.

Parameters:
  • name – the component name.
  • response – the response defining the component.
  • extra_args – arguments to add to the component.
Returns:

A named tuple comprising the whole-part hierarchy contained with the response along with any extra arguments.

composite(fetch)[source]

Build the whole-part hierarchy from the HTTP response.

Parameters:fetch – a function object defining an HTTP command.
Returns:A function object generating a composite from the obtained data.
contruct_dict_from_http_response(fetch)[source]

Decorator returning a dictionary containing the HTTP response.

Parameters:fetch – a function object defining an HTTP command.
Returns:A dictionary containing the payload returned by the HTTP command.
delete(url, query_dict=None)[source]

Execute HTTP DELETE command using session parameters.

Parameters:
  • href – A hypertext reference used by the HTTP command.
  • query_dict – A dictionary containing HTTP command parameters.
Returns:

The HTTP response to the HTTP command.

get(url, query_dict=None)[source]

Execute HTTP GET command using session parameters.

Parameters:
  • href – A hypertext reference used by the HTTP command.
  • query_dict – A dictionary containing HTTP command parameters.
Returns:

The HTTP response to the HTTP command.

list_component(name, response)[source]

Construct a list component from the response.

Parameters:
  • name – the key string identifying the list in the response.
  • response – a list.
Returns:

A dictionary containing list components.

post(url, query_dict=None)[source]

Execute HTTP POST command using session parameters.

Parameters:
  • href – A hypertext reference used by the HTTP command.
  • query_dict – A dictionary containing HTTP command parameters.
Returns:

The HTTP response to the HTTP command.

put(url, query_dict=None)[source]

Execute HTTP PUT command using session parameters.

Parameters:
  • href – A hypertext reference used by the HTTP command.
  • query_dict – A dictionary containing HTTP command parameters.
Returns:

The HTTP response to the HTTP command.

replace(s)[source]

Replace forbidden characters in named tuple names and field names.

Parameters:s – a string.
Returns:A string with the required substitutions.
validate_http_content_type(fetch)[source]

Decorator validating the response’s HTTP content type.

Parameters:fetch – a function object defining an HTTP command.
Returns:A function object for checking the HTTP Content-Type.
class rbtlib.resource.ResourceFactory(session, name, url, method)[source]

Resource specialization by URL and HTTP command.

Permit resource class instances to behave as functions. This separates resource construction from use. This relegates construction to the library and leaves client programs to focus on consuming resource outputs.

session

HTTP session.

name

Resource name.

url

Resource URL.

method

the HTTP method requred by the resource.

__call__(query_dict={})[source]

Use the getter to populate the resource.

The parent resource includes the entire Review Board response and an instance of the Resource class for any linked resource.

The top-level component is an amalgamation of the composite defined by the Review Board response and ResourceFactory objects for each child resource in that response.

The Review Board response is not altered.

Parameters:query_dict – the payload provided to the HTTP command.
Returns:A named tuple comprising the whole-part hierarchy containing the HTTP command response and ResourceFactory objects for each child resource.

Root List Resource

class rbtlib.root.Root(session, url)[source]

The Root List Resource for the Review Board instance.

A helper class, requiring the fully-qualified domain name and URI scheme used by the Review Board instance to query. The caller needn’t specify the entire URL to the Root List Resource.

Other Web API resources should rely upon the parent class.

session

the HTTP session.

url

the URL defining the resource location.

name

the resource name.

User Management

rbtlib.user.login(session, url, username, password)[source]

User login.

Parameters:
  • session – the HTTP session.
  • url – the Review Board URL.
  • username – account user name.
  • password – account password.
Returns:

The HTTP status code, not an indicator of a successful login.