implement reverse fake-locale

This commit is contained in:
Eric House 2014-04-20 21:36:41 -07:00
parent 5d3beb6404
commit 0bf8b45157

View file

@ -3,28 +3,30 @@
import sys, getopt, re import sys, getopt, re
from lxml import etree from lxml import etree
FMT = re.compile('.*%\d\$[dsXx].*', re.DOTALL)
FMT = re.compile('(%\d\$[dsXx])', re.DOTALL) FMT = re.compile('(%\d\$[dsXx])', re.DOTALL)
def capitalize( str ): def capitalize( str ):
split = re.split( FMT, str ) split = re.split( FMT, str )
for ii in range(len(split)): for ii in range(len(split)):
part = split[ii] if not re.match( FMT, split[ii] ):
if not re.match( FMT, part ):
split[ii] = split[ii].upper() split[ii] = split[ii].upper()
result = ''.join(split) result = ''.join(split)
print str, '=>', result
return result; return result;
def reverse( str ): def reverse( str ):
return str split = re.split( FMT, str )
split.reverse()
for ii in range(len(split)):
if not re.match( FMT, split[ii] ):
split[ii] = split[ii][::-1]
result = ''.join(split)
return result
def usage(): def usage():
print "usage:", sys.argv[0], '-l ca_PS|ba_CK [-o outfile]' print "usage:", sys.argv[0], '-l ca_PS|ba_CK [-o outfile]'
sys.exit(1) sys.exit(1)
def main(): def main():
print 'main'
algo = None algo = None
outfile = None outfile = None
try: try:
@ -33,21 +35,15 @@ def main():
if option == '-l': algo = value if option == '-l': algo = value
elif option == '-o': outfile = value elif option == '-o': outfile = value
else: else:
print 'WTF'
usage() usage()
except: except:
print 'got except'
print "Unexpected error:", sys.exc_info()[0] print "Unexpected error:", sys.exc_info()[0]
usage() usage()
print 'here'
if not algo: if not algo:
print "no algo" print "no algo"
usage() usage()
print 'here 2'
if algo == 'ca_PS': if algo == 'ca_PS':
func = capitalize func = capitalize
elif algo == 'ba_CK': elif algo == 'ba_CK':