Added support for case conversion function dispatch table and command validation of such requests.
1 parent e077c87 commit 4ab4291792b9e81f7fe2ca91909f511055747451
@tundra tundra authored on 19 Aug 2010
Showing 1 changed file
View
36
tren.py
PROGNAME = "tren.py"
BASENAME = PROGNAME.split(".py")[0]
PROGENV = BASENAME.upper()
INCLENV = PROGENV + "INCL"
RCSID = "$Id: tren.py,v 1.222 2010/08/19 19:22:04 tundra Exp $"
RCSID = "$Id: tren.py,v 1.223 2010/08/20 01:18:23 tundra Exp $"
VERSION = RCSID.split()[2]
 
# Copyright Information
 
eALPHACMDBAD = "Alphabet specificaton '%s' malformed! Try \"Name:Alphabet\""
eALPHACMDLEN = "Alphabet '%s' too short! Must contain at least 2 symbols."
eARGLENGTH = "%s must contain exactly %s character(s)!"
eBADARG = "Invalid command line: %s!"
eBADCASECONV = "Invalid case conversion argument: %s! Must be one of: %s"
eBADINCL = "option -%s requires argument" % INCL
eBADINSTANCE = "%s is an invalid replacement instance! Must be integer values in the form: n, n:n, :n, n:, or :"
eBADLEN = "Bad line length '%s'!"
eBADNEWOLD = "Bad -r argument '%s'! Requires exactly one new, old string separator (Default: " + DEFSEP + ")"
# Lookup Tables #
#----------------------------------------------------------#
 
 
# Case Conversion
 
 
# Notice use of *unbound* string function methods from the class definition
 
CASETBL = {'c' : str.capitalize,
'l' : str.lower,
's' : str.swapcase,
't' : str.title,
'u' : str.upper
}
 
CASEOPS = CASETBL.keys()
 
 
# Day And Month Conversion Tables
 
 
DAYS = {0:"Mon", 1:"Tue", 2:"Wed", 3:"Thu", 4:"Fri", 5:"Sat", 6:"Sun"}
 
# Force case conversion
if opt == "-e":
pass # Stick validation and storage logic here
 
# Make sure we support the requested case conversion
if val in CASEOPS:
ProgramOptions[CASECONV] = val
 
# Error out if we don't recognize it
else:
ErrorMsg(eBADCASECONV % (val, ", ".join(CASEOPS)))
 
# Force renaming of existing targets
 
if opt == "-f":