12
12
13
13
log = logging .getLogger (__name__ )
14
14
15
- # This string was created by looking at all unicode code points
16
- # and checking to see if they are considered whitespace
17
- # ('\s') by the re module
18
- whitespace_dict = dict .fromkeys (
19
- "" .join (
20
- [
21
- " \t \n \r \x0b \x0c \x1c \x1d \x1e " ,
22
- "\x1f \x85 \xa0 \u1680 \u2000 \u2001 " ,
23
- "\u2002 \u2003 \u2004 \u2005 \u2006 " ,
24
- "\u2007 \u2008 \u2009 \u200a \u2028 " ,
25
- "\u2029 \u202f \u205f \u3000 " ,
26
- ],
27
- ),
28
- )
29
-
30
-
31
- def is_whitespace (c ):
32
- """Returns true if the character c is whitespace"""
33
- global whitespace_dict
34
- return c in whitespace_dict
35
-
36
15
37
16
class one_space_line :
38
17
"""
@@ -49,7 +28,7 @@ def append_char(self, c):
49
28
Append a character of no particular class to the line.
50
29
Whitespace will be dropped if the line already ends in space.
51
30
"""
52
- if not is_whitespace ( c ):
31
+ if not c . isspace ( ):
53
32
self .parts .append (c )
54
33
self .trailing_space = False
55
34
else :
@@ -354,7 +333,7 @@ def process(self, lineiter):
354
333
else :
355
334
self .outbuf .append_char (char )
356
335
elif self .state [- 1 ] == "CONTINUING_FROM_SOL" :
357
- if is_whitespace ( char ):
336
+ if char . isspace ( ):
358
337
self .outbuf .append_space ()
359
338
elif char == "&" :
360
339
self .state .pop ()
@@ -395,13 +374,13 @@ def process(self, lineiter):
395
374
if char == "!" and self .state [- 2 ] == "TOPLEVEL" :
396
375
self .dir_check (inbuffer )
397
376
break
398
- elif not is_whitespace ( char ):
377
+ elif not char . isspace ( ):
399
378
for tmp in self .verify_continue :
400
379
self .outbuf .append_nonspace (tmp )
401
380
self .verify_continue = []
402
381
self .state .pop ()
403
382
inbuffer .putback (char )
404
- elif is_whitespace ( char ):
383
+ elif char . isspace ( ):
405
384
self .verify_continue .append (char )
406
385
else :
407
386
raise RuntimeError ("Unknown parser state" )
0 commit comments