Skip to content
This repository was archived by the owner on Nov 19, 2018. It is now read-only.

Commit c985db9

Browse files
committed
Revert "Adjusted quoting to DOT lang specification"
This reverts commit 64e3a63.
1 parent 1c30938 commit c985db9

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

pydot_ng/__init__.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,15 @@ def __repr__(self):
198198
return "frozendict(%s)" % dict.__repr__(self)
199199

200200

201-
# cases when no qoutes needed, from http://www.graphviz.org/doc/info/lang.html
202-
dot_keywords = ('graph', 'subgraph', 'digraph', 'node', 'edge', 'strict')
203-
id_alpha_num = re.compile(r'^[_a-zA-Z\200-\377][_a-zA-Z0-9\200-\377]*$',
204-
re.UNICODE)
205-
id_num = re.compile(r'^[-]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)$', re.UNICODE)
206-
id_html = re.compile(r'^<.*>$', re.DOTALL | re.UNICODE)
207-
id_quoted = re.compile(r'^".*"$', re.DOTALL | re.UNICODE)
201+
dot_keywords = ['graph', 'subgraph', 'digraph', 'node', 'edge', 'strict']
202+
203+
id_re_alpha_nums = re.compile('^[_a-zA-Z][a-zA-Z0-9_,]*$', re.UNICODE)
204+
id_re_alpha_nums_with_ports = re.compile(
205+
'^[_a-zA-Z][a-zA-Z0-9_,:\"]*[a-zA-Z0-9_,\"]+$', re.UNICODE)
206+
id_re_num = re.compile('^[0-9,]+$', re.UNICODE)
207+
id_re_with_port = re.compile('^([^:]*):([^:]*)$', re.UNICODE)
208+
id_re_dbl_quoted = re.compile('^\".*\"$', re.S | re.UNICODE)
209+
id_re_html = re.compile('^<.*>$', re.S | re.UNICODE)
208210

209211

210212
def needs_quotes(s):
@@ -226,18 +228,19 @@ def needs_quotes(s):
226228
if s in dot_keywords:
227229
return False
228230

231+
chars = [ord(c) for c in s if ord(c) > 0x7f or ord(c) == 0]
232+
if chars and not id_re_dbl_quoted.match(s) and not id_re_html.match(s):
233+
return True
234+
229235
for test_re in [
230-
id_alpha_num,
231-
id_num,
232-
id_html,
233-
id_quoted,
234-
]:
236+
id_re_alpha_nums, id_re_num, id_re_dbl_quoted,
237+
id_re_html, id_re_alpha_nums_with_ports]:
235238
if test_re.match(s):
236239
return False
237240

238-
chars = [ord(c) for c in s if ord(c) > 0x7f or ord(c) == 0]
239-
if chars and not id_quoted.match(s) and not id_html.match(s):
240-
return True
241+
m = id_re_with_port.match(s)
242+
if m:
243+
return needs_quotes(m.group(1)) or needs_quotes(m.group(2))
241244

242245
return True
243246

0 commit comments

Comments
 (0)