gensaschema._symbols module

Symbol management

Symbol management.

Copyright:

Copyright 2010 - 2023 André Malo or his licensors, as applicable

License:

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

exception gensaschema._symbols.SymbolException[source]

Symbol error

__annotations__ = {}
__module__ = 'gensaschema._symbols'
class gensaschema._symbols.Symbols(symbols=None, imports=None)[source]

Symbol table

_symbols

Symbols

Type:

dict

imports

Import container

Type:

_Imports

types

Type container

Type:

_Types

__annotations__ = {}
__contains__(name)[source]

Check symbol table entry

Parameters:

name (str) – Symbol identifier

Returns:

Does the symbol entry exist?

Return type:

bool

__delitem__(name)[source]

Remove symbol entry if available

Parameters:

name (str) – Symbol identifier

__dict__ = mappingproxy({'__module__': 'gensaschema._symbols', '__doc__': '\n    Symbol table\n\n    Attributes:\n      _symbols (dict):\n        Symbols\n\n      imports (_Imports):\n        Import container\n\n      types (_Types):\n        Type container\n    ', '__init__': <function Symbols.__init__>, '__delitem__': <function Symbols.__delitem__>, '__setitem__': <function Symbols.__setitem__>, '__getitem__': <function Symbols.__getitem__>, '__contains__': <function Symbols.__contains__>, '__iter__': <function Symbols.__iter__>, '__dict__': <attribute '__dict__' of 'Symbols' objects>, '__weakref__': <attribute '__weakref__' of 'Symbols' objects>, '__annotations__': {}})
__getitem__(name)[source]

Get symbol table entry

Parameters:

name (str) – Symbol identifier

Returns:

The symbol

Return type:

str

Raises:

KeyError – Symbol not found

__init__(symbols=None, imports=None)[source]

Initialization

Parameters:
  • symbols (dict) – Initial symbols

  • imports (iterable) – List of initial (id, import statement) tuples. If omitted or None, it’s empty.

__iter__()[source]

Make item iterator (id, value)

Returns:

The iterator

Return type:

iterable

__module__ = 'gensaschema._symbols'
__setitem__(name, symbol)[source]

Set symbol table entry

Parameters:
  • name (str) – Symbol identifier

  • symbol (str) – Symbol

Raises:

SymbolException – Symbol could not be set because of some conflict

__weakref__

list of weak references to the object (if defined)

class gensaschema._symbols._Imports(imports=None)[source]

Import table

_imports

Import list

Type:

list

__contains__(name)[source]

Check if name is in imports

Parameters:

name (str) – Import identifier

Returns:

Does an import with that identifier exist?

Return type:

bool

__dict__ = mappingproxy({'__module__': 'gensaschema._symbols', '__doc__': '\n    Import table\n\n    Attributes:\n      _imports (list):\n        Import list\n    ', '__init__': <function _Imports.__init__>, '__contains__': <function _Imports.__contains__>, '__setitem__': <function _Imports.__setitem__>, '__iter__': <function _Imports.__iter__>, '__dict__': <attribute '__dict__' of '_Imports' objects>, '__weakref__': <attribute '__weakref__' of '_Imports' objects>, '__annotations__': {}})
__init__(imports=None)[source]

Initialization

Parameters:

imports (iterable) – List of initial (id, import statement) tuples. If omitted or None, it’s empty.

__iter__()[source]

Make iterator over the import statements

Returns:

The iterator

Return type:

iterable

__module__ = 'gensaschema._symbols'
__setitem__(name, import_)[source]

Set import

Parameters:
  • name (str) – Symbolic name (to support import uniqueness)

  • import (str) – Import statement

Raises:

SymbolException – Import conflict

__weakref__

list of weak references to the object (if defined)

class gensaschema._symbols._Types(symbols)[source]

Type container

_types

Type map

Type:

dict

_symbols

Symbol table

Type:

gensaschema.Symbols

__dict__ = mappingproxy({'__module__': 'gensaschema._symbols', '__doc__': '\n    Type container\n\n    Attributes:\n      _types (dict):\n        Type map\n\n      _symbols (Symbols):\n        Symbol table\n    ', '__init__': <function _Types.__init__>, '__setitem__': <function _Types.__setitem__>, 'resolve': <function _Types.resolve>, '__dict__': <attribute '__dict__' of '_Types' objects>, '__weakref__': <attribute '__weakref__' of '_Types' objects>, '__annotations__': {}})
__init__(symbols)[source]

Initialization

Parameters:

symbols (gensaschema.Symbols) – Symbol table

__module__ = 'gensaschema._symbols'
__setitem__(class_, symbol)[source]

Set type

Parameters:
  • class (type) – Type to match

  • symbol (str) – Type module symbol

Raises:

SymbolException – Type conflict

__weakref__

list of weak references to the object (if defined)

resolve(type_, dialect)[source]

Resolve type to module symbol

Parameters:
  • type (object) – Type to resolve

  • dialect (str) – Dialect name

Returns:

Resolved symbol

Return type:

str

Raises:

SymbolException – Type could not be resolved

gensaschema._symbols._load_dotted(name)[source]

Load a dotted name

(Stolen from wtf-server)

The dotted name can be anything, which is passively resolvable (i.e. without the invocation of a class to get their attributes or the like).

Parameters:

name (str) – The dotted name to load

Returns:

The loaded object

Return type:

any

Raises:

ImportError – A module in the path could not be loaded