##// END OF EJS Templates
store: optimze _auxencode() a bit by grouping the reserved names by length...
Adrian Buehlmann -
r17570:f53a7b25 default
parent child Browse files
Show More
@@ -118,9 +118,9 b' def _buildlowerencodefun():'
118
118
119 lowerencode = _buildlowerencodefun()
119 lowerencode = _buildlowerencodefun()
120
120
121 _winreservednames = '''con prn aux nul
121 # Windows reserved names: con, prn, aux, nul, com1..com9, lpt1..lpt9
122 com1 com2 com3 com4 com5 com6 com7 com8 com9
122 _winres3 = ('aux', 'con', 'prn', 'nul') # length 3
123 lpt1 lpt2 lpt3 lpt4 lpt5 lpt6 lpt7 lpt8 lpt9'''.split()
123 _winres4 = ('com', 'lpt') # length 4 (with trailing 1..9)
124 def _auxencode(path, dotencode):
124 def _auxencode(path, dotencode):
125 '''
125 '''
126 Encodes filenames containing names reserved by Windows or which end in
126 Encodes filenames containing names reserved by Windows or which end in
@@ -144,16 +144,21 b' def _auxencode(path, dotencode):'
144 res = []
144 res = []
145 for n in path.split('/'):
145 for n in path.split('/'):
146 if n:
146 if n:
147 base = n.split('.')[0]
147 if dotencode and n[0] in '. ':
148 if base and (base in _winreservednames):
148 n = "~%02x" % ord(n[0]) + n[1:]
149 # encode third letter ('aux' -> 'au~78')
149 else:
150 ec = "~%02x" % ord(n[2])
150 l = n.find('.')
151 n = n[0:2] + ec + n[3:]
151 if l == -1:
152 l = len(n)
153 if ((l == 3 and n[:3] in _winres3) or
154 (l == 4 and n[3] <= '9' and n[3] >= '1'
155 and n[:3] in _winres4)):
156 # encode third letter ('aux' -> 'au~78')
157 ec = "~%02x" % ord(n[2])
158 n = n[0:2] + ec + n[3:]
152 if n[-1] in '. ':
159 if n[-1] in '. ':
153 # encode last period or space ('foo...' -> 'foo..~2e')
160 # encode last period or space ('foo...' -> 'foo..~2e')
154 n = n[:-1] + "~%02x" % ord(n[-1])
161 n = n[:-1] + "~%02x" % ord(n[-1])
155 if dotencode and n[0] in '. ':
156 n = "~%02x" % ord(n[0]) + n[1:]
157 res.append(n)
162 res.append(n)
158 return '/'.join(res)
163 return '/'.join(res)
159
164
General Comments 0
You need to be logged in to leave comments. Login now