Manifest object#

The manifest object contains structured datas of parsed and serialized CSS manifest.

Each reference rule is stored in as object attribute and every metas rules are stored in Manifest.metas attribute.

class py_css_styleguide.model.Manifest[source]#

Manifest object.

During load process, every rule is stored as object attribute so you can reach them directly.

_path#

Possible filepath for source if it has been given or finded from source file-object.

Type:

string

_datas#

Dictionnary of every rules returned by parser. This is not something you would need to reach commonly.

Type:

dict

_rule_attrs#

List of registered reference rules. You may use it in iteration to find available reference attribute names.

Type:

list

metas#

Dictionnary of every meta datas from manifest. Either filled by serializer (with load method) or dump content (with from_dict method).

Type:

dict

load(source, filepath=None)[source]#

Load source as manifest attributes

Parameters:

source (string or file-object) – CSS source to parse and serialize to find metas and rules. It can be either a string or a file-like object (aka with a read() method which return string).

Keyword Arguments:

filepath (string) – Optional filepath to memorize if source comes from a file. Default is None as if source comes from a string. If source argument is a file-like object, you should not need to bother of this argument since filepath will be filled from source name attribute.

Returns:

Dictionnary of serialized rules.

Return type:

dict

to_dict()[source]#

Serialize metas and reference attributes to a dictionnary.

Returns:

Data dictionnary.

Return type:

dict

to_json(indent=4)[source]#

Serialize metas and reference attributes to a JSON string.

Keyword Arguments:

indent (int) – Space indentation, default to 4.

Returns:

JSON datas.

Return type:

string

from_dict(data)[source]#

Load given data as manifest attributes.

Alike load method this initialize the manifest object with references (and metas) but without to parse CSS, only from a dictionnary.

Parameters:

data (dict) – A dictionnary of datas to load. This dictionnary have to be in the same format and structure than the one returned by to_dict method.