core.util.webpub_manifest_parser.core package

Submodules

core.util.webpub_manifest_parser.core.ast module

class core.util.webpub_manifest_parser.core.ast.ArrayOfCollectionsProperty(key, required, role, collection_type=<class 'core.util.webpub_manifest_parser.core.ast.Collection'>)[source]

Bases: BaseArrayProperty

Property allowing to contain a compact sub-collection.

property role

Return the sub-collection’s role.

Returns:

Sub-collection’s role

Return type:

CollectionRole

class core.util.webpub_manifest_parser.core.ast.ArrayOfContributorsProperty(key, required)[source]

Bases: BaseArrayProperty

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
PARSER = <core.util.webpub_manifest_parser.core.parsers.AnyOfParser object>
class core.util.webpub_manifest_parser.core.ast.ArrayOfLinksProperty(key, required)[source]

Bases: BaseArrayProperty

Property allowing to contain only unique links.

class core.util.webpub_manifest_parser.core.ast.ArrayOfSubjectsProperty(key, required)[source]

Bases: BaseArrayProperty

Property containing information about subjects.

For example:

- "Juvenile Fiction"
- {
    name: "Juvenile Fiction"
  }
- [
    "Juvenile Fiction",
    "Biography"
  ]
- [
    {
        name: "Juvenile Fiction"
    },
    {
        name: "Biography"
    }
  ]
PARSER = <core.util.webpub_manifest_parser.core.parsers.AnyOfParser object>
class core.util.webpub_manifest_parser.core.ast.Collection(role=None, links=None, metadata=None)[source]

Bases: CompactCollection

A collection is defined as a grouping of metadata, links and sub-collections.

property compact

Return a boolean value indicating if this collection is compact.

Returns:

Boolean value indicating if this collection is compact

Return type:

bool

property full

Return a boolean value indicating if this collection is full.

Returns:

Boolean value indicating if this collection is full

Return type:

bool

metadata

Property allowing only specific values of a specific Type.

property sub_collections

Return a list of sub-collections.

Returns:

List of sub-collections.

Return type:

CollectionList

class core.util.webpub_manifest_parser.core.ast.CollectionList(items=None)[source]

Bases: Node, list

List of sub-collections.

get_by_role(role)[source]

Return collections with the specific role.

Parameters:

role (str) – Collection’s role

Returns:

Collections with the specific role

Return type:

List[Collection]

class core.util.webpub_manifest_parser.core.ast.CompactCollection(role=None, links=None)[source]

Bases: Node

A compact collection is defined as a grouping of links.

Property allowing to contain only unique links.

property role

Return the collection’s role.

Returns:

Collection’s role.

Return type:

Optional[CollectionRole]

class core.util.webpub_manifest_parser.core.ast.CompactCollectionProperty(key, required, role, collection_class=<class 'core.util.webpub_manifest_parser.core.ast.CompactCollection'>)[source]

Bases: Property

Property allowing to contain a compact sub-collection.

property role

Return the sub-collection’s role.

Returns:

Sub-collection’s role

Return type:

CollectionRole

class core.util.webpub_manifest_parser.core.ast.Contributor(name=None, identifier=None, sort_as=None, roles=None, position=None, links=None)[source]

Bases: Node

Contributor object.

identifier

Property allowing only URI values.

Property allowing to contain only unique links.

name

Property allowing either only string/localizable string values.

For example:

- "plain string"
- {
    "eng": "Hello",
    "esp": "Hola"
}
position

Property allowing only float values.

roles

Property allowing either a string or array of strings as its values.

sort_as

Property allowing only string values.

class core.util.webpub_manifest_parser.core.ast.Extendable[source]

Bases: object

Abstract class adding ability to extend classes.

For example, RWPM link properties can be extended by EPUB link properties and OPDS 2.0 link properties.

extensions = None
classmethod get_extension()[source]

Return a new class having all extensions as mixins.

Returns:

New class containing extensions as mixins.

Return type:

Type

Bases: Node

Link to another resource.

alternates

Property containing an array of items.

bitrate

Property allowing only float values.

children

Property containing an array of items.

duration

Property allowing only float values.

height

Property allowing only integer values.

href

Property allowing only URI templates.

languages

Property allowing localizable strings.

For example:

- "en"
- [
    "eng",
    "fre"
  ]
properties

Property allowing only specific values of a specific Type.

rels

Property allowing either a string or array of strings as its values.

templated

Property allowing only boolean values.

title

Property allowing only string values.

type

Property allowing only string values.

width

Property allowing only integer values.

Bases: Node, list

List of links.

get_by_href(href)[source]

Return links with the specific URL.

Parameters:

href (str) – Link’s URL

Returns:

Links with the specified relation

Return type:

List[Link]

get_by_rel(rel)[source]

Return links with the specific relation.

Parameters:

rel (str) – Link’s relation

Returns:

Links with the specified relation

Return type:

List[Link]

class core.util.webpub_manifest_parser.core.ast.LinkProperties[source]

Bases: Node

Link properties.

clipped

Property allowing only boolean values.

extensions = (<class 'core.util.webpub_manifest_parser.opds2.ast.OPDS2LinkProperties'>,)
fit

Property allowing only specific string values.

orientation

Property allowing only specific string values.

page

Property allowing only specific string values.

spread

Property allowing only specific string values.

class core.util.webpub_manifest_parser.core.ast.Manifestlike(role=None, links=None, metadata=None)[source]

Bases: Collection

Base class for Manifest (Readium Web Publication Manifest) and Feed (OPDS 2).

An OPDS 2 feed is defined as a RWPM with enumerated exceptions.

This class implements the behavior common to both specs. The alternative is to have the Feed class subclass Manifest and then implement a lot of exceptions.

class core.util.webpub_manifest_parser.core.ast.Metadata(title=None, identifier=None, subtitle=None, modified=None, published=None, language=None, sort_as=None, author=None, translator=None, editor=None, artist=None, illustrator=None, letterer=None, penciler=None, colorist=None, inker=None, narrator=None, contributor=None, publisher=None, imprint=None, subject=None, description=None, duration=None, number_of_pages=None, belongs_to=None)[source]

Bases: Node

Dictionary containing manifest’s metadata.

artists

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
authors

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
belongs_to

Property allowing only specific values of a specific Type.

colorists

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
contributors

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
description

Property allowing only string values.

duration

Property allowing only float values.

editors

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
identifier

Property allowing only URI values.

illustrators

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
imprints

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
inkers

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
languages

Property allowing localizable strings.

For example:

- "en"
- [
    "eng",
    "fre"
  ]
letterers

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
modified

Property allowing only date & time values.

narrators

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
number_of_pages

Property allowing only float values.

pencilers

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
published

Property allowing date or date & time values.

publishers

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
reading_progression

Property allowing only specific string values.

sort_as

Property allowing only string values.

subjects

Property containing information about subjects.

For example:

- "Juvenile Fiction"
- {
    name: "Juvenile Fiction"
  }
- [
    "Juvenile Fiction",
    "Biography"
  ]
- [
    {
        name: "Juvenile Fiction"
    },
    {
        name: "Biography"
    }
  ]
subtitle

Property allowing either only string/localizable string values.

For example:

- "plain string"
- {
    "eng": "Hello",
    "esp": "Hola"
}
title

Property allowing either only string/localizable string values.

For example:

- "plain string"
- {
    "eng": "Hello",
    "esp": "Hola"
}
translators

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
type

Property allowing only URI values.

class core.util.webpub_manifest_parser.core.ast.Node[source]

Bases: PropertiesGrouping, Visitable, Extendable

Base class for all AST nodes.

accept(visitor)[source]

Accept the specified visitor.

Parameters:

visitor (Visitor) – Visitor object

class core.util.webpub_manifest_parser.core.ast.Owner[source]

Bases: Node, PropertiesGrouping

Object containing information about the collection’s owners.

collection

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
series

Property containing information about contributors.

For example:

- "Herman Melville"
- {
    name: "Herman Melville"
  }
- [
    "Herman Melville",
    "Mark Twain"
  ]
- [
    {
        name: "Herman Melville"
    },
    {
        name: "Mark Twain"
    }
  ]
class core.util.webpub_manifest_parser.core.ast.PresentationMetadata(title=None, identifier=None, subtitle=None, modified=None, published=None, language=None, sort_as=None, author=None, translator=None, editor=None, artist=None, illustrator=None, letterer=None, penciler=None, colorist=None, inker=None, narrator=None, contributor=None, publisher=None, imprint=None, subject=None, description=None, duration=None, number_of_pages=None, belongs_to=None)[source]

Bases: Metadata

RWPM extension containing presentation metadata.

clipped

Property allowing only boolean values.

continuous

Property allowing only boolean values.

fit

Property allowing only specific string values.

orientation

Property allowing only specific string values.

overflow

Property allowing only specific string values.

spread

Property allowing only specific string values.

class core.util.webpub_manifest_parser.core.ast.Subject[source]

Bases: Node, PropertiesGrouping

Subject object.

code

Property allowing only string values.

Property allowing to contain only unique links.

name

Property allowing either only string/localizable string values.

For example:

- "plain string"
- {
    "eng": "Hello",
    "esp": "Hola"
}
scheme

Property allowing only URI values.

sort_as

Property allowing only string values.

class core.util.webpub_manifest_parser.core.ast.Visitable[source]

Bases: object

Interface for objects walkable by AST visitors.

abstract accept(visitor)[source]

Accept the specified visitor.

Parameters:

visitor (Visitor) – Visitor object

class core.util.webpub_manifest_parser.core.ast.Visitor[source]

Bases: object

Interface for visitors walking through abstract syntax trees (AST).

abstract visit(node)[source]

Process the specified node.

Parameters:

node (Node) – AST node

core.util.webpub_manifest_parser.core.errors module

exception core.util.webpub_manifest_parser.core.errors.BaseSemanticError(message=None, inner_exception=None)[source]

Bases: BaseError

Exception raised in the case of any semantic errors.

exception core.util.webpub_manifest_parser.core.errors.BaseSyntaxError(message=None, inner_exception=None)[source]

Bases: BaseError

Exception raised in the case of syntax errors.

core.util.webpub_manifest_parser.core.parsers module

class core.util.webpub_manifest_parser.core.parsers.AnyOfParser(inner_parsers)[source]

Bases: ValueParser

Parser making sure that at least one of the inner parsers succeed.

property inner_parsers

Return the inner parsers.

Returns:

Inner parsers

Return type:

List[ValueParser]

parse(value)[source]

Make sure that at least one of the inner parsers succeed, otherwise raise the first validation error.

Parameters:

value (Any) – Value

Returns:

First valid value

Return type:

Any

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.ArrayParser(item_parser, unique_items=False)[source]

Bases: ValueParser

Array parser.

property item_parser

Return the parser used for parsing array items.

Returns:

Parser used for parsing array items

Return type:

ValueParser

parse(value)[source]

Parse the value into a list of parsed values.

Parameters:

value (Any) – Value

Returns:

List consisting of parsed items

Return type:

List

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.BooleanParser[source]

Bases: ValueParser

Boolean parser.

parse(value)[source]

Parse a boolean value.

Parameters:

value (Any) – Value

Returns:

Parsed boolean value

Return type:

int

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.DateParser[source]

Bases: FormatChecker

Date parser.

class core.util.webpub_manifest_parser.core.parsers.DateTimeParser[source]

Bases: FormatChecker

Date & time parser.

class core.util.webpub_manifest_parser.core.parsers.DocumentParser(syntax_analyzer, semantic_analyzer)[source]

Bases: object

Base class for RWPM-compatible parsers.

static get_manifest_json(input_stream)[source]

Parse the input stream into a JSON document containing an RWPM-compatible manifest.

Parameters:

input_stream (Union[six.StringIO, six.BinaryIO]) – Input stream containing JSON document with an RWPM-compatible manifest

Returns:

JSON document containing an RWPM-compatible manifest

Return type:

Dict

parse_file(input_file_path, encoding='utf-8')[source]

Parse the input file and return a validated AST object.

Parameters:
  • input_file_path (str) – Full path to the file containing RWPM-compatible document

  • encoding (str) – Input file’s encoding

Returns:

Validated manifest-like object

Return type:

python_rwpm_parser.ast.Manifestlike

parse_json(manifest_json)[source]

Parse the JSON document with an RWPM-compatible manifest and return a validated AST object.

Parameters:

manifest_json (Dict) – JSON document with an RWPM-compatible manifest

Returns:

Validated manifest-like object

Return type:

python_rwpm_parser.ast.Manifestlike

parse_stream(input_stream)[source]

Parse the input file and return a validated AST object.

Parameters:

input_stream (six.StringIO) – Full path to the file containing RWPM-compatible document

Returns:

Validated manifest-like object

Return type:

python_rwpm_parser.ast.Manifestlike

parse_url(url, encoding='utf-8')[source]

Fetch the content pointed by the URL, parse it and return a validated AST object.

Parameters:
  • url (str) – URL pointing to the RWPM-compatible document

  • encoding (str) – Input file’s encoding

Returns:

Validated manifest-like object

Return type:

python_rwpm_parser.ast.Manifestlike

class core.util.webpub_manifest_parser.core.parsers.DocumentParserFactory[source]

Bases: object

Base class for factories creating parsers for particular RWPM-compatible standards (for example, OPDS 2.0).

abstract create()[source]

Create a new Parser instance.

Returns:

Parser instance

Return type:

DocumentParser

class core.util.webpub_manifest_parser.core.parsers.EnumParser(items)[source]

Bases: StringParser

Enum parser.

parse(value)[source]

Make sure that the value is a part of the enumeration and return it back.

Parameters:

value (Any) – Value

Returns:

Parsed string value

Return type:

int

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.FormatChecker(json_schema_format)[source]

Bases: StringParser

Base class for all parsers using jsonschema FormatChecker.

parse(value)[source]

Parse the value according to the specified format.

Parameters:

value (Any) – Value

Returns:

Parsed value

Return type:

Any

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.IntegerParser(minimum=None, exclusive_minimum=None, maximum=None, exclusive_maximum=None)[source]

Bases: NumericParser

Integer parser.

class core.util.webpub_manifest_parser.core.parsers.LocalizableStringParser[source]

Bases: ObjectParser

Parser for localizable strings represented as a dictionary with keys equal to language codes.

LANGUAGE_PATTERN = '^((?P<grandfathered>(en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((?P<language>([A-Za-z]{2,3}(-(?P<extlang>[A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-(?P<script>[A-Za-z]{4}))?(-(?P<region>[A-Za-z]{2}|[0-9]{3}))?(-(?P<variant>[A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-(?P<extension>[0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(?P<privateUse>x(-[A-Za-z0-9]{1,8})+))?)|(?P<privateUse2>x(-[A-Za-z0-9]{1,8})+))$'
class core.util.webpub_manifest_parser.core.parsers.NumberParser(minimum=None, exclusive_minimum=None, maximum=None, exclusive_maximum=None)[source]

Bases: NumericParser

Number parser.

class core.util.webpub_manifest_parser.core.parsers.NumericParser(minimum=None, exclusive_minimum=None, maximum=None, exclusive_maximum=None)[source]

Bases: ValueParser

Numeric parser.

parse(value)[source]

Parse a numeric value.

Parameters:

value (Any) – Value

Returns:

Parsed numeric value

Return type:

Numeric

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.ObjectParser(properties_parser, properties_pattern=None)[source]

Bases: ValueParser

Object parser.

parse(value)[source]

Parse a JSON object into a Python dictionary.

Parameters:

value (Any) – Value

Returns:

Python dictionary containing parsed items

Return type:

Dict

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.StringParser[source]

Bases: ValueParser

String parser.

parse(value)[source]

Parse a string value.

Parameters:

value (Any) – Value

Returns:

Parsed string value

Return type:

str

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.StringPatternParser(pattern)[source]

Bases: StringParser

String parser using a regular expression pattern.

parse(value)[source]

Parse a string value using the specified regular expression.

Parameters:

value (Any) – Value

Returns:

Parsed string value

Return type:

int

Raise:

ValidationError

class core.util.webpub_manifest_parser.core.parsers.TypeParser(_type)[source]

Bases: ValueParser

Parser used for checking type information and as an indication of nested types.

parse(value)[source]

Check that the value has the correct type.

Parameters:

value (Any) – Value

Returns:

Value

Return type:

Any

Raise:

ValidationError

property type

Return the type.

“return: Type :rtype: Type

class core.util.webpub_manifest_parser.core.parsers.URIParser[source]

Bases: FormatChecker

URI parser.

class core.util.webpub_manifest_parser.core.parsers.URIReferenceParser[source]

Bases: FormatChecker

URI-reference parser.

class core.util.webpub_manifest_parser.core.parsers.URITemplateParser[source]

Bases: StringParser

URI template parser.

parse(value)[source]

Parse the URI into a Python dictionary containing URI’s subcomponents.

Parameters:

value (Any) – Value

Returns:

URI template

Return type:

URITemplate

class core.util.webpub_manifest_parser.core.parsers.ValueParser[source]

Bases: object

Base parser class.

abstract parse(value)[source]

Parse the value, raise ParsingError if the value is not correct, otherwise return the processed value.

Parameters:

value (Any) – Value to validate

Returns:

Processed value (for example, datetime object in the case of a value containing a date&time string)

Return type:

Any

Raise:

ValidationError

exception core.util.webpub_manifest_parser.core.parsers.ValueParsingError(message=None, inner_exception=None)[source]

Bases: BaseSyntaxError

Base class for all errors raised by value parsers.

core.util.webpub_manifest_parser.core.parsers.find_parser(parent_parser, child_parser_type)[source]

Find a child parser with a specified type in the parent parser.

This function is used for finding nested types.

Parameters:
  • parent_parser (ValueParser) – Parent parser

  • child_parser_type (Type) – Child parser’s type

Returns:

List of 2-tuples (parent parser, child parser)

Return type:

List[Optional[ValueParser], ValueParser]

core.util.webpub_manifest_parser.core.properties module

class core.util.webpub_manifest_parser.core.properties.ArrayOfStringsProperty(key, required, unique_items=False, list_type=<class 'list'>, default_value=None)[source]

Bases: BaseArrayProperty

Property allowing either a string or array of strings as its values.

class core.util.webpub_manifest_parser.core.properties.ArrayProperty(key, required, item_parser, unique_items=False, list_type=<class 'list'>, default_value=None)[source]

Bases: BaseArrayProperty

Property containing an array of items.

class core.util.webpub_manifest_parser.core.properties.BaseArrayProperty(key, required, parser, list_type=<class 'list'>, default_value=None)[source]

Bases: Property

Property containing a list of items.

property list_type

Return the class of a collection used to hold the items.

Returns:

Class of a collection used to hold the items

Return type:

Type

class core.util.webpub_manifest_parser.core.properties.BooleanProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only boolean values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.BooleanParser object>
class core.util.webpub_manifest_parser.core.properties.DateOrTimeProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing date or date & time values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.AnyOfParser object>
class core.util.webpub_manifest_parser.core.properties.DateProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only date values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.DateParser object>
class core.util.webpub_manifest_parser.core.properties.DateTimeProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only date & time values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.DateTimeParser object>
class core.util.webpub_manifest_parser.core.properties.EnumProperty(key, required, items, default_value=None)[source]

Bases: Property

Property allowing only specific string values.

class core.util.webpub_manifest_parser.core.properties.HasProperties[source]

Bases: object

Interface representing class containing ObjectProperty meta-properties.

abstract get_setting_value(setting_name, default_value=None)[source]

Return the setting’s value.

Parameters:
  • setting_name (string) – Name of the setting

  • default_value (Any) – Default value

Returns:

Setting’s value

Return type:

Any

abstract set_setting_value(setting_name, setting_value)[source]

Set the setting’s value.

Parameters:
  • setting_name (string) – Name of the setting

  • setting_value (Any) – New value of the setting

class core.util.webpub_manifest_parser.core.properties.IntegerProperty(key, required, minimum=None, exclusive_minimum=None, maximum=None, exclusive_maximum=None, default_value=None)[source]

Bases: Property

Property allowing only integer values.

class core.util.webpub_manifest_parser.core.properties.ListOfLanguagesProperty(key, required)[source]

Bases: BaseArrayProperty

Property allowing localizable strings.

For example:

- "en"
- [
    "eng",
    "fre"
  ]
class core.util.webpub_manifest_parser.core.properties.LocalizableStringProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing either only string/localizable string values.

For example:

- "plain string"
- {
    "eng": "Hello",
    "esp": "Hola"
}
PARSER = <core.util.webpub_manifest_parser.core.parsers.AnyOfParser object>
class core.util.webpub_manifest_parser.core.properties.NumberProperty(key, required, minimum=None, exclusive_minimum=None, maximum=None, exclusive_maximum=None, default_value=None)[source]

Bases: Property

Property allowing only float values.

class core.util.webpub_manifest_parser.core.properties.ParsableProperty(key, required, default_value=None)[source]

Bases: Property

Base class for all property classes having predefined parsers.

PARSER = <object object>
class core.util.webpub_manifest_parser.core.properties.PropertiesGrouping[source]

Bases: HasProperties

Group of properties.

static get_class_properties(klass)[source]

Return a list of 2-tuples containing information ConfigurationMetadata properties in the specified class.

Parameters:

klass (type) – Class

Returns:

List of 2-tuples containing information ConfigurationMetadata properties in the specified class

Return type:

List[Tuple[string, ConfigurationMetadata]]

static get_required_class_properties(klass)[source]

Return a list of 2-tuples containing information about required ConfigurationMetadata properties.

Parameters:

klass (type) – Class

Returns:

List of 2-tuples containing information ConfigurationMetadata properties in the specified class

Return type:

List[Tuple[string, ConfigurationMetadata]]

get_setting_value(setting_name, default_value=None)[source]

Return the setting’s value.

Parameters:
  • setting_name (str) – Setting’s name

  • default_value (Any) – Setting’s default value

set_setting_value(setting_name, setting_value)[source]

Set the setting’s value.

Parameters:
  • setting_name (str) – Setting’s name

  • setting_value (Any) – New setting’s value

class core.util.webpub_manifest_parser.core.properties.Property(key, required, parser, default_value=None)[source]

Bases: object

Class representing object property, storing property’s metadata and its value.

property default_value

Return the property’s default value.

Returns:

Property’s default value.

Return type:

bool

property key

Return the property’s key.

Returns:

Property’s key

Return type:

str

property parser

Return the parser used to validate and parse this property’s value.

Returns:

Parser used to validate and parse this property’s value.

Return type:

parsers.Parser

property required

Return a boolean value indicating whether this property is required or not.

Returns:

Boolean value indicating whether this property is required or not.

Return type:

bool

class core.util.webpub_manifest_parser.core.properties.StringProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only string values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.StringParser object>
class core.util.webpub_manifest_parser.core.properties.TypeProperty(key, required, nested_type, default_value=None)[source]

Bases: Property

Property allowing only specific values of a specific Type.

class core.util.webpub_manifest_parser.core.properties.URIProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only URI values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.URIParser object>
class core.util.webpub_manifest_parser.core.properties.URIReferenceProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only URI-reference values.

PARSER = <core.util.webpub_manifest_parser.core.parsers.URIReferenceParser object>
class core.util.webpub_manifest_parser.core.properties.URITemplateProperty(key, required, default_value=None)[source]

Bases: ParsableProperty

Property allowing only URI templates.

PARSER = <core.util.webpub_manifest_parser.core.parsers.URITemplateParser object>

core.util.webpub_manifest_parser.core.registry module

class core.util.webpub_manifest_parser.core.registry.CollectionRole(key, compact, required, multi=False)[source]

Bases: RegistryItem

Registry item representing a collection role.

property compact

Return the boolean value indicating whether the collection shall be compact.

Returns:

Boolean value indicating whether the collection shall be compact

Return type:

bool

property multi

Return the boolean value indicating whether there can be multiple collections with this role.

Returns:

Boolean value indicating whether there can be multiple collections with this role

Return type:

bool

property required

Return the boolean value indicating whether the collection is required.

Returns:

Boolean value indicating whether the collection is required

Return type:

bool

class core.util.webpub_manifest_parser.core.registry.LinkRelation(key)[source]

Bases: RegistryItem

Registry item representing a link relation.

class core.util.webpub_manifest_parser.core.registry.MediaType(key)[source]

Bases: RegistryItem

Registry item representing a specific media type.

class core.util.webpub_manifest_parser.core.registry.Registry(items=None)[source]

Bases: MutableMapping

Collection of registry items with a particular type (collection roles, media types, etc.).

class core.util.webpub_manifest_parser.core.registry.RegistryItem(key)[source]

Bases: object

Single metadata registry item (collection role, media type, etc.).

property key

Return a unique identifier of this registry item.

Returns:

Unique identifier of this registry item

Return type:

str

core.util.webpub_manifest_parser.core.semantic module

exception core.util.webpub_manifest_parser.core.semantic.CollectionWrongFormatError(collection, inner_exception=None)[source]

Bases: BaseSemanticError

Exception raised in the case when collection’s format (compact, full) doesn’t not conform with its role.

property collection

Return a collection with a wrong format.

Returns:

Collection with a wrong format

Return type:

python_rwpm_parser.ast.Collection

class core.util.webpub_manifest_parser.core.semantic.SemanticAnalyzer(media_types_registry, link_relations_registry, collection_roles_registry)[source]

Bases: Visitor

Visitor performing semantic analysis of the RWPM-compatible documents.

visit

Dispatch methods based on type signature

See Also:

Dispatcher

core.util.webpub_manifest_parser.core.syntax module

exception core.util.webpub_manifest_parser.core.syntax.MissingPropertyError(cls, object_property, message=None, inner_exception=None)[source]

Bases: BaseSyntaxError

Exception raised in the case of a missing required property.

property cls

Return the object’s class where the missing property is defined.

Returns:

Object’s class where the missing property is defined

Return type:

Type

property object_property

Return the missing property.

Returns:

Missing property

Return type:

python_rwpm_parser.metadata.ObjectProperty

class core.util.webpub_manifest_parser.core.syntax.SyntaxAnalyzer[source]

Bases: object

Base class for syntax analyzers checking the base grammar rules of RWPM and parsing raw JSON into AST.

CONTEXT = '@context'
METADATA = 'metadata'
METADATA_IDENTIFIER = 'identifier'
analyze(manifest_json)[source]

Parse JSON file into RWPM AST.

Parameters:

manifest_json (Dict) – RWPM-compatible manifest

Returns:

RWPM AST

Return type:

ManifestLike

Module contents