xml-preferences


Namexml-preferences JSON
Version 1.1.6 PyPI version JSON
download
home_page
Summaryxml-preferences reads and writes preferences infomation from XML files.
upload_time2023-11-07 22:31:37
maintainer
docs_urlNone
author
requires_python>=3.10
licenseApache-2.0
keywords development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Module xml_preferences
----------------------

xml_preferences uses a scheme to create a hierarchy of objects that
represent the data stored in an XML files. CHanges to the objects can
later to saved back into an XML file.

The inspiration for this module is to store preferences for applications.

Classes
-------

  class xml_preferences.XmlPreferences

    __init__( scheme )

        The *scheme* is an instance of xml_preferences.Scheme.

    load( filename )

        Reads the preferences from the *filename* and returns the resulting
        tree of xml_preferences.PreferencesNode objects.

        In case of an error xml_preferences.ParseError is raise.

    loadString( text )

        Reads the preferences from the string *text* and returns the resulting
        tree of xml_preferences.PreferencesNode objects.

        In case of an error xml_preferences.ParseError is raise.

    save( data_node )

        Write the xml_preferences.PreferencesNode *data_node* hierarchy
        into the file used to load() the preferences.

    saveAs( data_node, filename )

        Write the xml_preferences.PreferencesNode *data_node* hierarchy
        into *fileaname*.

    saveToString( data_node )

        Write the xml_preferences.PreferencesNode *data_node* hierarchy
        into a string and return the string.

    saveToFile( data_node, f )

        Write the xml_preferences.PreferencesNode *data_node* hierarchy
        into the file object *f*.

  class xml_preferences.Scheme

    __init__( document_root )

        The *document_root* is an instance of xml_preferences.SchemeNode
        and represent the top level XML document element.

    dumpScheme( f )

        Write a dump of the scheme into the file object *f*.

        This is useful for debugging issues with scheme design.

  class xml_preferences.SchemeNode

    __init__( factory, element_name, all_attribute_info=None, element_plurality=False, key_attribute=None, collection_name=None, store_as=None, default=True, default_attributes=None )

        The *SchemeNode* represents on XML element with the name *element_name*.

        Any attributes that element has are listed in *all_attribute_info*, which is a tuple/list of names or name,type pairs.
        For example:

            all_attribute_info=('description', ('count', int))

        The *SchemeNode* can represent an in three ways:

        1. The element will only appear once.
        2. The element has  *element_plurality* set to True and can appear many times and will be stored as a list of elements in its parent.
        3. The element has a *key_attribute* and can appear many times and will be stored as a dictionary in its parent.

        The *collection_name* defaults to the element_name. The *collection_name* is passed to the parent 
        setChildNodeList or setChildNodeMap functions.

        *store_as* defaults to the *element_name* and is used to name the python variable that this node is store in its in parent object.

        When *default* is True and there is not XML that matches this SchemeNode a default value will be stored in the parent object.

        When the node is defaulted the attributes of the node can be set from a dictionary pass as *default_attributes*.

    dumpScheme( f, indent=0 )

        Write a dump of the scheme into the file object *f*.

        This is useful for debugging issues with scheme design.

    addSchemeChild( scheme_node )
    __lshift__( scheme_node )

        Add *scheme_node* as a child element of this SchemeNode.
        The << operator is useful in making the scheme definition readable.

  class xml_preferences.PreferencesNode

    For typical use all the set and get functions provide all the necessary features.
    That can be overriden to create special behaviour. It is assumed that all
    attribures are initised to a suitable value in __init__.

    __init__()

        Derive from *PreferencesNode* to initialise the variables used to hold the parsed XML preferences.

    finaliseNode( self )

        Called after all attributes and child nodes have been set on this node.

        Use this call to default any missing preferences.

    setAttr( self, name, value )

        Called to save the value of an attribute. The default implemention is:

        setattr( self, name, value )

    setChildNode( self, name, node )

        Called to save the value of singleton child element. The default implemention is:

        setattr( self, name, node )

    setChildNodeList( self, collection_name, node )

        Called to save the value of the next element to added to a list. The default implemention is:

        getattr( self, collection_name ).append( node )

    setChildNodeMap( self, collection_name, key, node )

        Called to save the value of the next element into a dict using the *key*. The default implemention is:

        getattr( self, collection_name )[ key ] = node

    getAttr( self, name )

        Called to get the value of the *name* attribute. The default implemention is:

        return getattr( self, name )

    getChildNode( self, name )

        Called to get the value of the *name* child node. The default implemention is:

        return getattr( self, name )

    getChildNodeList( self, collection_name )

        Called to get a list of values of the *collection_name* child nodes, which are assumed to be stored in a list. The default implemention is:

        return getattr( self, name )

    getChildNodeMap( self, collection_name )

        Called to get a list value of the *collection_name* child nodes, which are assumed to be stored in a dict. The default implemention is:

        return getattr( self, name ).values()

    dumpNode( self, f, indent=0 )

        Write a dump of the PreferencesNode hierarchy into file object *f*.

        Set *indent* to the number of spaces to indent the dumped text.

        Useful when debugging.

Example
-------

    See test_xml_preferences.py for example use.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "xml-preferences",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "",
    "keywords": "development",
    "author": "",
    "author_email": "Barry Scott <barry@barrys-emacs.org>",
    "download_url": "https://files.pythonhosted.org/packages/9e/7c/5f1a0551ff529331cef3cb300add32963637248c612bda54feb074fe0b78/xml-preferences-1.1.6.tar.gz",
    "platform": null,
    "description": "Module xml_preferences\n----------------------\n\nxml_preferences uses a scheme to create a hierarchy of objects that\nrepresent the data stored in an XML files. CHanges to the objects can\nlater to saved back into an XML file.\n\nThe inspiration for this module is to store preferences for applications.\n\nClasses\n-------\n\n  class xml_preferences.XmlPreferences\n\n    __init__( scheme )\n\n        The *scheme* is an instance of xml_preferences.Scheme.\n\n    load( filename )\n\n        Reads the preferences from the *filename* and returns the resulting\n        tree of xml_preferences.PreferencesNode objects.\n\n        In case of an error xml_preferences.ParseError is raise.\n\n    loadString( text )\n\n        Reads the preferences from the string *text* and returns the resulting\n        tree of xml_preferences.PreferencesNode objects.\n\n        In case of an error xml_preferences.ParseError is raise.\n\n    save( data_node )\n\n        Write the xml_preferences.PreferencesNode *data_node* hierarchy\n        into the file used to load() the preferences.\n\n    saveAs( data_node, filename )\n\n        Write the xml_preferences.PreferencesNode *data_node* hierarchy\n        into *fileaname*.\n\n    saveToString( data_node )\n\n        Write the xml_preferences.PreferencesNode *data_node* hierarchy\n        into a string and return the string.\n\n    saveToFile( data_node, f )\n\n        Write the xml_preferences.PreferencesNode *data_node* hierarchy\n        into the file object *f*.\n\n  class xml_preferences.Scheme\n\n    __init__( document_root )\n\n        The *document_root* is an instance of xml_preferences.SchemeNode\n        and represent the top level XML document element.\n\n    dumpScheme( f )\n\n        Write a dump of the scheme into the file object *f*.\n\n        This is useful for debugging issues with scheme design.\n\n  class xml_preferences.SchemeNode\n\n    __init__( factory, element_name, all_attribute_info=None, element_plurality=False, key_attribute=None, collection_name=None, store_as=None, default=True, default_attributes=None )\n\n        The *SchemeNode* represents on XML element with the name *element_name*.\n\n        Any attributes that element has are listed in *all_attribute_info*, which is a tuple/list of names or name,type pairs.\n        For example:\n\n            all_attribute_info=('description', ('count', int))\n\n        The *SchemeNode* can represent an in three ways:\n\n        1. The element will only appear once.\n        2. The element has  *element_plurality* set to True and can appear many times and will be stored as a list of elements in its parent.\n        3. The element has a *key_attribute* and can appear many times and will be stored as a dictionary in its parent.\n\n        The *collection_name* defaults to the element_name. The *collection_name* is passed to the parent \n        setChildNodeList or setChildNodeMap functions.\n\n        *store_as* defaults to the *element_name* and is used to name the python variable that this node is store in its in parent object.\n\n        When *default* is True and there is not XML that matches this SchemeNode a default value will be stored in the parent object.\n\n        When the node is defaulted the attributes of the node can be set from a dictionary pass as *default_attributes*.\n\n    dumpScheme( f, indent=0 )\n\n        Write a dump of the scheme into the file object *f*.\n\n        This is useful for debugging issues with scheme design.\n\n    addSchemeChild( scheme_node )\n    __lshift__( scheme_node )\n\n        Add *scheme_node* as a child element of this SchemeNode.\n        The << operator is useful in making the scheme definition readable.\n\n  class xml_preferences.PreferencesNode\n\n    For typical use all the set and get functions provide all the necessary features.\n    That can be overriden to create special behaviour. It is assumed that all\n    attribures are initised to a suitable value in __init__.\n\n    __init__()\n\n        Derive from *PreferencesNode* to initialise the variables used to hold the parsed XML preferences.\n\n    finaliseNode( self )\n\n        Called after all attributes and child nodes have been set on this node.\n\n        Use this call to default any missing preferences.\n\n    setAttr( self, name, value )\n\n        Called to save the value of an attribute. The default implemention is:\n\n        setattr( self, name, value )\n\n    setChildNode( self, name, node )\n\n        Called to save the value of singleton child element. The default implemention is:\n\n        setattr( self, name, node )\n\n    setChildNodeList( self, collection_name, node )\n\n        Called to save the value of the next element to added to a list. The default implemention is:\n\n        getattr( self, collection_name ).append( node )\n\n    setChildNodeMap( self, collection_name, key, node )\n\n        Called to save the value of the next element into a dict using the *key*. The default implemention is:\n\n        getattr( self, collection_name )[ key ] = node\n\n    getAttr( self, name )\n\n        Called to get the value of the *name* attribute. The default implemention is:\n\n        return getattr( self, name )\n\n    getChildNode( self, name )\n\n        Called to get the value of the *name* child node. The default implemention is:\n\n        return getattr( self, name )\n\n    getChildNodeList( self, collection_name )\n\n        Called to get a list of values of the *collection_name* child nodes, which are assumed to be stored in a list. The default implemention is:\n\n        return getattr( self, name )\n\n    getChildNodeMap( self, collection_name )\n\n        Called to get a list value of the *collection_name* child nodes, which are assumed to be stored in a dict. The default implemention is:\n\n        return getattr( self, name ).values()\n\n    dumpNode( self, f, indent=0 )\n\n        Write a dump of the PreferencesNode hierarchy into file object *f*.\n\n        Set *indent* to the number of spaces to indent the dumped text.\n\n        Useful when debugging.\n\nExample\n-------\n\n    See test_xml_preferences.py for example use.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "xml-preferences reads and writes preferences infomation from XML files.",
    "version": "1.1.6",
    "project_urls": {
        "Bug Tracker": "https://github.com/barry-scott/xml-preferences/issues",
        "Homepage": "https://github.com/barry-scott/xml-preferences"
    },
    "split_keywords": [
        "development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "083431e16ad7d4a503de555a4a808542c685953aba0f7c416a3465ac19974d05",
                "md5": "46676cb9e8d87615d1693710a749bbad",
                "sha256": "87bf0dc333969e03a8ca807f416a58ce57315334132992b8dfec1fcbb2c455b0"
            },
            "downloads": -1,
            "filename": "xml_preferences-1.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "46676cb9e8d87615d1693710a749bbad",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12049,
            "upload_time": "2023-11-07T22:31:35",
            "upload_time_iso_8601": "2023-11-07T22:31:35.906233Z",
            "url": "https://files.pythonhosted.org/packages/08/34/31e16ad7d4a503de555a4a808542c685953aba0f7c416a3465ac19974d05/xml_preferences-1.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e7c5f1a0551ff529331cef3cb300add32963637248c612bda54feb074fe0b78",
                "md5": "7e006ac86f019c3b08b63dc7abd1c3d1",
                "sha256": "e679392fde186a7eec675dad66f3042b7d60bb428e462ff9313f5535d4967acd"
            },
            "downloads": -1,
            "filename": "xml-preferences-1.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "7e006ac86f019c3b08b63dc7abd1c3d1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14183,
            "upload_time": "2023-11-07T22:31:37",
            "upload_time_iso_8601": "2023-11-07T22:31:37.457208Z",
            "url": "https://files.pythonhosted.org/packages/9e/7c/5f1a0551ff529331cef3cb300add32963637248c612bda54feb074fe0b78/xml-preferences-1.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-07 22:31:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "barry-scott",
    "github_project": "xml-preferences",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "xml-preferences"
}
        
Elapsed time: 0.14148s