tests/filtertmp.py
author Renato Cunha <renatoc@gmail.com>
Tue, 03 Aug 2010 13:41:47 -0300
changeset 11747 40d5633889bb
parent 10469 b26c4a89a143
permissions -rwxr-xr-x
hgfixes: add a fixer to convert plain strings to bytestrings This patch implements a 2to3 fixer that converts all plain strings in a python source file to byte strings syntax. Example: foo = 'Normal string' would become foo = b'Normal string' The motivation behind this fixer can be found in http://selenic.com/pipermail/mercurial-devel/2010-June/022363.html or, in other words: the current hg source assumes that _most_ strings are "meant" to be byte sequences, so it makes sense to make the convertion implemented by this patch. As mentioned above, not all mercurial modules want to use strings as bytes, examples include i18n (which uses unicode), and demandimport (in py3k, module names are normal strings, thus unicode, and there's no need for a convertion). Therefore, these modules are blacklisted in the fixer. There are also a few functions that can take only unicode arguments, thus the convertion shouldn't be done for those.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10468
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     1
#!/usr/bin/env python
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     2
#
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     3
# This used to be a simple sed call like:
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     4
#
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     5
#  $ sed "s:$HGTMP:*HGTMP*:"
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     6
#
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     7
# But $HGTMP has ':' under Windows which breaks the sed call.
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     8
#
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     9
import sys, os
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    10
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    11
input = sys.stdin.read()
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    12
input = input.replace(os.sep, '/')
10469
b26c4a89a143 Fix test-push-validation under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 10468
diff changeset
    13
hgtmp = os.environ['HGTMP'].replace(os.sep, '/')
b26c4a89a143 Fix test-push-validation under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 10468
diff changeset
    14
input = input.replace(hgtmp, '$HGTMP')
10468
2250fc372d34 Fix test-share and test-subrepo under Windows
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    15
sys.stdout.write(input)