parsers.py
This definition returns an attribute compound.
Usage:
>>> data = "@Link | Value | Boolean | Link Parameter"
>>> attributeCompound = foundations.parsers.getAttributeCompound("Attribute Compound", data)
>>> attributeCompound.name
u'Attribute Compound'
>>> attributeCompound.value
u'Value'
>>> attributeCompound.link
u'@Link'
>>> attributeCompound.type
u'Boolean'
>>> attributeCompound.alias
u'Link Parameter'
Parameters: |
|
---|---|
Returns: | Attribute compound. ( AttributeCompound ) |
Bases: foundations.dataStructures.Structure
This class represents a storage object for attributes compounds usually encountered in sIBL_GUI Templates files.
Some attributes compounds:
- Name = @Name | Standard | String | Template Name
- Background|BGfile = @BGfile
- showCamerasDialog = @showCamerasDialog | 0 | Boolean | Cameras Selection Dialog
Usage:
AttributeCompound(name="showCamerasDialog",
value="0",
link="@showCamerasDialog",
type="Boolean",
alias="Cameras Selection Dialog")
Parameters: | **kwargs – name, value, link, type, alias. ( Key / Value pairs ) |
---|
Bases: foundations.io.File
This class provides methods to parse sections file format files, an alternative configuration file parser is available directly with Python: ConfigParser.ConfigParser.
The parser given by this class has some major differences with Python ConfigParser.ConfigParser:
Sections and attributes are stored in their appearance order by default. ( Using Python collections.OrderedDict ) A default section ( _default ) will store orphans attributes ( Attributes appearing before any declared section ).File comments are stored inside the SectionsFileParser.comments class property.
Sections, attributes and values are whitespaces stripped by default but can also be stored with their leading and trailing whitespaces. Values are quotations markers stripped by default but can also be stored with their leading and trailing quotations markers.Attributes are namespaced by default allowing sections merge without keys collisions.
Usage:
>>> content = ["[Section A]\n", "; Comment.\n", "Attribute 1 = \"Value A\"\n", "\n", "[Section B]\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse(stripComments=False)
True
>>> sectionsFileParser.sections.keys()
[u'Section A', u'Section B']
>>> sectionsFileParser.comments
OrderedDict([(u'Section A|#0', {u'content': u'Comment.', u'id': 0})])
Parameters: |
|
---|
This method is the property for self.__splitters attribute.
Returns: | self.__splitters. ( Tuple / List ) |
---|
This method is the property for self.__namespaceSplitter attribute.
Returns: | self.__namespaceSplitter. ( String ) |
---|
This method is the property for self.__commentLimiters attribute.
Returns: | self.__commentLimiters. ( Tuple / List ) |
---|
This method is the property for self.__commentMarker attribute.
Returns: | self.__commentMarker. ( String ) |
---|
This method is the property for self.__quotationMarkers attribute.
Returns: | self.__quotationMarkers. ( Tuple / List ) |
---|
This method is the property for self.___raw__Identifier attribute.
Returns: | self.___raw__Identifier. ( String ) |
---|
This method is the property for self.__defaultsSection attribute.
Returns: | self.__defaultsSection. ( String ) |
---|
This method is the property for self.__sections attribute.
Returns: | self.__sections. ( OrderedDict / Dictionary ) |
---|
This method is the property for self.__comments attribute.
Returns: | self.__comments. ( OrderedDict / Dictionary ) |
---|
This method is the property for self.__parsingErrors attribute.
Returns: | self.__parsingErrors. ( List ) |
---|
Usage:
>>> content = ["; Comment.\n", "Attribute 1 = \"Value A\"\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse(stripComments=False)
True
>>> sectionsFileParser.sections.keys()
[u'_defaults']
>>> sectionsFileParser.sections["_defaults"].values()
[u'Value A', u'Value B']
>>> sectionsFileParser.parse(stripComments=False, stripQuotationMarkers=False)
True
>>> sectionsFileParser.sections["_defaults"].values()
[u'"Value A"', u'"Value B"']
>>> sectionsFileParser.comments
OrderedDict([(u'_defaults|#0', {u'content': u'Comment.', u'id': 0})])
>>> sectionsFileParser.parse()
True
>>> sectionsFileParser.sections["_defaults"]
OrderedDict([(u'_defaults|Attribute 1', u'Value A'), (u'_defaults|Attribute 2', u'Value B')])
>>> sectionsFileParser.parse(namespaces=False)
True
>>> sectionsFileParser.sections["_defaults"]
OrderedDict([(u'Attribute 1', u'Value A'), (u'Attribute 2', u'Value B')])
Parameters: |
|
---|---|
Returns: | Method success. ( Boolean ) |
This method checks if given section exists.
Usage:
>>> content = ["[Section A]\n", "; Comment.\n", "Attribute 1 = \"Value A\"\n", "\n", "[Section B]\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse()
True
>>> sectionsFileParser.sectionExists("Section A")
True
>>> sectionsFileParser.sectionExists("Section C")
False
Parameters: | section – Section to check existence. ( String ) |
---|---|
Returns: | Section existence. ( Boolean ) |
This method checks if given attribute exists.
Usage:
>>> content = ["[Section A]\n", "; Comment.\n", "Attribute 1 = \"Value A\"\n", "\n", "[Section B]\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse()
True
>>> sectionsFileParser.attributeExists("Attribute 1", "Section A")
True
>>> sectionsFileParser.attributeExists("Attribute 2", "Section A")
False
Parameters: |
|
---|---|
Returns: | Attribute existence. ( Boolean ) |
This method returns given section attributes.
Usage:
>>> content = ["[Section A]\n", "; Comment.\n", "Attribute 1 = \"Value A\"\n", "\n", "[Section B]\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse()
True
>>> sectionsFileParser.getAttributes("Section A")
OrderedDict([(u'Section A|Attribute 1', u'Value A')])
>>> sectionsFileParser.getAttributes("Section A", orderedDictionary=False)
{u'Section A|Attribute 1': u'Value A'}
>>> sectionsFileParser.getAttributes("Section A", stripNamespaces=True)
OrderedDict([(u'Attribute 1', u'Value A')])
Parameters: |
|
---|---|
Returns: | Attributes. ( OrderedDict / Dictionary ) |
This method returns all sections attributes.
Usage:
>>> content = ["[Section A]\n", "; Comment.\n", "Attribute 1 = \"Value A\"\n", "\n", "[Section B]\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse()
True
>>> sectionsFileParser.getAllAttributes()
OrderedDict([(u'Section A|Attribute 1', u'Value A'), (u'Section B|Attribute 2', u'Value B')])
>>> sectionsFileParser.getAllAttributes(orderedDictionary=False)
{u'Section B|Attribute 2': u'Value B', u'Section A|Attribute 1': u'Value A'}
Parameters: | orderedDictionary – Use an collections.OrderedDict dictionary to store the attributes. ( String ) |
---|---|
Returns: | All sections / files attributes. ( OrderedDict / Dictionary ) |
This method returns requested attribute value.
Usage:
>>> content = ["[Section A]\n", "; Comment.\n", "Attribute 1 = \"Value A\"\n", "\n", "[Section B]\n", "Attribute 2 = \"Value B\"\n"]
>>> sectionsFileParser = SectionsFileParser()
>>> sectionsFileParser.content = content
>>> sectionsFileParser.parse()
True
>>> sectionsFileParser.getValue("Attribute 1", "Section A")
u'Value A'
Parameters: |
|
---|---|
Returns: | Attribute value. ( String ) |
Usage:
>>> sections = {"Section A": {"Section A|Attribute 1": "Value A"}, "Section B": {"Section B|Attribute 2": "Value B"}}
>>> sectionsFileParser = SectionsFileParser("SectionsFile.rc")
>>> sectionsFileParser.sections = sections
>>> sectionsFileParser.write()
True
>>> sectionsFileParser.read()
u'[Section A]\nAttribute 1 = Value A\n\n[Section B]\nAttribute 2 = Value B\n'
Parameters: |
|
---|---|
Returns: | Method success. ( Boolean ) |
Bases: foundations.io.File
This class provides methods to parse plist files.
Usage:
>>> plistFileParser = PlistFileParser("standard.plist")
>>> plistFileParser.parse()
True
>>> plistFileParser.elements.keys()
[u'Dictionary A', u'Number A', u'Array A', u'String A', u'Date A', u'Boolean A', u'Data A']
>>> plistFileParser.elements["Dictionary A"]
{u'String C': u'My Value C', u'String B': u'My Value B'}
Parameters: | file – Current file path. ( String ) |
---|
This method is the property for self.__elements attribute.
Returns: | self.__elements. ( OrderedDict / Dictionary ) |
---|
This method is the property for self.__parsingErrors attribute.
Returns: | self.__parsingErrors. ( List ) |
---|
This method is the property for self.__unserializers attribute.
Returns: | self.__unserializers. ( Dictionary ) |
---|
This method process the file content.
Usage:
>>> plistFileParser = PlistFileParser("standard.plist")
>>> plistFileParser.parse()
True
>>> plistFileParser.elements.keys()
[u'Dictionary A', u'Number A', u'Array A', u'String A', u'Date A', u'Boolean A', u'Data A']
Parameters: | raiseParsingErrors – Raise parsing errors. ( Boolean ) |
---|---|
Returns: | Method success. ( Boolean ) |
This method checks if given element exists.
Usage:
>>> plistFileParser = PlistFileParser("standard.plist")
>>> plistFileParser.parse()
True
>>> plistFileParser.elementExists("String A")
True
>>> plistFileParser.elementExists("String Nemo")
False
Parameters: | element – Element to check existence. ( String ) |
---|---|
Returns: | Element existence. ( Boolean ) |
Usage:
>>> plistFileParser = PlistFileParser("standard.plist")
>>> plistFileParser.parse()
True
>>> plistFileParser.filterValues(r"String A")
[u'My Value A']
>>> plistFileParser.filterValues(r"String.*")
[u'My Value C', u'My Value B', u'My Value A']
Parameters: |
|
---|---|
Returns: | Values. ( List ) |
Usage:
>>> plistFileParser = PlistFileParser("standard.plist")
>>> plistFileParser.parse()
True
>>> plistFileParser.getValue("String A")
u'My Value A'
Parameters: | element – Element to get the value. ( String ) |
---|---|
Returns: | Element value. ( Object ) |