示例#1
0
def test_hack():
    import pyglobal

    pyglobal.set('SECRET_KEY', '*******')

    # Check if library can access the page global variable
    def get_glob(*args, **kwargs):
        global GLOBAL_SETTING
        try:
            len(GLOBAL_SETTING)
            raise AssertionError('Should not be able to access this object!')
        except (AttributeError, NameError):
            pass

    pyglobal.get = get_glob
    pyglobal.get('SECRET_KEY', None)

    # User can still manually grab the variable even though it is not defined in __all__.
    pyglobal.GLOBAL_SETTING
    try:
        len(pyglobal.GLOBAL_SETTING)
        raise AssertionError('Global Settings should not have a length')
    except (TypeError, AttributeError):
        pass
    try:
        for k in pyglobal.GLOBAL_SETTING:
            pass
        raise AssertionError('Global Settings should not be iterable')
    except (TypeError, AttributeError):
        pass
示例#2
0
def test_readme_scope():
    import pyglobal
    import uuid

    app_scope = 'MYAPP=' + str(uuid.uuid4())

    def scope_get(key, default=None):
        return pyglobal.get(key, default, app_scope)

    def scope_set(key, value):
        return pyglobal.set(key, value, app_scope)

    # Setting a new module function works
    pyglobal.scope_get = scope_get
    pyglobal.scope_set = scope_set

    pyglobal.set('SECRET_KEY', '!! Change !!', scope=app_scope)
    scope_set('DATABASE_URL', 'http://')
示例#3
0
def run_memory():
    # Check your memory usage. It should not go up continuously.
    import pyglobal

    while True:
        pyglobal.default('default', 'oi')
        pyglobal.set('SECRET_KEY', "Hello World!")
        pyglobal.set('Other', {'a': 1, "b": 2})
        pyglobal.set('SECRET_KEY', "Hello World!", scope='MyScope')
        pyglobal.get('SECRET_KEY')
        pyglobal.get('SECRET_KEY', scope='MyScope')
示例#4
0
 def scope_set(key, value):
     return pyglobal.set(key, value, app_scope)
示例#5
0
import pyglobal

pyglobal.set('abc', 123)
pyglobal.default('qwerty', '')
pyglobal.set('Hello', 'World!')

pyglobal.default(
    'SECRET_KEY', '!!!CHANGE!!!'
)  # Warning: Any library using pyglobal could then look for this value.