示例#1
0
def dumps(vals, pretty=0, braces=0, sorted=1, hsize=0, crossref=0):
    '''
    Dump sequence of values into unicode text.

    :param vals:
       Sequence of values to convert.

    :param pretty:
        Flag indicating pretty dumping:

        * `True` - use pretty dumping
        * `False` - compact dumping (default)

    :param braces:
        Flag indicating using braces (JSON-style) during formatting:

        * `True` - use formatting with braces (JSON-style)
        * `False` - use formatting without braces (YAML-style, default)

    :param crossref:
        Flag for crossreferece support in unsafe mode

        * `True` - use reference to the object on duplicate
        * `False` - use copy of the object on duplicate (default)

    :returns:
        Unicode text in AXON format.
    '''
    fd = StringWriter()

    dumper = Dumper(fd, pretty, braces, sorted, hsize, crossref)
    dumper.dump(vals)
    v = fd.getvalue()
    fd.close()
    return v
示例#2
0
文件: api.py 项目: gelstudios/paper
def dumps(vals, pretty=0, braces=0, sorted=1, hsize=0, crossref=0):
    '''
    Dump sequence of values into unicode text.

    :param vals:
       Sequence of values to convert.

    :param pretty:
        Flag indicating pretty dumping:

        * `True` - use pretty dumping
        * `False` - compact dumping (default)

    :param braces:
        Flag indicating using braces (JSON-style) during formatting:

        * `True` - use formatting with braces (JSON-style)
        * `False` - use formatting without braces (YAML-style, default)

    :param crossref:
        Flag for crossreferece support in unsafe mode

        * `True` - use reference to the object on duplicate
        * `False` - use copy of the object on duplicate (default)

    :returns:
        Unicode text in AXON format.
    '''
    fd = StringWriter()

    dumper = Dumper(fd, pretty, braces, sorted, hsize, crossref)
    dumper.dump(vals)
    v = fd.getvalue()
    fd.close()
    return v
示例#3
0
文件: api.py 项目: gelstudios/paper
def dump(fpath, val, pretty=0, braces=0, sorted=1, hsize=0, crossref=0, encoding='utf-8'):
    '''\
    Same as :py:func:`dumps` but for dumping into a file.

    :param fpath:
        Path to file for dumping.

    For other parameters see :py:func:`dumps`.
    '''
    fd = io.open(fpath, mode='w', encoding=encoding)

    dumper = Dumper(fd, pretty, braces, sorted, hsize, crossref)
    dumper.dump(val)
    fd.close()
示例#4
0
def dump(fpath,
         val,
         pretty=0,
         braces=0,
         sorted=1,
         hsize=0,
         crossref=0,
         encoding='utf-8'):
    '''\
    Same as :py:func:`dumps` but for dumping into a file.

    :param fpath:
        Path to file for dumping.

    For other parameters see :py:func:`dumps`.
    '''
    fd = io.open(fpath, mode='w', encoding=encoding)

    dumper = Dumper(fd, pretty, braces, sorted, hsize, crossref)
    dumper.dump(val)
    fd.close()