Exemplo n.º 1
0
    def test_does_not_double_encode(self):
        x = u"λ"
        x_e = forcestr(x)
        assert forcestr(x_e) == x_e

        x_u = forceunicode(x_e)
        assert forceunicode(x_u) == x_u
Exemplo n.º 2
0
    def test_does_not_double_encode(self):
        x = u"λ"
        x_e = forcestr(x)
        assert forcestr(x_e) == x_e

        x_u = forceunicode(x_e)
        assert forceunicode(x_u) == x_u
Exemplo n.º 3
0
    def test_idempotent(self):
        x = u"a"
        assert forceunicode(forcestr(x)) == x

        x = u"λ"
        assert forceunicode(forcestr(x)) == x

        assert forceunicode(forcestr(SOURCE1)) == SOURCE1

        x = "a"
        assert forcestr(forceunicode(x)) == x
Exemplo n.º 4
0
    def test_idempotent(self):
        x = u"a"
        assert forceunicode(forcestr(x)) == x

        x = u"λ"
        assert forceunicode(forcestr(x)) == x

        assert forceunicode(forcestr(SOURCE1)) == SOURCE1

        x = "a"
        assert forcestr(forceunicode(x)) == x
Exemplo n.º 5
0
def ssh_graph_server(sshargs):
    s1 = socket.socket()
    s1.bind(('127.0.0.1', socket.INADDR_ANY))
    localhost, localport = s1.getsockname()

    if sshargs[0] != 'LOCAL':
        remoteport = random.randrange(10000, 20000)
        #  ^^^ and just hope there is no conflict

        args = [
            'ssh', '-S', 'none', '-C',
            '-R%d:127.0.0.1:%d' % (remoteport, localport)
        ]
        args = args + sshargs + ['python -u -c "exec input()"']
    else:
        remoteport = localport
        args = ['python', '-u', '-c', 'exec input()']

    print(' '.join(args))
    p = subprocess.Popen(args,
                         bufsize=0,
                         stdin=subprocess.PIPE,
                         stdout=subprocess.PIPE)
    p.stdin.write(
        forcestr(repr('port=%d\n%s' % (remoteport, REMOTE_SOURCE)) + '\n'))
    line = p.stdout.readline()
    assert line == 'OK\n'

    graphserver.listen_server(None, s1=s1)
Exemplo n.º 6
0
 def reload(graph_id):
     page = getpage(graph_id)
     if save_tmp_file:
         f = open(save_tmp_file, 'w')
         f.write(forcestr(page.source))
         f.close()
     messages.extend(page_messages(page, graph_id))
     send_graph_messages(io, messages)
     del messages[:]
Exemplo n.º 7
0
def splitline(line,
              re_word=re.compile(
                  forcestr(r'[^\s"]\S*|["]["]|["].*?[^\\]["]'))):
    import ast
    result = []
    for word in re_word.findall(line):
        if word.startswith(b'"'):
            word = ast.literal_eval(forceunicode(word))
        result.append(word)
    return result
Exemplo n.º 8
0
 def test_forcestr_should_not_fail(self):
     garbage = u"\xef\xff\xbb\xbf\xce\xbb\xff\xff"  # garbage
     result = forcestr(garbage)                     # should not raise
Exemplo n.º 9
0
"""
Graph file parsing.
"""
from __future__ import print_function, absolute_import

import sys, re
import subprocess

from dotviewer import msgstruct

from dotviewer.strunicode import forcestr, forceunicode

re_nonword = re.compile(forcestr(r'([^0-9a-zA-Z_.]+)'))
re_plain = re.compile(forcestr(r'graph [-0-9.]+ [-0-9.]+ [-0-9.]+$'),
                      re.MULTILINE)
re_digraph = re.compile(forcestr(r'\b(graph|digraph)\b'), re.IGNORECASE)


def guess_type(content):
    # try to see whether it is a directed graph or not,
    # or already a .plain file
    # XXX not a perfect heursitic
    if re_plain.match(content):
        return 'plain'  # already a .plain file
    # look for the word 'graph' or 'digraph' followed by a '{'.
    bracepos = None
    lastfound = ''
    for match in re_digraph.finditer(content):
        position = match.start()
        if bracepos is None:
            bracepos = content.find(b'{', position)
Exemplo n.º 10
0
def page_messages(page, graph_id):
    from dotviewer import graphparse
    return graphparse.parse_dot(graph_id, forcestr(page.source), page.links,
                                getattr(page, 'fixedfont', False))
Exemplo n.º 11
0
 def test_forcestr_should_not_fail(self):
     garbage = u"\xef\xff\xbb\xbf\xce\xbb\xff\xff"  # garbage
     result = forcestr(garbage)  # should not raise