lglass.rpsl

class lglass.rpsl.Object(data=None)

This object type is some kind of magic: It acts as a dictionary and a list, therefore an implementation using a trie would be the best idea. Unfortunately, lists are fast enough for our purpose, so we perform linear searches. If you have time, implement is as tree. And don’t implement it as dict.

add(k, v)

Add new entry at the end with given key and value.

extend(ex)

expand has also multiple behaviours depending on given data types. If ex is a list of tuples, then this is simply appended as key-value-pairs to the structure. Otherwise, if ex is a dict, then __setitem__ will be used on the values of struct

get(key)

Get all values for given key.

index(key)

Return index of first entry for key.

inverses(database)

Returns a generator which yields any related object.

items()

Return iterator which yields all items

keys()

Return iterator which yields all keys.

real_primary_key

The real primary key is a database-dependent primary key which was used to lookup the object in the database. This is useful in broken databases, which don’t use the primary_key as file name.

real_spec

The real_spec is the spec which can be used on databases, if they are broken and use a real_primary_key.

real_type

The real type is a database-dependent type which addresses the object type in the database, due to inconsistence.

remove(k)

Remove any occurence of a key.

schema(database)

Return schema object or None.

spec

The spec of an object is a tuple consisting of the type and primary_key.

to_dict()

Return dictionary format.

to_json_form()

Return json format with attached real spec.

values()

Return iterator which yields all values

class lglass.rpsl.RIPESchemaObject(ex=None)

The RIPESchemaObject is similar to the SchemaObject, except that it’s accepting RIPE-style schemas and is able to generate a normal schema object including guessed inverse relations.

constraints()

Return generator which yields all constraints, except that this function parses RIPE style schemas.

to_schema()

Convert object to a traditional SchemaObject.

class lglass.rpsl.SchemaKeyConstraint(key_name, **kwargs)

The SchemaKeyConstraint object represents a simple constraint for attributes of Object instances. One object can describe several constraints for one key.

validate(obj)

Validate constraint against object.

class lglass.rpsl.SchemaObject(ex=None)

A SchemaObject is an extended object type which acts as a schema for other Object instances and defines the attributes of an Object instance. It has additional methods for finding inverse objects, validating other objects and generating constraints.

constraint_for(key)

Return constraint for given key.

constraints()

Return generator which yields all constraints.

find_inverse(db, key, value)

Return generator which yields all inverse objects.

validate(obj)

Check whether the given object is valid.

validate_self()

Check whether the instance of the current SchemaObject is a valid schema.

class lglass.rpsl.SchemaValidator(schema)

The SchemaValidator object binds a schema to an validator and is able to check the validity for all constraints.

is_valid(obj)

Return true if given Object instance is valid for a schema, otherwise False.

validate(obj)

Return True if given Object instance is valid for a schema, otherwise the exception of the first invalid attribute will be raised.

lglass.rpsl.inetnum_cidrs(inetnum)

Return all CIDRs included in given inetnum object.

lglass.rpsl.parse_rpsl(lines, pragmas={})

This is a simple RPSL parser which expects an iterable which yields lines. This parser processes the object format, not the policy format. The object format used by this parser is similar to the format described by the RFC: Each line consists of key and value, which are separated by a colon ‘:’. The ‘:’ can be surrounded by whitespace characters including line breaks, because this parser doesn’t split the input into lines; it’s newline unaware. The format also supports line continuations by beginning a new line of input with a whitespace character. This whitespace character is stripped, but the parser will produce a ‘n’ in the resulting value. Line continuations are only possible for the value part, which means, that the key and ‘:’ must be on the same line of input.

We also support an extended format using pragmas, which can define the processing rules like line-break type, and whitespace preservation. Pragmas are on their own line, which must begin with “%!”, followed by any amount of whitespace, “pragma”, at least one whitespace, followed by the pragma-specific part.

The following pragmas are supported:

%! pragma whitespace-preserve [on|off]
Preserve any whitespace of input in keys and values and don’t strip whitespace.
%! pragma newline-type [cr|lf|crlf|none]
Define type of newline by choosing between cr “Mac OS 9”, lf “Unix”, crlf “Windows” and none.
%! pragma rfc
Reset all pragmas to the RFC-conform values.
%! pragma stop-at-empty-line [on|off]
Enforces the parser to stop at an empty line
%! pragma condense-whitespace [on|off]
Replace any sequence of whitespace characters with simple space (‘ ‘)
%! pragma strict-ripe [on|off]
Do completely RIPE database compilant parsing, e.g. don’t allow any space between key and the colon.
%! pragma hash-comment [on|off]
Recognize hash ‘#’ as beginning of comment
Read the Docs v: latest
Versions
latest
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.