Exemplo n.º 1
0
def iloads(text, mode="safe", errto=None, json=0):
    '''\
    Iterative loading values from unicode text.

    :param text:
        Unicode text.

    :param mode:
        Specifies the method of building python objects for complex values
        (see .. py:func:`load`)

    :param errto:
        Name of file for reporting errors

    :param json:
        If true then allow JSON encoded parts.

    :returns:
        Iterator object. It returns values during iteration.
    '''
    text = as_unicode(text)
    fd = StringReader(text)

    loader = Loader(fd, mode, errto, json)
    for val in loader.iload():
        yield val
Exemplo n.º 2
0
def load(fd, mode="safe", errto=None, encoding='utf-8', json=0):
    '''
    Load object from unicode text.

    :param fd:
        Input file name of file object opening as TextIO/StringIO.

    :param mode:
        Specifies the method of building python objects for complex values.

        There are values of parameter `mode`:
            * `safe` - use safe object builder
            * `strict` - use unsafe builder with strict name resolution: if there is no registered name
              for building object builder return `undef` object
            * `mixed` - use unsafe object builder with following rule: if there is no registered name
              for building object then use `safe` mode.

    :param errto:
        Name of file for reporting errors

    :param encoding:
        Encoding of input file (default `utf-8`).

    :param json:
        If true then allow JSON encoded parts.

    :returns:
        List of values.
    '''
    if type(fd) in (str_type, unicode_type):
        fd = io.open(fd, mode='r', encoding=encoding)

    loader = Loader(fd, mode, errto, json)
    return loader.load()
Exemplo n.º 3
0
def loads(text, mode="safe", errto=None, json=0):
    '''\
    Load values from unicode text.

    :param text:
        Unicode text.

    :param mode:
        Specifies the method of building python objects for complex values
        (see .. py:func:`load`)

    :param errto:
        Name of file for reporting errors

    :param json:
        If true then allow JSON encoded parts.

    :returns:
        List of values.
    '''
    text = as_unicode(text)
    fd = StringReader(text)

    loader = Loader(fd, mode, errto, json)
    return loader.load()
Exemplo n.º 4
0
def iloads(text, mode="safe", errto=None, json=0):
    '''\
    Iterative loading values from unicode text.

    :param text:
        Unicode text.

    :param mode:
        Specifies the method of building python objects for complex values
        (see .. py:func:`load`)

    :param errto:
        Name of file for reporting errors

    :param json:
        If true then allow JSON encoded parts.

    :returns:
        Iterator object. It returns values during iteration.
    '''
    text = as_unicode(text)
    fd = StringReader(text)

    loader = Loader(fd, mode, errto, json)
    for val in loader.iload():
        yield val
Exemplo n.º 5
0
def load(fd, mode="safe", errto=None, encoding='utf-8', json=0):
    '''
    Load object from unicode text.

    :param fd:
        Input file name of file object opening as TextIO/StringIO.

    :param mode:
        Specifies the method of building python objects for complex values.

        There are values of parameter `mode`:
            * `safe` - use safe object builder
            * `strict` - use unsafe builder with strict name resolution: if there is no registered name
              for building object builder return `undef` object
            * `mixed` - use unsafe object builder with following rule: if there is no registered name
              for building object then use `safe` mode.

    :param errto:
        Name of file for reporting errors

    :param encoding:
        Encoding of input file (default `utf-8`).

    :param json:
        If true then allow JSON encoded parts.

    :returns:
        List of values.
    '''
    if type(fd) in (str_type, unicode_type):
        fd = io.open(fd, mode='r', encoding=encoding)

    loader = Loader(fd, mode, errto, json)
    return loader.load()
Exemplo n.º 6
0
def loads(text, mode="safe", errto=None, json=0):
    '''\
    Load values from unicode text.

    :param text:
        Unicode text.

    :param mode:
        Specifies the method of building python objects for complex values
        (see .. py:func:`load`)

    :param errto:
        Name of file for reporting errors

    :param json:
        If true then allow JSON encoded parts.

    :returns:
        List of values.
    '''
    text = as_unicode(text)
    fd = StringReader(text)

    loader = Loader(fd, mode, errto, json)
    return loader.load()
Exemplo n.º 7
0
def iload(fd, mode="safe", errto=None, encoding='utf-8', json=0):
    '''\
    Iterative loading values from input file.

    Arguments are same as in .. py:func:`load`.

    :returns:
        iterator object.
    '''

    if type(fd) in (str_type, unicode_type):
        fd = io.open(fd, mode='r', encoding=encoding)

    loader = Loader(fd, mode, errto, json)
    for val in loader.iload():
        yield val
Exemplo n.º 8
0
def iload(fd, mode="safe", errto=None, encoding='utf-8', json=0):
    '''\
    Iterative loading values from input file.

    Arguments are same as in .. py:func:`load`.

    :returns:
        iterator object.
    '''

    if type(fd) in (str_type, unicode_type):
        fd = io.open(fd, mode='r', encoding=encoding)

    loader = Loader(fd, mode, errto, json)
    for val in loader.iload():
        yield val