@@ -198,15 +198,13 @@ def __repr__(self):
198
198
return "frozendict(%s)" % dict .__repr__ (self )
199
199
200
200
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 )
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 )
210
208
211
209
212
210
def needs_quotes (s ):
@@ -228,19 +226,18 @@ def needs_quotes(s):
228
226
if s in dot_keywords :
229
227
return False
230
228
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
-
235
229
for test_re in [
236
- id_re_alpha_nums , id_re_num , id_re_dbl_quoted ,
237
- id_re_html , id_re_alpha_nums_with_ports ]:
230
+ id_alpha_num ,
231
+ id_num ,
232
+ id_html ,
233
+ id_quoted ,
234
+ ]:
238
235
if test_re .match (s ):
239
236
return False
240
237
241
- m = id_re_with_port . match ( s )
242
- if m :
243
- return needs_quotes ( m . group ( 1 )) or needs_quotes ( m . group ( 2 ))
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
244
241
245
242
return True
246
243
0 commit comments