graph: Use list comprehension for value sanitizing which is ~2x faster
This commit is contained in:
+5
-11
@@ -1,6 +1,6 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#
|
#
|
||||||
# Copyright (C) 2005 - 2007, TUBITAK/UEKAE
|
# Copyright (C) 2005 - 2011, TUBITAK/UEKAE
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
# the terms of the GNU General Public License as published by the Free
|
# the terms of the GNU General Public License as published by the Free
|
||||||
@@ -12,16 +12,12 @@
|
|||||||
# the most simple minded digraph class ever
|
# the most simple minded digraph class ever
|
||||||
|
|
||||||
|
|
||||||
import string
|
|
||||||
|
|
||||||
import pisi
|
import pisi
|
||||||
|
|
||||||
import gettext
|
import gettext
|
||||||
__trans = gettext.translation('pisi', fallback=True)
|
__trans = gettext.translation('pisi', fallback=True)
|
||||||
_ = __trans.ugettext
|
_ = __trans.ugettext
|
||||||
|
|
||||||
# not an error!
|
|
||||||
|
|
||||||
class CycleException(pisi.Exception):
|
class CycleException(pisi.Exception):
|
||||||
def __init__(self, cycle):
|
def __init__(self, cycle):
|
||||||
self.cycle = cycle
|
self.cycle = cycle
|
||||||
@@ -141,12 +137,10 @@ class Digraph(object):
|
|||||||
return list
|
return list
|
||||||
|
|
||||||
def id_str(self, u):
|
def id_str(self, u):
|
||||||
def repl(char):
|
# Graph format only accepts underscores as key values
|
||||||
if char in string.punctuation:
|
# Sanitize the values. This is 2x faster than the old method.
|
||||||
return '_'
|
return ''.join([ch if ch not in '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' \
|
||||||
else:
|
else '_' for ch in u])
|
||||||
return char
|
|
||||||
return pisi.util.flatten_list(map(repl, str(u)))
|
|
||||||
|
|
||||||
def write_graphviz(self, f):
|
def write_graphviz(self, f):
|
||||||
f.write('digraph G {\n')
|
f.write('digraph G {\n')
|
||||||
|
|||||||
Reference in New Issue
Block a user