Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/encoding.py @ 24593:f473a1fe5c7c
encoding: define an enum that specifies what normcase does to ASCII strings
For C code we don't want to pay the cost of calling into a Python function for
the common case of ASCII filenames. However, while on most POSIX platforms we
normalize filenames by lowercasing them, on Windows we uppercase them. We
define an enum here indicating the direction that filenames should be
normalized as. Some platforms (notably Cygwin) have more complicated
normalization behavior -- we add a case for that too.
In upcoming patches we'll also define a fallback function that is called if the
string has non-ASCII bytes.
This enum will be replicated in the C code to make foldmaps. There's
unfortunately no nice way to avoid that -- we can't have encoding import
parsers because of import cycles. One way might be to have parsers import
encoding, but accessing Python modules from C code is just awkward.
The name 'normcasespecs' was chosen to indicate that this is merely an integer
that specifies a behavior, not a function. The name was pluralized since in
upcoming patches we'll introduce 'normcasespec' which will be one of these
values.
author | Siddharth Agarwal <sid0@fb.com> |
---|---|
date | Wed, 01 Apr 2015 00:21:10 -0700 |
parents | ac08de78de7f |
children | b4258d5a1600 |
comparison
equal
deleted
inserted
replaced
24592:d7cf8102bf09 | 24593:f473a1fe5c7c |
---|---|
352 except UnicodeError: | 352 except UnicodeError: |
353 return s.upper() # we don't know how to fold this except in ASCII | 353 return s.upper() # we don't know how to fold this except in ASCII |
354 except LookupError, k: | 354 except LookupError, k: |
355 raise error.Abort(k, hint="please check your locale settings") | 355 raise error.Abort(k, hint="please check your locale settings") |
356 | 356 |
357 class normcasespecs(object): | |
358 '''what a platform's normcase does to ASCII strings | |
359 | |
360 This is specified per platform, and should be consistent with what normcase | |
361 on that platform actually does. | |
362 | |
363 lower: normcase lowercases ASCII strings | |
364 upper: normcase uppercases ASCII strings | |
365 other: the fallback function should always be called''' | |
366 lower = -1 | |
367 upper = 1 | |
368 other = 0 | |
369 | |
357 _jsonmap = {} | 370 _jsonmap = {} |
358 | 371 |
359 def jsonescape(s): | 372 def jsonescape(s): |
360 '''returns a string suitable for JSON | 373 '''returns a string suitable for JSON |
361 | 374 |