Private Methods & Classes

Knowledge of the following methods & classes (which are not part of the public rosteron module API) is only of benefit if further developing the rosteron module.

Private Session Methods

_browse() Method

Session._browse(url_fragment: Optional[str], purpose: str) → rosteron._Response

Note the current client time, browse to the next page, log the response in case save_logs() is called later, and attempt to build a corresponding _Response object.

Parameters:
  • url_fragment – if specified, the URL (minus the base Session URL) that will be navigated to; if not specified, the current page’s selected form will be submitted.
  • purpose – the type of output expected by this navigation/submission (login, home, roster, or logout). Used in BadResponseError messages and response logging.
Return type:

_Response

Raises:

BadResponseError – if the response doesn’t have the expected RosterOn page traits.

__exit__() Method

Session.__exit__(exc_type, exc_val, exc_tb) → bool

Ensure that the RosterOn user is logged out. Called at the end of any with block that uses this Session object.

The parameters describe the exception raised inside the with block, if any, and are not used.

Returns:False, to indicate that any exception that occurred should propagate to the caller rather than be suppressed.

Private _Response Class

class rosteron._Response(time: datetime.datetime, id: str, content: bs4.Tag)

A semi-evaluated RosterOn response, returned by the Session._browse() method.

Every interesting response from RosterOn Mobile conveniently holds its interesting content in a structure like this:

...
<div data-role="page" id="account-login">
    ...
    <div data-role="content">
        <!-- content of interest within -->
    </div>
</div>
...

The id attribute can be used to very confidently (and cheaply) determine the intent of the page. The content itself should only be further processed if that ID is as expected.

Parameters:
  • time – ideally the time as returned by the server in the response header; failing that, the client time when the request was started.
  • id – the page ID as specified by the id attribute in the <div data-role="page"> element.
  • content – the <div data-role="content"> element as a bs4.Tag object.

Private _LogEntry Class

class rosteron._LogEntry(time: datetime.datetime, response: requests.Response, purpose: str)

A saved, timestamped RosterOn request/response pair for potential later logging to file.

These are constructed in Session._browse(), appended to the Session._log list, and emitted on request by Session.save_logs() as files.

Parameters:
  • time – the client time when the request was started.
  • response – the final returned requests.Response object, which holds its corresponding request in its request attribute and intermediate responses (if any) in its history attribute.
  • purpose – the type of output that was expected by this operation (login, home, roster, or logout). Used in the filename.