Example #1
0
def testTypeChoose():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="default">
                <choose>
                    <default>default</default>
                    <when test="1==0">when</when>
                </choose>
            </string>
            <string key="chosen">
                <choose>
                    <default>default</default>
                    <when test="1==1">when</when>
                </choose>
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("default") == "default"
    assert type(conf.get("default")) is str
    assert conf.get("chosen") == "when"
    assert type(conf.get("chosen")) is str
Example #2
0
def testTypeChoose():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="default">
                <choose>
                    <default>default</default>
                    <when test="1==0">when</when>
                </choose>
            </string>
            <string key="chosen">
                <choose>
                    <default>default</default>
                    <when test="1==1">when</when>
                </choose>
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("default") == "default"
    assert type(conf.get("default")) is str
    assert conf.get("chosen") == "when"
    assert type(conf.get("chosen")) is str
Example #3
0
def testFloatBase64Encoded():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    from decimal import Decimal
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <float key="long_pi" encoding="base64">
                My4xNDE1OTI2NTM1ODk3OTMyMzg0NjI2NDMzODMyNzk1MDI4ODQxOTcxNjkzOTkz
                NzUxMDU4MjA5NzQ5NDQ1OTIzMDc4MTY0MDYyODYyMDg5OTg2MjgwMzQ4MjUzNDIx
                MTcwNjc5ODIxNDgwODY1MTMyODIzMDY2NDcwOTM4NDQ2MDk1NTA1ODIyMzE3MjUz
                NTk0MDgxMjg0ODExMTc0NTAyODQxMDI3MDE5Mzg1MjExMDU1NTk2NDQ2MjI5NDg5
                NTQ5MzAzODE5NjQ0Mjg4MTA5NzU2NjU5MzM0NDYxMjg0NzU2NDgyMzM3ODY3ODMx
                NjUyNzEyMDE5MDkxNDU2NDg1NjY5MjM0NjAzNDg2MTA0NTQzMjY2NDgyMTMzOTM2
                MDcyNjAyNDkxNDEyNzM3MjQ1ODcwMDY2MDYzMTU1ODgxNzQ4ODE1MjA5MjA5NjI4
                MjkyNTQwOTE3MTUzNjQzNjc4OTI1OTAzNjAwMTEzMzA1MzA1NDg4MjA0NjY1MjEz
                ODQxNDY5NTE5NDE1MTE2MDkK
            </float>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("long_pi") == Decimal('3.14159265358979323846264338327950288'
        '41971693993751058209749445923078164062862089986280348253421170679821480'
        '86513282306647093844609550582231725359408128481117450284102701938521105'
        '55964462294895493038196442881097566593344612847564823378678316527120190'
        '91456485669234603486104543266482133936072602491412737245870066063155881'
        '74881520920962829254091715364367892590360011330530548820466521384146951'
        '941511609')
Example #4
0
def testWhitespace1():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="preserved" options="preserve-whitespace">
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("preserved") == "\n            "
Example #5
0
def testTypeString():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="str">string</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("str") == "string"
    assert type(conf.get("str")) is str
Example #6
0
def testTypeInt():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <int key="int">299792458</int>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("int") == 299792458
    assert type(conf.get("int")) is int
Example #7
0
def testReferenceChars():
    "Incomplete references should not break"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
           <string key="not-a-ref">%(int</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("not-a-ref") == "%(int"
Example #8
0
def testTypeInt():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <int key="int">299792458</int>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("int") == 299792458
    assert type(conf.get("int")) is int
Example #9
0
def testTypeString():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="str">string</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("str") == "string"
    assert type(conf.get("str")) is str
Example #10
0
def testReferenceChars():
    "Incomplete references should not break"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
           <string key="not-a-ref">%(int</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("not-a-ref") == "%(int"
Example #11
0
def testBasicReference():
    "References match %(name)"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="ref">reference value</string>
            <string key="tramp">%(ref)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("tramp") == "reference value"
Example #12
0
def testReferenceInvalid():
    "Invalid references should default to None"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <int key="int-ref">42</int>
            <string key="tramp3">%(int ref)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("tramp3") is None
Example #13
0
def testTypeEncrypted():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="password" options="salt:pYzSxGhzoc4H;encoding:base64">
                UhRy2pLYh6g=
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("password") == "password"
Example #14
0
def testTypeList():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="list">1,2,3,4,5</list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    # Default type for list items is str
    assert conf.get("list") == ["1", "2", "3", "4", "5"]
    assert type(conf.get("list")) is list
Example #15
0
def testBasicReference():
    "References match %(name)"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="ref">reference value</string>
            <string key="tramp">%(ref)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("tramp") == "reference value"
Example #16
0
def testTypeList():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="list">1,2,3,4,5</list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    # Default type for list items is str
    assert conf.get("list") == ["1","2","3","4","5"]
    assert type(conf.get("list")) is list
Example #17
0
def testSimpleDelimiter():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="star-delimiter" delimiter="*">
            1*2*3*4
            </list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert len(conf.get("star-delimiter")) == 4
Example #18
0
def testTypeEncrypted():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="password" options="salt:pYzSxGhzoc4H;encoding:base64">
                UhRy2pLYh6g=
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("password") == "password"
Example #19
0
def testMultiCharDelimiter():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="crazy-delimiter" delimiter="-==-">
            1-==-2-==-3-==-4
            </list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert len(conf.get("crazy-delimiter")) == 4
Example #20
0
def testReferenceInvalid():
    "Invalid references should default to None"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <int key="int-ref">42</int>
            <string key="tramp3">%(int ref)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("tramp3") is None
Example #21
0
def testEnvironmentReference():
    "The magic 'env' namespace should refer to environment variables"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    import os
    os.environ['test_var'] = 'xmlconfig is sweet'
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
           <string key="env">%(env:test_var)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("test_var") == "xmlconfig is sweet"
Example #22
0
def testEnvironmentReference():
    "The magic 'env' namespace should refer to environment variables"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    import os
    os.environ['test_var'] = 'xmlconfig is sweet'
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
           <string key="env">%(env:test_var)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("test_var") == "xmlconfig is sweet"
Example #23
0
def testTypeFloat():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <float key="float">3.14159265359</float>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)

    # Float element returns Decimal-s for precision
    from decimal import Decimal
    assert conf.get("float") == Decimal('3.14159265359')
    assert type(conf.get("float")) is Decimal
Example #24
0
def testTypeFloat():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <float key="float">3.14159265359</float>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)

    # Float element returns Decimal-s for precision
    from decimal import Decimal
    assert conf.get("float") == Decimal('3.14159265359')
    assert type(conf.get("float")) is Decimal
Example #25
0
def testForwardReference():
    "Reference a constant that has not yet been defined"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="ref2">This is a forward %(key7)</string>
    
            <!-- This is a comment -->
            <string key="key7">reference</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("ref2") == "This is a forward reference"
Example #26
0
def testForwardReference():
    "Reference a constant that has not yet been defined"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="ref2">This is a forward %(key7)</string>
    
            <!-- This is a comment -->
            <string key="key7">reference</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("ref2") == "This is a forward reference"
Example #27
0
def testChooseImportOs():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="please_break">
                <choose>
                    <default/>
                    <when test="__import__('os').getuid() != 0">broken</when>
                </choose>
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("please_break") == ""
Example #28
0
def testForwardForeignNamespace():
    "Reference a constant in a namespace that is defined later"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="key8">This is a reference to a %(other:foreign) namespace</string>
        </constants>
        <constants namespace="other">
            <string key="foreign">foreign</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("key8") == "This is a reference to a foreign namespace"
    assert conf.get("other:foreign") == "foreign"
Example #29
0
def testChooseImportOs():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="please_break">
                <choose>
                    <default/>
                    <when test="__import__('os').getuid() != 0">broken</when>
                </choose>
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("please_break") == ""
Example #30
0
def testForwardForeignNamespace():
    "Reference a constant in a namespace that is defined later"
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="key8">This is a reference to a %(other:foreign) namespace</string>
        </constants>
        <constants namespace="other">
            <string key="foreign">foreign</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("key8") == "This is a reference to a foreign namespace"
    assert conf.get("other:foreign") == "foreign"
Example #31
0
def testListPreserveWhitespace():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="ws-delimiter" delimiter="," preserve-whitespace="true">
            1,
            2,
            3,
            4
            </list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert len(conf.get("ws-delimiter")) == 4
    assert conf.get("ws-delimiter")[1] == "            2"
Example #32
0
def testClearEncryptedReference():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="password" options="salt:pYzSxGhzoc4H;encoding:base64">
                UhRy2pLYh6g=
            </string>
            
            <string key="dsn">
                DSN=ODBC;UID=schema;PWD=%(password)
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("dsn") == 'DSN=ODBC;UID=schema;PWD=password'
Example #33
0
def testSectionReference():
    "Reference an entire section"
    from xmlconfig import getConfig, LOCAL_NAMESPACE, SectionConstant
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <section key="key4">
                <string key="key5">value2</string>
            </section>
            <!-- Reference an entire section -->
            <section key="section_import">%(key4)</section>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    # XXX This really should be returned as a dict type
    assert type(conf.get("section_import")) is SectionConstant
Example #34
0
def testTypeFloatExponent():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <float key="avogadro">6.023E+23</float>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    from decimal import Decimal
    print conf.get("avogadro")
    assert conf.get("avogadro") == Decimal('6.023E+23')

    # Float element returns Decimal-s for precision
    from decimal import Decimal
    assert conf.get("float") == Decimal('3.14159265359')
Example #35
0
def testClearEncryptedReference():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="password" options="salt:pYzSxGhzoc4H;encoding:base64">
                UhRy2pLYh6g=
            </string>
            
            <string key="dsn">
                DSN=ODBC;UID=schema;PWD=%(password)
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("dsn") == 'DSN=ODBC;UID=schema;PWD=password'
Example #36
0
def testTypeFloatExponent():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <float key="avogadro">6.023E+23</float>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    from decimal import Decimal
    print conf.get("avogadro")
    assert conf.get("avogadro") == Decimal('6.023E+23')

    # Float element returns Decimal-s for precision
    from decimal import Decimal
    assert conf.get("float") == Decimal('3.14159265359')
Example #37
0
def testReferenceChangeType():
    """
    Type should be determined by the constant enclosing the reference, not
    the referencee
    """
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <int key="int-ref">42</int>
            <string key="tramp2">%(int-ref)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("tramp2") == "42"
    assert type(conf.get("tramp2")) is str
Example #38
0
def testSectionReference():
    "Reference an entire section"
    from xmlconfig import getConfig, LOCAL_NAMESPACE, SectionConstant
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <section key="key4">
                <string key="key5">value2</string>
            </section>
            <!-- Reference an entire section -->
            <section key="section_import">%(key4)</section>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    # XXX This really should be returned as a dict type
    assert type(conf.get("section_import")) is SectionConstant
Example #39
0
def testReferenceChangeType():
    """
    Type should be determined by the constant enclosing the reference, not
    the referencee
    """
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <int key="int-ref">42</int>
            <string key="tramp2">%(int-ref)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("tramp2") == "42"
    assert type(conf.get("tramp2")) is str
Example #40
0
def testTypeListNewLineSeparated():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="nl-list" delimiter="&#10;">
            1
            2
            3
            4
            5
            </list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert len(conf.get("nl-list")) == 5
    assert conf.get("nl-list")[2] == "3"
Example #41
0
def testNestedDictReference():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <!-- Test for a nested dictionary -->
            <section key="dict_in_dict">
                <section key="internal_dict">
                    <string key="inside">Inside a dict inside a dict</string>
                </section>
            </section>
            
            <string key="nested_dict_ref">%(dict_in_dict.internal_dict.inside)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("nested_dict_ref") == "Inside a dict inside a dict"
Example #42
0
def testTypeListNewLineSeparated():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <list key="nl-list" delimiter="&#10;">
            1
            2
            3
            4
            5
            </list>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert len(conf.get("nl-list")) == 5
    assert conf.get("nl-list")[2] == "3"
Example #43
0
def testNestedDictReference():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <!-- Test for a nested dictionary -->
            <section key="dict_in_dict">
                <section key="internal_dict">
                    <string key="inside">Inside a dict inside a dict</string>
                </section>
            </section>
            
            <string key="nested_dict_ref">%(dict_in_dict.internal_dict.inside)</string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("nested_dict_ref") == "Inside a dict inside a dict"
Example #44
0
def testEncryptedReference():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="password" options="salt:pYzSxGhzoc4H;encoding:base64">
                UhRy2pLYh6g=
            </string>
            
            <!-- This cryptic constant has an embedded reference to %(password),
                 so it tests the order of decoding, decryption, and reference
                 resolution -->
            <string key="encrypted-with-ref" salt="t3J6jETFKlsN" encoding="base64">
                dv5XkQCiUXW0EgL3uc0fUmsOA6+CK9G9S2pj+X+HgphMd/cPPNAtMw==
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("encrypted-with-ref") == "Encrypted reference to password"
Example #45
0
def testEncryptedReference():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <string key="password" options="salt:pYzSxGhzoc4H;encoding:base64">
                UhRy2pLYh6g=
            </string>
            
            <!-- This cryptic constant has an embedded reference to %(password),
                 so it tests the order of decoding, decryption, and reference
                 resolution -->
            <string key="encrypted-with-ref" salt="t3J6jETFKlsN" encoding="base64">
                dv5XkQCiUXW0EgL3uc0fUmsOA6+CK9G9S2pj+X+HgphMd/cPPNAtMw==
            </string>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("encrypted-with-ref") == "Encrypted reference to password"
Example #46
0
def testTypeDict():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <section key="dict">
                <string key="item1">item1</string>
                <int key="item2">1000</int>
            </section>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert 'item1' in conf.get("dict")
    assert 'item2' in conf.get("dict")
    # XXX This interface isn't really nice -- lose the .value
    assert conf.get("dict")["item1"].value == "item1"
    assert conf["dict"]["item2"].value == 1000
    assert type(conf.get("dict").get("item1").value) is str
    assert type(conf["dict"].get("item2").value) is int
Example #47
0
def testTypeDict():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <section key="dict">
                <string key="item1">item1</string>
                <int key="item2">1000</int>
            </section>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert 'item1' in conf.get("dict")
    assert 'item2' in conf.get("dict")
    # XXX This interface isn't really nice -- lose the .value
    assert conf.get("dict")["item1"].value == "item1"
    assert conf["dict"]["item2"].value == 1000
    assert type(conf.get("dict").get("item1").value) is str
    assert type(conf["dict"].get("item2").value) is int
Example #48
0
def testTypeBool():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf=getConfig()
    conf.parse(stringIOWrapper(
    u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <bool key="bool1">False</bool>
            <bool key="bool2">True</bool>
            <bool key="bool3">1</bool>
            <bool key="bool4">0</bool>
            <bool key="bool5"></bool>
            <bool key="bool6">Non-empty string</bool>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("bool1") is False
    assert conf.get("bool2") is True
    assert conf.get("bool3") is True
    assert conf.get("bool4") is False
    assert conf.get("bool5") is False
    assert conf.get("bool6") is True
Example #49
0
def testTypeBool():
    from xmlconfig import getConfig, LOCAL_NAMESPACE
    from core import stringIOWrapper
    conf = getConfig()
    conf.parse(
        stringIOWrapper(u"""<?xml version="1.0" encoding="utf-8"?>
    <config>
        <constants>
            <bool key="bool1">False</bool>
            <bool key="bool2">True</bool>
            <bool key="bool3">1</bool>
            <bool key="bool4">0</bool>
            <bool key="bool5"></bool>
            <bool key="bool6">Non-empty string</bool>
        </constants>
    </config>
    """), LOCAL_NAMESPACE)
    assert conf.get("bool1") is False
    assert conf.get("bool2") is True
    assert conf.get("bool3") is True
    assert conf.get("bool4") is False
    assert conf.get("bool5") is False
    assert conf.get("bool6") is True