@@ -198,13 +198,15 @@ def __repr__(self):
198
198
return "frozendict(%s)" % dict .__repr__ (self )
199
199
200
200
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 )
208
210
209
211
210
212
def needs_quotes (s ):
@@ -226,18 +228,19 @@ def needs_quotes(s):
226
228
if s in dot_keywords :
227
229
return False
228
230
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
+
229
235
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 ]:
235
238
if test_re .match (s ):
236
239
return False
237
240
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 ))
241
244
242
245
return True
243
246
0 commit comments