Scope Parsing

Scope parsing is handled by the ScopeParser type.

Additionally, Scope objects define a parse() method which wraps parser usage.

ScopeParser provides classmethods as its primary interface, so there is no need to instantiate the parser in order to use it.

ScopeParser Reference

class globus_sdk.scopes.ScopeParser[source]

Bases: object

The ScopeParser handles the conversion of strings to scopes.

Most interfaces are classmethods, meaning users should prefer usage like ScopeParser.parse("foo")

classmethod merge_scopes(scopes_a, scopes_b)[source]

Given two lists of Scopes, merge them into one list of Scopes by parsing them as one combined scope string.

Parameters:
  • scopes_a (list[Scope]) – list of Scopes to be merged with scopes_b

  • scopes_b (list[Scope]) – list of Scopes to be merged with scopes_a

Return type:

list[Scope]

classmethod parse(scope_string)[source]

Parse an arbitrary scope string to a list of scopes.

Zero or more than one scope may be returned, as in the case of an empty string or space-delimited scopes.

Warning

Parsing passes through an intermediary representation which treats scopes as a graph. This ensures that the behavior of parses matches the treatment of scope strings in Globus Auth authorization flows. However, this also means that the parsing does not allow for strings which represent consent trees with structures in which the same scope appears in multiple parts of the tree.

Parameters:

scope_string (str) – The string to parse

Return type:

list[Scope]

classmethod serialize(scopes, *, reject_empty=True)[source]

Normalize scopes to a space-separated scope string.

The results of this method are suitable for sending to Globus Auth. Scopes are not parsed, merged, or normalized by this method.

Parameters:
  • scopes (str | Scope | Iterable[str | Scope]) – A scope string, scope object, or an iterable of scope strings and scope objects.

  • reject_empty (bool) – When true (the default), raise an error if the scopes serialize to the empty string.

Returns:

A space-separated scope string.

Return type:

str

Example usage:

>>> ScopeParser.serialize([Scope("foo"), "bar", Scope("qux")])
'foo bar qux'
class globus_sdk.scopes.ScopeParseError[source]

The error raised if scope parsing fails.

class globus_sdk.scopes.ScopeCycleError[source]

The error raised if scope parsing discovers a cycle.