comparison mercurial/util.py @ 6839:01db3e101362

move filename encoding functions from util.py to new store.py
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 24 Jul 2008 16:32:51 +0200
parents c016dc1a8e91
children 11229144aa01
comparison
equal deleted inserted replaced
6838:15ee8066bf5b 6839:01db3e101362
1343 # executable, whoever tries to actually run it will give a 1343 # executable, whoever tries to actually run it will give a
1344 # much more useful error message. 1344 # much more useful error message.
1345 return name 1345 return name
1346 return find_in_path(name, os.environ.get('PATH', ''), default=default) 1346 return find_in_path(name, os.environ.get('PATH', ''), default=default)
1347 1347
1348 def _buildencodefun():
1349 e = '_'
1350 win_reserved = [ord(x) for x in '\\:*?"<>|']
1351 cmap = dict([ (chr(x), chr(x)) for x in xrange(127) ])
1352 for x in (range(32) + range(126, 256) + win_reserved):
1353 cmap[chr(x)] = "~%02x" % x
1354 for x in range(ord("A"), ord("Z")+1) + [ord(e)]:
1355 cmap[chr(x)] = e + chr(x).lower()
1356 dmap = {}
1357 for k, v in cmap.iteritems():
1358 dmap[v] = k
1359 def decode(s):
1360 i = 0
1361 while i < len(s):
1362 for l in xrange(1, 4):
1363 try:
1364 yield dmap[s[i:i+l]]
1365 i += l
1366 break
1367 except KeyError:
1368 pass
1369 else:
1370 raise KeyError
1371 return (lambda s: "".join([cmap[c] for c in s]),
1372 lambda s: "".join(list(decode(s))))
1373
1374 encodefilename, decodefilename = _buildencodefun()
1375
1376 def encodedopener(openerfn, fn):
1377 def o(path, *args, **kw):
1378 return openerfn(fn(path), *args, **kw)
1379 return o
1380
1381 def mktempcopy(name, emptyok=False, createmode=None): 1348 def mktempcopy(name, emptyok=False, createmode=None):
1382 """Create a temporary file with the same contents from name 1349 """Create a temporary file with the same contents from name
1383 1350
1384 The permission bits are copied from the original file. 1351 The permission bits are copied from the original file.
1385 1352