Ejemplo n.º 1
0
def convert(string, from_, to_):
    if from_ == to_:
        return encoded(string)
    assert from_ in FORMATS and to_ in FORMATS
    g = Graph()
    g.parse(StringIO(encoded(string)), format=from_)
    out = StringIO()
    g.serialize(out, format=to_)
    out.seek(0)
    return out.read()
Ejemplo n.º 2
0
def convert(string, from_, to_):
    if from_ == to_:
        return encoded(string)
    assert from_ in FORMATS and to_ in FORMATS
    g = Graph()
    g.parse(StringIO(encoded(string)), format=from_)
    out = StringIO()
    g.serialize(out, format=to_)
    out.seek(0)
    return out.read()
Ejemplo n.º 3
0
def convert(string, from_, to_=None):
    assert from_ in FORMATS and (to_ is None or to_ in FORMATS)

    res = pipe('%s2xml -i utf8 -o utf8' % from_, encoded(string))
    if to_:
        res = pipe('xml2%s -i utf8 -o utf8' % to_, res)
    return res.decode('utf8')
Ejemplo n.º 4
0
def pipe(cmd, input_):
    proc = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    return proc.communicate(encoded(input_))[0]