Author: reinhard
Date: 2007-07-12 12:04:23 -0500 (Thu, 12 Jul 2007)
New Revision: 9757
Removed:
trunk/gnue-common/src/cursing/
trunk/gnue-common/src/datatypes/
trunk/gnue-common/src/external/README.plex
trunk/gnue-common/src/external/plex/
trunk/gnue-common/src/formatting/BaseMask.py
trunk/gnue-common/src/formatting/DateMask.py
trunk/gnue-common/src/formatting/FormatExceptions.py
trunk/gnue-common/src/formatting/NumberMask.py
trunk/gnue-common/src/formatting/TextMask.py
trunk/gnue-common/src/formatting/masks/
Log:
Removed some old stuff. Still available in svn attic if it should be needed
again.
Deleted: trunk/gnue-common/src/external/README.plex
===================================================================
--- trunk/gnue-common/src/external/README.plex 2007-07-12 14:25:21 UTC (rev 9756)
+++ trunk/gnue-common/src/external/README.plex 2007-07-12 17:04:23 UTC (rev 9757)
@@ -1,37 +0,0 @@
-This is version 1.1.4 of Plex, a Python module for building lexical
-analysers. See the doc directory for instructions on using it.
-
-Plex is free of any restrictions. You can use it, redistribute it,
-sell it, whatever you want. All I ask is that you give me credit if
-you distribute any code derived from it.
-
-
-Greg Ewing,
-Computer Science Department,
-University of Canterbury,
-Christchurch,
-New Zealand
-
[email protected]
-
-Version History
----------------
-
-1.1.4 Fixed bug causing argument of Rep or Rep1 to
- fail to match following a newline.
-
-1.1.3 Fixed bug causing Eol to fail to match at the
- beginning of a line in some circumstances.
-
-1.1.2 Changed Scanner.yield() to Scanner.produce() to
- accommodate Python 2.3, where yield is a keyword.
-
- Changed test10 to not rely so much on details of
- string repr.
-
-1.1.1 Fixed two minor bugs: uncommented Scanner.next_char() and
- added import of types to Regexps.py.
-
-1.1 Added support for case-insensitive matches.
-
-1.0 First official release.
Deleted: trunk/gnue-common/src/formatting/BaseMask.py
===================================================================
--- trunk/gnue-common/src/formatting/BaseMask.py 2007-07-12 14:25:21 UTC (rev 9756)
+++ trunk/gnue-common/src/formatting/BaseMask.py 2007-07-12 17:04:23 UTC (rev 9757)
@@ -1,432 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2007 Free Software Foundation
-#
-# FILE:
-# BaseMask.py
-#
-# DESCRIPTION:
-#
-# NOTES:
-#
-
-from gnue.common.apps import GDebug
-from FormatExceptions import *
-
-# TODO: i18n
-# import locale
-# locale.nl_langinfo( option)
-#
-# Return some locale-specific information as a string. This function is
-# not available on all systems, and the set of possible options might
-# also vary across platforms. The possible argument values are numbers,
-# for which symbolic constants are available in the locale module.
-#
-# DAY_1 ... DAY_7
-# Return name of the n-th day of the week.
-#
-# ABDAY_1 ... ABDAY_7
-# Return abbreviated name of the n-th day of the week.
-#
-# MON_1 ... MON_12
-# Return name of the n-th month.
-#
-# ABMON_1 ... ABMON_12
-# Return abbreviated name of the n-th month.
-
-
-# This is a class for a mask literal element
-class Literal:
- def __init__(self, literal):
- self.literal = literal
-
- def getFormattedValue(self, value):
- return self.literal
-
- def isValidEntry(self, value):
- return value == self.literal
-
- def isCompleteEntry(self, value):
- return 0
-
-class BaseMask:
- value = ""
- maskMappings = {}
- inputHandlers = []
- outputHandlers = []
- output2Handlers = []
- predefinedLiterals = ""
- basetype = "base"
- defaultmask = ""
- literalClass = Literal
-
- def __init__(self, outputMask, inputMask=None, outputMask2=None):
-
- self.outputHandlers = self.parseMask(outputMask)
- print "Creating mask handler: %s;%s" % (outputMask,inputMask)
- print self.outputHandlers
-
- if inputMask != None:
- self.inputHandlers = self.parseMask(inputMask)
- if outputMask2 != None:
- self.output2Handlers = self.parseMask(outputMask2)
-
- # Calculate our array lengths once to speed up
- # our code. This should always be equivalent to:
- # len(self.inputHandlers)
- # len(self.inputMaskPos)
- # len(self.inputMaskLen)
- # len(self.inputDisplayLen)
- self.inputCount = len(self.inputHandlers)
-
- self.reset()
-
-
- def reset(self):
-
- # Holds the starting positions of each element section...
- self.inputMaskPos = [0] * self.inputCount
-
- # Holds the length of each element section...
- self.inputMaskLen = [0] * self.inputCount
-
- # Holds the length of each formatted element section...
- self.inputDisplayLen = [0] * self.inputCount
- # .. including padding
- self.inputFormattedLen = [0] * self.inputCount
-
-
- self.index = 0
- self.cursor = 0
- self.display = ""
- self.input = ""
-
-
- # Take a mask string and break it into its elements and map it to handlers
- def parseMask(self, mask, edit=0):
- assert gDebug(7,'parseMask("%s")' % mask)
- maskHandler = []
-
- # Load a predefined mask, if that's what user specified
- # TODO: Should predefined masks be pulled from other than gnue.conf?
- if len(mask) > 1 and mask[0] == '&':
- for i in range(edit+1):
- edstr = ('edit','')[i]
- if mask[1:] == self.basetype:
- try:
- mask = gConfig('%s%smask' % (self.basetype, edstr), self.defaultmask)
- except KeyError:
- pass
- else:
- try:
- mask = gConfig('%smask_%s' % (self.basetype, edstr, mask[1:]))
- except KeyError:
- pass
- if not len(mask):
- tmsg = u_('The requested format mask "%(mask)s" is not defined for '
- '%(type)s fields') \
- % {'mask': mask [1:],
- 'type': self.basetype}
- raise PredefinedMaskNotFound, tmsg
-
- # Process each character in mask at a time
- isLiteral = 0
- for ch in mask:
- if ch == '\\':
- isLiteral = 1
- elif isLiteral or ch in self.predefinedLiterals:
- isLiteral = 0
- maskHandler.append(self.literalClass(ch))
- elif self.maskMappings.has_key(ch):
- maskHandler.append(self.maskMappings[ch])
- else:
- tmsg = u_('Unexpected character "%(char)s" in %(type)s mask.') \
- % {'char': ch,
- 'type': self.basetype}
- raise InvalidCharInMask, tmsg
-
- return maskHandler
-
- # If secondary is true, then use secondary mask (outputMask2)
- def getFormattedOutput(self, secondary=0):
- pass
-
- def getFormattedInput(self):
- pass
-
-
- def setText(self, text):
- self.input = text
- self.display = text
- self.reset()
-
- def isValid(self):
- return 1
-
- # Returns (value, formatted text, cursor)
- def addText(self, value, text, pos, replaces=0, padding="_"):
- shift = 0
- cursor = self.cursor
- for size in self.inputDisplayLen:
- shift -= size
-
- print "Starting cursor: %s; shift: %s" % (cursor, shift)
-
-
- value = self.processEdit(value, text, pos, replaces)
- formatted = self.getFormattedInput(value,padding=padding)
-
- for size in self.inputDisplayLen:
- shift += size
-
- self.cursor = cursor + shift
- self.moveCursorRelative(0)
-
- print "Ending cursor: %s; shift: %s" % (self.cursor, shift)
-
- return (value, formatted, self.cursor)
-
-
-
- # Returns (value, formatted text, cursor)
- def deleteText(self, text, pos, characters):
- pass
-
-
-
- #
- # Given a display cursor, calculate the index into the string
- #
- def cursorToIndex(self, cursor):
- # TODO
- pos = 0
- index = 0
- i = 0
- while ( i < self.inputCount - 1 ) and \
- ( cursor < pos + self.inputDisplayLen[i] ) :
- pos += self.inputDisplayLen[i]
- i += 1
-
-
- diff = cursor - pos - self.inputDisplayLen[i]
- if diff > self.inputMaskLen[i]:
- diff = self.inputMaskLen[i]
-
- return max(self.inputMaskPos[i] + diff,0)
-
-
- #
- # Given an index into the string, calculate the display cursor,
- #
- def indexToCursor(self, index):
-
- i = 0
- while ( i < self.inputCount - 1 ) and \
- ( index < self.inputMaskPos[i] ) :
- i += 1
-
- pos = self.inputMaskPos[i]
-
- diff = index - pos - self.inputMaskLen[i]
-
- # TODO
- return max(pos + diff,0)
-
-
- #
- # Move cursor using relative units
- #
- # If relative > 0, move cursor to the right <relative> units
- # If relative < 0, move cursor to the left |<relative>| units
- # This takes into account Literals, etc.
- #
- def moveCursorRelative(self, relative):
-
- print "*** moveCursorRelative(%s)" % relative
-
- # Direction = -1 (left) or 1 (right).
- direction = relative == 0 or int(relative/abs(relative))
-
- print "relative=%s" % relative
- print "direction=%s" % direction
-
- self.cursor = self.cursor + relative
-
- print "cursor #1: %s" % self.cursor
-
- if self.cursor <= 0:
- self.cursor = 0
- self.direction = 1
- elif self.cursor > len(self.display):
- self.cursor = len(self.display)
- self.direction = -1
-
- print "cursor #2: %s" % self.cursor
-
- pos = 0
- section = 0
- while section < self.inputCount and \
- ((pos + self.inputDisplayLen[section]) < self.cursor):
-
- pos += self.inputDisplayLen[section]
- print "%s; %s" %(section, pos)
- section += 1
-
-
- print "pos=%s" % pos
- print "section=%s" % pos
-
- if pos + self.inputFormattedLen[section] == self.cursor:
- print "cursor #2b: %s" % self.cursor
- section += direction
-
- print "section=%s" % section
-
- if section == self.inputCount:
-# self.cursor = pos + self.inputDisplayLen[-1]
- print "cursor #3: %s" % self.cursor
- section -= 1
-
-
-
- print "section=%s" % section
- if isinstance(self.inputHandlers[section], Literal):
- self.moveCursorRelative(direction)
- print "cursor #4: %s" % self.cursor
-
- self.index = self.cursorToIndex(self.cursor)
-
- print "New cursor position: %s" % self.cursor
-
- return self.cursor
-
-
- #
- # Move cursor to the beginning of the field
- #
- def moveCursorToBegin(self):
-
- # Reset cursor to beginning
- self.cursor = 0
- self.index = 0
-
- # This will handle if the first character is a literal
- # (e.g., for phone numbers (999) 999-9999, this will move
- # to the first '9', not the '('
- return self.moveCursorRelative(0)
-
-
- #
- # Move cursor to the beginning of the field
- #
- def moveCursorToEnd(self):
-
- # Reset cursor to beginning
- self.cursor = self.indexToCursor(self.lastInputPos)
-
- return self.moveCursorRelative(0)
-
-
-
- #
- # Edit the value
- #
- def processEdit (self, value, str, pos=0, replaces=0):
- print "-"*50
- assert gDebug(7,'processEdit(%s,%s,%s,%s)' % (value,str,pos,replaces))
- nv = value
-
- if pos == len(nv):
- nv += str
- else:
- nv = "%s%s%s" % (nv[:pos],str,nv[pos+replaces:])
-
- assert gDebug(7,"inputMaskPos=%s" % self.inputMaskPos)
-
- print "pos=%s"%pos
-
- section = 0
- while section < self.inputCount and \
- self.inputMaskPos[section] < pos and \
- self.inputMaskPos[section] > 0:
- section += 1
- i = pos
-
- # Debug...
- section = 0
- i = 0
-
- while i < len(nv):
- if not self.inputHandlers[section]\
- .isValidEntry(nv[self.inputMaskPos[section]:i+1]):
- if i == self.inputMaskPos[section] and \
- not isinstance(self.inputHandlers[section],Literal):
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
- return nv
- else:
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
- if section == self.inputCount - 1:
- if i != len(nv)-1:
- return nv
- else:
- break
- else:
- section += 1
- self.inputMaskPos[section] = i
- self.inputMaskLen[section] = 0
- else:
- i += 1
-
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
-
- for i in range(section+1, self.inputCount):
- self.inputMaskLen[i] = 0
-
- self.index = pos + len(value)
- self.cursor = self.indexToCursor(self.index)
- print "after processEdit, index=%s;cursor=%s" % (self.index, self.cursor)
-
- assert gDebug(7,"<< %s" % nv)
- return nv
-
-
-
-# This is a base class for mask elements
-class MaskSection:
-
- def __init__(self):
- self.minLength = 0
- self.maxLength = 0
-
- self.intersperse = 0
- self.intersperseString = ","
- self.intersperseRepeat = 1
-
-
- def getFormattedValue(self):
- return self.value
-
- def isValidEntry(self, value):
- return 0
-
- def isCompleteEntry(self, value):
- return len(value) == self.maxLength
-
-
-
Deleted: trunk/gnue-common/src/formatting/DateMask.py
===================================================================
--- trunk/gnue-common/src/formatting/DateMask.py 2007-07-12 14:25:21 UTC (rev 9756)
+++ trunk/gnue-common/src/formatting/DateMask.py 2007-07-12 17:04:23 UTC (rev 9757)
@@ -1,666 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2007 Free Software Foundation
-#
-# FILE:
-# DateMask.py
-#
-# DESCRIPTION:
-#
-# NOTES:
-#
-# \ Next character is a literal
-# a Abbreviated weekday name (Sun..Sat)
-# b Abbreviated month name (Jan..Dec)
-# d day of month (01..31)
-# h hour (01..12)
-# g hour (00..23)
-# j day of year (001..366)
-# m month (01..12)
-# i minute (00..59)
-# p am or pm
-# s second (00..60)
-# u week number of year with Sunday as first day of
-# week (00..53)
-# v week number of year with Monday as first day of
-# week (01..52)
-# y year
-#
-# Predefined literals: "/-.:, "
-#
-# Example:
-#
-# m/d/y 01/23/01
-# m/Y 01/2001
-# h:i p 12:29 pm
-#
-#####################################################################
-
-
-from BaseMask import BaseMask, MaskSection, Literal
-from gnue.common.apps import GDebug
-from gnue.common.utils.GDateTime import GDateTime, InvalidDate
-from FormatExceptions import *
-
-
-# TODO: This is obviously not Internationalized!
-monthNames = ['January','February','March','April','May','June',
- 'July','August','September','October','November','December']
-
-monthAbbrevNames = ['Jan','Feb','Mar','Apr','May','Jun',
- 'Jul','Aug','Sep','Oct','Nov','Dec']
-
-weekdayNames = ['Sunday','Monday','Tuesday','Wednesday',
- 'Thursday','Friday','Saturday']
-
-weekdayAbbrevNames = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
-
-
-predefinedDateLiterals = "-./: ,"
-
-
-class DateLiteral (Literal):
- def addSelfToDate(self, value, date):
- pass
-
- def isValidEntry(self, value):
- return value == self.literal or len(value) == 1 and value in predefinedDateLiterals
-
-
-class DateMask (BaseMask):
- def __init__(self, outputMask, inputMask=None, outputMask2=None):
-
- self.predefinedLiterals = predefinedDateLiterals
-
- self.basetype = "date"
- self.literalClass = DateLiteral
-
- # TODO: Make DateMask's defaultmask be based on locale settings
- self.defaultmask = "m/d/y"
-
- # Reference the module-level mask mappings
- # These should never change from the values created
- # at init time.
- self.maskMappings = maskMappings
-
- BaseMask.__init__(self, outputMask, inputMask, outputMask2)
-
- self.value = GDateTime()
- self.entry = ""
-
-
- def getFormattedOutput(self, value, secondary=0):
- if value in (None,''):
- return ""
-
- rv = ""
- val = self._buildDate(value, 1)
- if secondary:
- handlers = self.output2Handlers
- else:
- handlers = self.outputHandlers
-
- try:
- for m in self.outputHandlers:
- rv += m.getFormattedValue(val)
-
- return rv
- except InvalidDate, msg:
- raise InvalidEntry, msg
-
-
- def getFormattedInput(self, value, padding=""):
-
- assert gDebug(7,'getFormattedInput(%s,%s)' % (value,padding))
- print "**** Formattin dis puppy!"
-
- val = self._buildDate(value, 0)
-
- self.display = ""
- self.lastInputPos = 0
- lastElement = self.inputCount - 1
-
- print o(u_("inputMaskPos=%s") % self.inputMaskLen)
- print o(u_("inputMaskLen=%s") % self.inputMaskLen)
-
-
- for i in range(self.inputCount):
-
- # Keep track of the last valid position
- if self.inputMaskLen[i]:
- self.lastInputPos = i + self.inputMaskLen[i] - 1
-
- piece = ""
- pad = ""
- partial = value[self.inputMaskPos[i]: \
- self.inputMaskPos[i]+self.inputMaskLen[i]]
-
- # If this is a "literal" print it as is
- if isinstance(self.inputHandlers[i],Literal):
- piece = self.inputHandlers[i].getFormattedValue(val)
-
- else:
-
- # If this is the very last (partial) section, add it unformatted
- if self.inputMaskLen[i] and \
- ( (i == lastElement) or \
- ( ( i < lastElement) and \
- not self.inputMaskLen[i+1] and \
- not self.inputHandlers[i].isCompleteEntry(partial)) ) :
-
-
- piece = partial
-
- # Pad any extra space in this section
- if len(padding):
- pad = padding * (self.inputHandlers[i].maxLength - len(piece))
-
- # .. or if we have data to output, format it appropriately
- elif self.inputMaskLen[i]:
- piece = self.inputHandlers[i].getFormattedValue(val)
-
- # .. or if we have no data but are padding, pad appropriately
- elif len(padding):
- pad = padding * self.inputHandlers[i].maxLength
-
- self.inputDisplayLen[i] = len(piece)
- self.inputFormattedLen[i] = len(piece+pad)
- self.display += piece + pad
-
- return self.display
-
-
- def _buildDate(self, value, mustValidate=0):
- date = GDateTime()
-
- for i in range(self.inputCount):
- if (self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal)):
-# if self.inputHandlers[i].isValidEntry(value[ self.inputMaskPos[i]: \
-# self.inputMaskPos[i] + self.inputMaskLen[i]]):
- self.inputHandlers[i].addSelfToDate(
- value[ self.inputMaskPos[i]: \
- self.inputMaskPos[i] + self.inputMaskLen[i]], date )
-# else:
-# raise InvalidEntry, "Invalid Entry"
-
- return date
-
-
-
-
-#####################################################################
-#
-# Mask elements
-#
-#####################################################################
-
-class _baseDateSection (MaskSection):
- def __init__(self):
- pass
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _numberRangeSection (_baseDateSection):
-
- minLength = 0
- maxLength = 0
- valueRange = (0,0)
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= self.valueRange[0] and v <= self.valueRange[1] \
- and len(value) <= self.maxLength) or \
- (v <= self.valueRange[1] and len(value) < self.maxLength)
- except ValueError:
- return 0
-
- def isCompleteEntry(self, value):
- v = int(value)
- return v >= self.valueRange[0] \
- and v <= self.valueRange[1] \
- and (len(value) == self.maxLength or
- v * 10 > self.valueRange[1])
-
-
-
-class _aSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return weekdayAbbrevNames[date.getDayOfWeek()]
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _ASection(_aSection):
- def getFormattedValue(self, date):
- return weekdayNames[date.getDayOfWeek()]
-
-
-class _bSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return monthAbbrevNames[(date.month or 1) - 1]
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _BSection(_bSection):
- def getFormattedValue(self, date):
- return monthNames[(date.month or 1) - 1]
-
-
-class _cSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _dSection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
- self.valueRange = (0,31)
-
- def getFormattedValue(self, date):
- return "%02i" % date.day
-
- def addSelfToDate(self, value, date):
- date.day = int(value or 1)
-
-
-class _DSection(_dSection):
- def getFormattedValue(self, date):
- return "%i" % date.day
-
-
-class _hSection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
- self.valueRange = (0,24)
-
- def getFormattedValue(self, date):
- return "%02i" % date.hour
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- date.hour = int(value or 0)
-
-
-class _HSection(_hSection):
- def getFormattedValue(self, date):
- return "%i" % date.hour
-
-
-class _gSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _GSection(_gSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _jSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _JSection(_jSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _mSection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
- self.valueRange = (1,12)
-
- def getFormattedValue(self, date):
- return "%02i" % date.month
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 12 and len(value) <= 2) or \
- (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.month = int(value or 1)
-
-
-class _MSection(_baseDateSection):
- def getFormattedValue(self, date):
- return "%i" % date.month
-
-
-class _iSection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
- self.valueRange = (0,59)
-
- def getFormattedValue(self, date):
- return "%02i" % date.minute
-
- def addSelfToDate(self, value, date):
- date.minute = int(value)
-
-
-class _ISection(_iSection):
- def getFormattedValue(self, date):
- return "%2i" % date.minute
-
-
-class _pSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return date.hour >= 12 and 'pm' or 'am'
-
- def isValidEntry(self, value):
- return string.upper(string.replace(string.replace(value,' ',''),'.','')) \
- in ('A','AM','P','PM')
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _PSection(_pSection):
- def getFormattedValue(self, date):
- return date.hour >= 12 and 'PM' or 'AM'
-
-
-class _sSection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
- self.valueRange = (0,59)
-
- def getFormattedValue(self, date):
- return "%02i" % date.second
-
- def addSelfToDate(self, value, date):
- date.second = int(value)
-
-
-class _SSection(_sSection):
- def getFormattedValue(self, date):
- return "%2i" % date.second
-
-
-class _uSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _USection(_uSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _vSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _VSection(_vSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _wSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _xSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _XSection(_xSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _ySection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 2
- self.maxLength = 2
- self.valueRange = (0,99)
-
- def getFormattedValue(self, date):
- return "%02i" % divmod(date.year, 100)[1]
-
- def addSelfToDate(self, value, date):
- # TODO: Temporary year hack!
- v = int(value)
- if v >= 50:
- date.year = 1900 + v
- else:
- date.year = 2000 + v
-
-
-class _YSection(_numberRangeSection):
- def __init__(self):
- _numberRangeSection.__init__(self)
- self.minLength = 2
- self.maxLength = 4
- self.valueRange = (0,9999)
-
- def getFormattedValue(self, date):
- return "%04i" % date.year
-
- def addSelfToDate(self, value, date):
- date.year = int(value)
-
-
-
-#####################################################################
-#
-# Mask mappings
-#
-#####################################################################
-
-
-# Map the mask characters to their corresponding classes...
-# Since these can be reused, we will create one instance at
-# the module level... this will add a *little* overhead at
-# module load time, but will save significant time when many
-# masks are used by the app.
-maskMappings = {
- 'a': _aSection(), 'A': _ASection(),
- 'b': _bSection(), 'B': _BSection(),
- 'c': _cSection(), 'd': _dSection(),
- 'D': _DSection(),
- 'h': _hSection(), 'H': _HSection(),
- 'g': _gSection(), 'G': _GSection(),
- 'j': _jSection(), 'J': _JSection(),
- 'm': _mSection(), 'M': _mSection(),
- 'i': _iSection(), 'I': _ISection(),
- 'p': _pSection(), 'P': _PSection(),
- 's': _sSection(), 'S': _SSection(),
- 'u': _uSection(), 'U': _USection(),
- 'v': _vSection(), 'V': _VSection(),
- 'w': _wSection(),
- 'x': _xSection(), 'X': _XSection(),
- 'y': _ySection(), 'Y': _YSection() }
-
-
-
-
-
-#####################################################################
-#
-# Debugging stuff
-#
-#####################################################################
-
-if __name__ == '__main__':
- GDebug.setDebug(20)
- val = ""
- dates = DateMask(r'\D\a\t\e: A, B d, Y \T\i\m\e: h:i:s','m.d.y')
-
-# val = dates.processEdit(val, '07/161',0,0)
-# print "processEdit <= %s" % val
-# print dates.getFormattedInput(val, "_")
-
- val = dates.processEdit(val, '1',0,0)
- print "processEdit <= %s" % val
- print dates.getFormattedInput(val, "_")
-
- val = dates.processEdit(val, '2',1,0)
- print "processEdit <= %s" % val
- print dates.getFormattedInput(val, "_")
-
- val = dates.processEdit(val, '091',1,1)
- print "processEdit <= %s" % val
- print dates.getFormattedInput(val, "_")
-
- val = dates.processEdit(val, '',1,1)
- print "processEdit <= %s" % val
- print dates.getFormattedInput(val, "_")
-
-
Deleted: trunk/gnue-common/src/formatting/FormatExceptions.py
===================================================================
--- trunk/gnue-common/src/formatting/FormatExceptions.py 2007-07-12 14:25:21 UTC (rev 9756)
+++ trunk/gnue-common/src/formatting/FormatExceptions.py 2007-07-12 17:04:23 UTC (rev 9757)
@@ -1,53 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2007 Free Software Foundation
-#
-# FILE:
-# BaseMask.py
-#
-# DESCRIPTION:
-#
-# NOTES:
-#
-
-from gnue.common.apps import errors
-
-# Base Exception for markup problems with mask
-class MaskMarkupError (errors.ApplicationError):
- pass
-
-# Developer specified a predefined mask (using "&name" notation)
-# that does not exist
-class PredefinedMaskNotFound (MaskMarkupError):
- pass
-
-# The supplied mask includes a token that is not recognized
-class InvalidCharInMask (MaskMarkupError):
- pass
-
-
-# Base exception for user/data input problems
-class MaskInputError (errors.UserError):
- pass
-
-# The supplied input from user is invalid
-class InvalidEntry(MaskInputError):
- pass
-
-
Deleted: trunk/gnue-common/src/formatting/NumberMask.py
===================================================================
--- trunk/gnue-common/src/formatting/NumberMask.py 2007-07-12 14:25:21 UTC (rev 9756)
+++ trunk/gnue-common/src/formatting/NumberMask.py 2007-07-12 17:04:23 UTC (rev 9757)
@@ -1,600 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2007 Free Software Foundation
-#
-# FILE:
-# NumberMask.py
-#
-# DESCRIPTION:
-#
-# NOTES:
-#
-# \ Next character is a literal
-# a Abbreviated weekday name (Sun..Sat)
-# b Abbreviated month name (Jan..Dec)
-# d day of month (01..31)
-# h hour (01..12)
-# g hour (00..23)
-# j day of year (001..366)
-# m month (01..12)
-# i minute (00..59)
-# p am or pm
-# s second (00..60)
-# u week number of year with Sunday as first day of
-# week (00..53)
-# v week number of year with Monday as first day of
-# week (01..52)
-# y year
-#
-# Predefined literals: "/-.:, "
-#
-# Example:
-#
-# m/d/y 01/01/2001
-# m/y 01/2001
-# h:i p 12:29 pm
-#
-
-from BaseMask import BaseMask, MaskSection, Literal
-from gnue.common.utils.GDateTime import GDateTime, InvalidDate
-from FormatExceptions import *
-
-class DateLiteral (Literal):
- def addSelfToDate(self, value, date):
- pass
-
- def isValidEntry(self, value):
- return value == self.literal or value in predefinedDateLiterals
-
-class NumberMask (BaseMask):
- def __init__(self, outputMask, inputMask=None, outputMask2=None):
-
- self.predefinedLiterals = predefinedDateLiterals
-
- self.basetype = "date"
- self.literalClass = DateLiteral
-
- # TODO: Make NumberMask's defaultmask be based on locale settings
- self.defaultmask = "m/d/y"
-
- self.maskMappings = {
- 'a': _aSection, 'A': _ASection,
- 'b': _bSection, 'B': _BSection,
- 'c': _cSection, 'd': _dSection,
- 'D': _DSection, 'h': _hSection,
- 'H': _HSection,
- 'g': _gSection, 'G': _GSection,
- 'j': _jSection, 'J': _JSection,
- 'm': _mSection, 'M': _mSection,
- 'i': _iSection, 'I': _ISection,
- 'p': _pSection, 'P': _PSection,
- 's': _sSection, 'S': _SSection,
- 'u': _uSection, 'U': _USection,
- 'v': _vSection, 'V': _VSection,
- 'w': _wSection,
- 'x': _xSection, 'X': _XSection,
- 'y': _ySection, 'Y': _YSection }
-
- BaseMask.__init__(self, outputMask, inputMask, outputMask2)
-
- self.value = GDateTime()
- self.entry = ""
- self.inputMaskPos = []
- self.inputMaskLen = []
- for i in range(len(self.inputHandlers)):
- self.inputMaskPos.append(0)
- self.inputMaskLen.append(0)
-
-
- def processEdit (self, str, pos=0, replaces=0):
- nv = self.entry
- if pos == len(nv):
- nv += str
- else:
- nv = "%s%s%s" % (nv[:pos],str,nv[pos+replaces:])
-
- section = 0
- while section < len(self.inputMaskPos) and \
- self.inputMaskPos[section] < pos:
- section += 1
-
- i = pos
- while i < len(nv):
- if not self.inputHandlers[section]\
- .isValidEntry(nv[self.inputMaskPos[section]:i+1]):
- if i == self.inputMaskPos[section] and \
- not isinstance(self.inputHandlers[section],Literal):
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
- return 1
- else:
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
- if section == len(self.inputHandlers) - 1:
- if i != len(nv)-1:
- return 1
- else:
- section += 1
- self.inputMaskPos[section] = i
- self.inputMaskLen[section] = 0
- else:
- i += 1
-
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
-
- for i in range(section+1, len(self.inputHandlers)):
- self.inputMaskLen[i] = 0
-
-
- self.entry = nv
- return 1
-
-
- def getFormattedOutput(self, secondary=0):
- rv = ""
- value = self._buildDate(self.entry, 1)
- if secondary:
- handlers = self.output2Handlers
- else:
- handlers = self.outputHandlers
-
- try:
- for m in self.outputHandlers:
- rv += m.getFormattedValue(value)
-
- return rv
- except InvalidDate, msg:
- raise InvalidEntry, msg
-
-
- def getFormattedDisplay(self):
- rv = ""
- value = self._buildDate(self.entry, 1)
-
- try:
- for m in self.outputHandlers:
- rv += m.getFormattedValue(value)
-
- return rv
- except InvalidDate, msg:
- raise InvalidEntry, msg
-
-
- def getFormattedInput(self, padding=""):
- rv = ""
- value = self._buildDate(self.entry, 0)
-
-# self.lastInputPos =
-
- print self.inputMaskLen
-
- for i in range(len(self.inputHandlers)):
- if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
- rv += self.inputHandlers[i].getFormattedValue(value)
- elif len(padding):
- rv += padding * self.inputHandlers[i].maxLength
-
- return rv
-
-
- def _buildDate(self, value, mustValidate=0):
- date = GDateTime()
-
- for i in range(len(self.inputHandlers)):
- if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
- self.inputHandlers[i].addSelfToDate(
- value[ self.inputMaskPos[i]: \
- self.inputMaskPos[i] + self.inputMaskLen[i]], date )
- elif mustValidate:
- raise InvalidEntry, u_("Invalid Entry")
-
- return date
-
-
-
-class _baseDateSection (MaskSection):
- def __init__(self):
- pass
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _aSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return weekdayAbbrevNames[date.getDayOfWeek()]
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _ASection(_aSection):
- def getFormattedValue(self, date):
- return weekdayNames[date.getDayOfWeek()]
-
-
-class _bSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return monthAbbrevNames[(date.month or 1) - 1]
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _BSection(_bSection):
- def getFormattedValue(self, date):
- return monthNames[(date.month or 1) - 1]
-
-
-class _cSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _dSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.day
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 31) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.day = int(value or 1)
-
-
-class _DSection(_dSection):
- def getFormattedValue(self, date):
- return "%i" % date.day
-
-
-class _hSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.hour
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- date.hour = int(value or 0)
-
-
-class _HSection(_hSection):
- def getFormattedValue(self, date):
- return "%i" % date.hour
-
-
-class _gSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _GSection(_gSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _jSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _JSection(_jSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _mSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.month
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 12) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.month = int(value or 1)
-
-
-class _MSection(_baseDateSection):
- def getFormattedValue(self, date):
- return "%i" % date.month
-
-
-class _iSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.minute
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.minute = int(value)
-
-
-class _ISection(_iSection):
- def getFormattedValue(self, date):
- return "%2i" % date.minute
-
-
-class _pSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _PSection(_pSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _sSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.second
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.second = int(value)
-
-
-class _SSection(_sSection):
- def getFormattedValue(self, date):
- return "%2i" % date.second
-
-
-class _uSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _USection(_uSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _vSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _VSection(_vSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _wSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _xSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _XSection(_xSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _ySection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 2
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % divmod(date.year, 100)[1]
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0) and (v <= 99)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- # TODO: Temporary year hack!
- v = int(value)
- if v >= 50:
- date.year = 1900 + v
- else:
- date.year = 2000 + v
-
-
-class _YSection(_ySection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 2
- self.maxLength = 4
-
- def getFormattedValue(self, date):
- return "%04i" % date.year
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 1) and (v <= 9999)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.year = int(value)
-
-
-
Deleted: trunk/gnue-common/src/formatting/TextMask.py
===================================================================
--- trunk/gnue-common/src/formatting/TextMask.py 2007-07-12 14:25:21 UTC (rev 9756)
+++ trunk/gnue-common/src/formatting/TextMask.py 2007-07-12 17:04:23 UTC (rev 9757)
@@ -1,590 +0,0 @@
-#
-# This file is part of GNU Enterprise.
-#
-# GNU Enterprise is free software; you can redistribute it
-# and/or modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2, or (at your option) any later version.
-#
-# GNU Enterprise is distributed in the hope that it will be
-# useful, but WITHOUT ANY WARRANTY; without even the implied
-# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-# PURPOSE. See the GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with program; see the file COPYING. If not,
-# write to the Free Software Foundation, Inc., 59 Temple Place
-# - Suite 330, Boston, MA 02111-1307, USA.
-#
-# Copyright 2001-2007 Free Software Foundation
-#
-# FILE:
-# TextMask.py
-#
-# DESCRIPTION:
-#
-# NOTES:
-#
-# Global Directives
-# {proper} Display all text in Proper case
-# {upper} Display all text in Upper case
-# {lower} Display all text in Lower case
-#
-# Predefined literals: " "
-#
-#
-# Example:
-#
-# m/d/y 01/01/2001
-# m/y 01/2001
-# h:i p 12:29 pm
-#
-
-from BaseMask import BaseMask, MaskSection, Literal
-from gnue.common.utils.GDateTime import GDateTime, InvalidDate
-from FormatExceptions import *
-
-class DateLiteral (Literal):
- def addSelfToDate(self, value, date):
- pass
-
- def isValidEntry(self, value):
- return value == self.literal or value in predefinedDateLiterals
-
-class TextMask (BaseMask):
- def __init__(self, outputMask, inputMask=None, outputMask2=None):
-
- self.predefinedLiterals = predefinedDateLiterals
-
- self.basetype = "date"
- self.literalClass = DateLiteral
-
- # TODO: Make TextMask's defaultmask be based on locale settings
- self.defaultmask = "m/d/y"
-
- self.maskMappings = {
- 'a': _aSection, 'A': _ASection,
- 'b': _bSection, 'B': _BSection,
- 'c': _cSection, 'd': _dSection,
- 'D': _DSection, 'h': _hSection,
- 'H': _HSection,
- 'g': _gSection, 'G': _GSection,
- 'j': _jSection, 'J': _JSection,
- 'm': _mSection, 'M': _mSection,
- 'i': _iSection, 'I': _ISection,
- 'p': _pSection, 'P': _PSection,
- 's': _sSection, 'S': _SSection,
- 'u': _uSection, 'U': _USection,
- 'v': _vSection, 'V': _VSection,
- 'w': _wSection,
- 'x': _xSection, 'X': _XSection,
- 'y': _ySection, 'Y': _YSection }
-
- BaseMask.__init__(self, outputMask, inputMask, outputMask2)
-
- self.value = GDateTime()
- self.entry = ""
- self.inputMaskPos = []
- self.inputMaskLen = []
- for i in range(len(self.inputHandlers)):
- self.inputMaskPos.append(0)
- self.inputMaskLen.append(0)
-
-
- def processEdit (self, str, pos=0, replaces=0):
- nv = self.entry
- if pos == len(nv):
- nv += str
- else:
- nv = "%s%s%s" % (nv[:pos],str,nv[pos+replaces:])
-
- section = 0
- while section < len(self.inputMaskPos) and \
- self.inputMaskPos[section] < pos:
- section += 1
-
- i = pos
- while i < len(nv):
- if not self.inputHandlers[section]\
- .isValidEntry(nv[self.inputMaskPos[section]:i+1]):
- if i == self.inputMaskPos[section] and \
- not isinstance(self.inputHandlers[section],Literal):
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
- return 1
- else:
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
- if section == len(self.inputHandlers) - 1:
- if i != len(nv)-1:
- return 1
- else:
- section += 1
- self.inputMaskPos[section] = i
- self.inputMaskLen[section] = 0
- else:
- i += 1
-
- self.inputMaskLen[section] = i - self.inputMaskPos[section]
-
- for i in range(section+1, len(self.inputHandlers)):
- self.inputMaskLen[i] = 0
-
-
- self.entry = nv
- return 1
-
-
- def getFormattedOutput(self, secondary=0):
- rv = ""
- value = self._buildDate(self.entry, 1)
- if secondary:
- handlers = self.output2Handlers
- else:
- handlers = self.outputHandlers
-
- try:
- for m in self.outputHandlers:
- rv += m.getFormattedValue(value)
-
- return rv
- except InvalidDate, msg:
- raise InvalidEntry, msg
-
-
- def getFormattedDisplay(self):
- rv = ""
- value = self._buildDate(self.entry, 1)
-
- try:
- for m in self.outputHandlers:
- rv += m.getFormattedValue(value)
-
- return rv
- except InvalidDate, msg:
- raise InvalidEntry, msg
-
-
- def getFormattedInput(self, padding=""):
- rv = ""
- value = self._buildDate(self.entry, 0)
-
-# self.lastInputPos =
-
- print self.inputMaskLen
-
- for i in range(len(self.inputHandlers)):
- if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
- rv += self.inputHandlers[i].getFormattedValue(value)
- elif len(padding):
- rv += padding * self.inputHandlers[i].maxLength
-
- return rv
-
-
- def _buildDate(self, value, mustValidate=0):
- date = GDateTime()
-
- for i in range(len(self.inputHandlers)):
- if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
- self.inputHandlers[i].addSelfToDate(
- value[ self.inputMaskPos[i]: \
- self.inputMaskPos[i] + self.inputMaskLen[i]], date )
- elif mustValidate:
- raise InvalidEntry, u_("Invalid Entry")
-
- return date
-
-
-
-class _baseDateSection (MaskSection):
- def __init__(self):
- pass
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _aSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return weekdayAbbrevNames[date.getDayOfWeek()]
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _ASection(_aSection):
- def getFormattedValue(self, date):
- return weekdayNames[date.getDayOfWeek()]
-
-
-class _bSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return monthAbbrevNames[(date.month or 1) - 1]
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _BSection(_bSection):
- def getFormattedValue(self, date):
- return monthNames[(date.month or 1) - 1]
-
-
-class _cSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _dSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.day
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 31) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.day = int(value or 1)
-
-
-class _DSection(_dSection):
- def getFormattedValue(self, date):
- return "%i" % date.day
-
-
-class _hSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.hour
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- date.hour = int(value or 0)
-
-
-class _HSection(_hSection):
- def getFormattedValue(self, date):
- return "%i" % date.hour
-
-
-class _gSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _GSection(_gSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _jSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _JSection(_jSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _mSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.month
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 12) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.month = int(value or 1)
-
-
-class _MSection(_baseDateSection):
- def getFormattedValue(self, date):
- return "%i" % date.month
-
-
-class _iSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.minute
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.minute = int(value)
-
-
-class _ISection(_iSection):
- def getFormattedValue(self, date):
- return "%2i" % date.minute
-
-
-class _pSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _PSection(_pSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _sSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % date.second
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0 and v <= 59) or (v == 0 and len(value) == 1)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.second = int(value)
-
-
-class _SSection(_sSection):
- def getFormattedValue(self, date):
- return "%2i" % date.second
-
-
-class _uSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _USection(_uSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _vSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _VSection(_vSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _wSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _xSection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 1
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
- def isValidEntry(self, value):
- return 0
-
- def addSelfToDate(self, value, date):
- pass
-
-
-class _XSection(_xSection):
- def getFormattedValue(self, date):
- # TODO: Implement this mask element
- return "*" * self.maxLength
-
-
-class _ySection(_baseDateSection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 2
- self.maxLength = 2
-
- def getFormattedValue(self, date):
- return "%02i" % divmod(date.year, 100)[1]
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 0) and (v <= 99)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- # TODO: Temporary year hack!
- v = int(value)
- if v >= 50:
- date.year = 1900 + v
- else:
- date.year = 2000 + v
-
-
-class _YSection(_ySection):
- def __init__(self):
- _baseDateSection.__init__(self)
- self.minLength = 2
- self.maxLength = 4
-
- def getFormattedValue(self, date):
- return "%04i" % date.year
-
- def isValidEntry(self, value):
- try:
- v = int(value)
- return (v >= 1) and (v <= 9999)
- except ValueError:
- return 0
-
- def addSelfToDate(self, value, date):
- date.year = int(value)
-
-
-
-
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.