29 |
from gnue.common import GDebug |
from gnue.common import GDebug |
30 |
from FormatExceptions import * |
from FormatExceptions import * |
31 |
|
|
32 |
|
# TODO: i18n |
33 |
|
# import locale |
34 |
|
# locale.nl_langinfo( option) |
35 |
|
# |
36 |
|
# Return some locale-specific information as a string. This function is |
37 |
|
# not available on all systems, and the set of possible options might |
38 |
|
# also vary across platforms. The possible argument values are numbers, |
39 |
|
# for which symbolic constants are available in the locale module. |
40 |
|
# |
41 |
|
# DAY_1 ... DAY_7 |
42 |
|
# Return name of the n-th day of the week. |
43 |
|
# |
44 |
|
# ABDAY_1 ... ABDAY_7 |
45 |
|
# Return abbreviated name of the n-th day of the week. |
46 |
|
# |
47 |
|
# MON_1 ... MON_12 |
48 |
|
# Return name of the n-th month. |
49 |
|
# |
50 |
|
# ABMON_1 ... ABMON_12 |
51 |
|
# Return abbreviated name of the n-th month. |
52 |
|
|
53 |
|
|
54 |
# This is a class for a mask literal element |
# This is a class for a mask literal element |
55 |
class Literal: |
class Literal: |
56 |
def __init__(self, literal): |
def __init__(self, literal): |
79 |
def __init__(self, outputMask, inputMask=None, outputMask2=None): |
def __init__(self, outputMask, inputMask=None, outputMask2=None): |
80 |
|
|
81 |
self.outputHandlers = self.parseMask(outputMask) |
self.outputHandlers = self.parseMask(outputMask) |
82 |
|
print "Creating mask handler: %s;%s" % (outputMask,inputMask) |
83 |
|
print self.outputHandlers |
84 |
|
|
85 |
if inputMask != None: |
if inputMask != None: |
86 |
self.inputHandlers = self.parseMask(inputMask) |
self.inputHandlers = self.parseMask(inputMask) |
87 |
if outputMask2 != None: |
if outputMask2 != None: |
119 |
|
|
120 |
|
|
121 |
# Take a mask string and break it into its elements and map it to handlers |
# Take a mask string and break it into its elements and map it to handlers |
122 |
def parseMask(self, mask): |
def parseMask(self, mask, edit=0): |
123 |
GDebug.printMesg(15,'parseMask("%s")' % mask) |
GDebug.printMesg(15,'parseMask("%s")' % mask) |
124 |
maskHandler = [] |
maskHandler = [] |
125 |
|
|
126 |
# Load a predefined mask, if that's what user specified |
# Load a predefined mask, if that's what user specified |
127 |
# TODO: Should predefined masks be pulled from other than gnue.conf? |
# TODO: Should predefined masks be pulled from other than gnue.conf? |
128 |
if len(mask) > 1 and mask[0] == '&': |
if len(mask) > 1 and mask[0] == '&': |
129 |
if mask[1:] == self.basetype: |
for i in range(edit+1): |
130 |
mask = gConfig('%smask' % self.basetype, self.defaultmask) |
edstr = ('edit','')[i] |
131 |
else: |
if mask[1:] == self.basetype: |
132 |
try: |
try: |
133 |
mask = gConfig('%smask_%s' % (self.basetype, mask[1:])) |
mask = gConfig('%s%smask' % (self.basetype, edstr), self.defaultmask) |
134 |
except KeyError: |
except KeyError: |
135 |
raise PredefinedMaskNotFound, \ |
pass |
136 |
_('The requested format mask "%s" is not defined for %s fields') \ |
else: |
137 |
% (mask[1:], self.basetype) |
try: |
138 |
|
mask = gConfig('%smask_%s' % (self.basetype, edstr, mask[1:])) |
139 |
|
except KeyError: |
140 |
|
pass |
141 |
|
if not len(mask): |
142 |
|
raise PredefinedMaskNotFound, \ |
143 |
|
_('The requested format mask "%s" is not defined for %s fields') \ |
144 |
|
% (mask[1:], self.basetype) |
145 |
|
|
146 |
# Process each character in mask at a time |
# Process each character in mask at a time |
147 |
isLiteral = 0 |
isLiteral = 0 |