@@ -140,25 +140,33 @@ def resolve(path, posix=True):
140140    return  path 
141141
142142
143- legal_punctuation  =  r"!\#$%&\(\)\+,\-\.;\=@\[\]_\{\}\~" 
144- legal_spaces  =  r" " 
145- legal_chars  =  r'A-Za-z0-9'  +  legal_punctuation 
143+ legal_punctuation  =  r'!\#$%&\(\)\+,\-\.;\=@\[\]_\{\}\~' 
144+ legal_spaces  =  r' ' 
145+ legal_alphanumeric  =  r'A-Za-z0-9' 
146+ legal_chars  =  legal_alphanumeric  +  legal_punctuation 
146147legal_chars_inc_spaces  =  legal_chars  +  legal_spaces 
147148illegal_chars_re  =  r'[^'  +  legal_chars  +  r']' 
148149illegal_chars_exc_spaces_re  =  r'[^'  +  legal_chars_inc_spaces  +  r']' 
149150replace_illegal_chars  =  re .compile (illegal_chars_re ).sub 
150151replace_illegal_chars_exc_spaces  =  re .compile (illegal_chars_exc_spaces_re ).sub 
151152
152153
153- posix_legal_punctuation  =  r"!@#$%^&\*\(\)-_=\+\[\{\]\}\\\|;:'\",<.>\/\?`~"  
154- posix_legal_chars  =  r"A-Za-z0-9"  +  posix_legal_punctuation 
154+ posix_legal_punctuation  =  r'<:"/>\|\*\^\\\'`\?'    +   legal_punctuation 
155+ posix_legal_chars  =  legal_alphanumeric  +  posix_legal_punctuation 
155156posix_legal_chars_inc_spaces  =  posix_legal_chars  +  legal_spaces 
156- posix_illegal_chars_re  =  r"[^"   +  posix_legal_chars  +  r"]"  
157- posix_illegal_chars_exc_spaces_re  =  r"[^"   +  posix_legal_chars_inc_spaces  +  r"]"  
157+ posix_illegal_chars_re  =  r'[^'   +  posix_legal_chars  +  r']'  
158+ posix_illegal_chars_exc_spaces_re  =  r'[^'   +  posix_legal_chars_inc_spaces  +  r']'  
158159replace_illegal_posix_chars  =  re .compile (posix_illegal_chars_re ).sub 
159160replace_illegal_posix_chars_exc_spaces  =  re .compile (posix_illegal_chars_exc_spaces_re ).sub 
160161
161162
163+ ILLEGAL_WINDOWS_NAMES  =  set ([
164+     'com1' , 'com2' , 'com3' , 'com4' , 'com5' , 'com6' , 'com7' , 'com8' , 'com9' ,
165+     'lpt1' , 'lpt2' , 'lpt3' , 'lpt4' , 'lpt5' , 'lpt6' , 'lpt7' , 'lpt8' , 'lpt9' ,
166+     'aux' , 'con' , 'nul' , 'prn' 
167+ ])
168+ 
169+ 
162170def  portable_filename (filename , preserve_spaces = False , posix_only = False ):
163171    """ 
164172    Return a new name for `filename` that is portable across operating systems. 
@@ -197,16 +205,8 @@ def portable_filename(filename, preserve_spaces=False, posix_only=False):
197205            filename  =  replace_illegal_chars ('_' , filename )
198206
199207    if  not  posix_only :
200-         # these are illegal both upper and lowercase and with or without an extension 
201-         # we insert an underscore after the base name. 
202-         windows_illegal_names  =  set ([
203-             'com1' , 'com2' , 'com3' , 'com4' , 'com5' , 'com6' , 'com7' , 'com8' , 'com9' ,
204-             'lpt1' , 'lpt2' , 'lpt3' , 'lpt4' , 'lpt5' , 'lpt6' , 'lpt7' , 'lpt8' , 'lpt9' ,
205-             'aux' , 'con' , 'nul' , 'prn' 
206-         ])
207- 
208208        basename , dot , extension  =  filename .partition ('.' )
209-         if  basename .lower () in  windows_illegal_names :
209+         if  basename .lower () in  ILLEGAL_WINDOWS_NAMES :
210210            filename  =  '' .join ([basename , '_' , dot , extension ])
211211
212212    # no name made only of dots. 
0 commit comments