[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/common/src/FormatMasks BaseMask.py DateMas...
From: |
Jason Cater |
Subject: |
gnue/common/src/FormatMasks BaseMask.py DateMas... |
Date: |
Wed, 02 Jan 2002 18:23:05 -0500 |
CVSROOT: /home/cvs
Module name: gnue
Changes by: Jason Cater <address@hidden> 02/01/02 18:23:05
Modified files:
common/src/FormatMasks: BaseMask.py DateMask.py
Log message:
more work on input masks
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/FormatMasks/BaseMask.py.diff?cvsroot=OldCVS&tr1=1.7&tr2=1.8&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/common/src/FormatMasks/DateMask.py.diff?cvsroot=OldCVS&tr1=1.11&tr2=1.12&r1=text&r2=text
Patches:
Index: gnue/common/src/FormatMasks/BaseMask.py
diff -c gnue/common/src/FormatMasks/BaseMask.py:1.7
gnue/common/src/FormatMasks/BaseMask.py:1.8
*** gnue/common/src/FormatMasks/BaseMask.py:1.7 Tue Jan 1 13:31:35 2002
--- gnue/common/src/FormatMasks/BaseMask.py Wed Jan 2 18:23:05 2002
***************
*** 171,178 ****
--- 171,180 ----
def processEdit (self, value, str, pos=0, replaces=0):
+ print "-"*50
GDebug.printMesg(15,'processEdit(%s,%s,%s,%s)' % (value,str,pos,replaces))
nv = value
+ print "%s == %s" % (pos, len(nv))
if pos == len(nv):
nv += str
else:
***************
*** 180,188 ****
GDebug.printMesg(15,"inputMaskPos=%s" % self.inputMaskPos)
section = 0
while section < len(self.inputMaskPos) and \
! self.inputMaskPos[section] < pos:
section += 1
i = pos
while i < len(nv):
--- 182,193 ----
GDebug.printMesg(15,"inputMaskPos=%s" % self.inputMaskPos)
+ print "pos=%s"%pos
+
section = 0
while section < len(self.inputMaskPos) and \
! self.inputMaskPos[section] < pos and \
! self.inputMaskPos[section] > 0:
section += 1
i = pos
while i < len(nv):
Index: gnue/common/src/FormatMasks/DateMask.py
diff -c gnue/common/src/FormatMasks/DateMask.py:1.11
gnue/common/src/FormatMasks/DateMask.py:1.12
*** gnue/common/src/FormatMasks/DateMask.py:1.11 Tue Jan 1 13:31:35 2002
--- gnue/common/src/FormatMasks/DateMask.py Wed Jan 2 18:23:05 2002
***************
*** 6,18 ****
# 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.
#
--- 6,18 ----
# 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.
#
***************
*** 69,75 ****
weekdayAbbrevNames = ['Sun','Mon','Tue','Wed','Thu','Fri','Sat']
-
predefinedDateLiterals = "-./: ,"
--- 69,74 ----
***************
*** 91,113 ****
# TODO: Make DateMask'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)
--- 90,99 ----
# 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)
***************
*** 146,160 ****
print val
! for i in range(len(self.inputHandlers)):
if self.inputMaskLen[i]:
self.lastInputPos = i + self.inputMaskLen[i] - 1
! if (i < len(self.inputMaskLen) - 1):# and not self.inputMaskLen[i+1]:
! rv +=
value[self.inputMaskPos[i]:self.inputMaskPos[i]+self.inputMaskLen[i]]
! if self.inputMaskLen[i] or isinstance(self.inputHandlers[i],Literal):
rv += self.inputHandlers[i].getFormattedValue(val)
! elif len(padding):
! rv += padding * self.inputHandlers[i].maxLength
return rv
--- 132,178 ----
print val
! lastElement = len(self.inputHandlers) - 1
!
! for i in range(lastElement+1):
!
! # Keep track of the last valid position
if self.inputMaskLen[i]:
self.lastInputPos = i + self.inputMaskLen[i] - 1
!
!
! # If this is a "literal" print it as is
! if isinstance(self.inputHandlers[i],Literal):
rv += self.inputHandlers[i].getFormattedValue(val)
! print "#3 %s" % rv
! else:
!
! # If this is the very last (partial) section, add it unformatted
! if self.inputMaskLen[i] and \
! ( (i == lastElement) or \
! ( ( i < lastElement) and self.inputMaskLen[i+1] ) ) :
!
!
! out = value[self.inputMaskPos[i]: \
! self.inputMaskPos[i]+self.inputMaskLen[i]]
!
! rv += out
!
! # Pad any extra space in this section
! if len(padding):
! rv += padding * (self.inputHandlers[i].maxLength - len(out))
!
! print "#1 %s" % rv
!
! # .. or if we have data to output, format it appropriately
! elif self.inputMaskLen[i]:
! rv += self.inputHandlers[i].getFormattedValue(val)
! print "#2a %s" % rv
!
! # .. or if we have no data but are padding, pad appropriately
! elif len(padding):
! rv += padding * self.inputHandlers[i].maxLength
! print "#2b %s" % rv
return rv
***************
*** 176,181 ****
--- 194,205 ----
+
+ #####################################################################
+ #
+ # Mask elements
+ #
+
class _baseDateSection (MaskSection):
def __init__(self):
pass
***************
*** 220,226 ****
def isValidEntry(self, value):
return 0
! def addSelfToDate(self, value, date):
pass
--- 244,250 ----
def isValidEntry(self, value):
return 0
! def addSelfToDate(self, value, date):
pass
***************
*** 271,277 ****
return "%i" % date.day
! class _hSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
--- 295,301 ----
return "%i" % date.day
! class _hSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
***************
*** 298,304 ****
self.minLength = 1
self.maxLength = 2
! def getFormattedValue(self, date):
# TODO: Implement this mask element
return "*" * self.maxLength
--- 322,328 ----
self.minLength = 1
self.maxLength = 2
! def getFormattedValue(self, date):
# TODO: Implement this mask element
return "*" * self.maxLength
***************
*** 315,321 ****
return "*" * self.maxLength
! class _jSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
--- 339,345 ----
return "*" * self.maxLength
! class _jSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
***************
*** 379,385 ****
except ValueError:
return 0
! def addSelfToDate(self, value, date):
date.minute = int(value)
--- 403,409 ----
except ValueError:
return 0
! def addSelfToDate(self, value, date):
date.minute = int(value)
***************
*** 411,417 ****
return "*" * self.maxLength
! class _sSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
--- 435,441 ----
return "*" * self.maxLength
! class _sSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
***************
*** 459,465 ****
return "*" * self.maxLength
! class _vSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
--- 483,489 ----
return "*" * self.maxLength
! class _vSection(_baseDateSection):
def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
***************
*** 483,489 ****
class _wSection(_baseDateSection):
! def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
--- 507,513 ----
class _wSection(_baseDateSection):
! def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
***************
*** 500,506 ****
class _xSection(_baseDateSection):
! def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
--- 524,530 ----
class _xSection(_baseDateSection):
! def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 1
self.maxLength = 2
***************
*** 522,529 ****
return "*" * self.maxLength
! class _ySection(_baseDateSection):
! def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 2
self.maxLength = 2
--- 546,553 ----
return "*" * self.maxLength
! class _ySection(_baseDateSection):
! def __init__(self):
_baseDateSection.__init__(self)
self.minLength = 2
self.maxLength = 2
***************
*** 568,581 ****
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')
! input = dates.createInputHandler('07/16/01')
# val = dates.processEdit(val, '07/1601')
print dates.getFormattedInput(val, "_")
! print dates.getFormattedOutput(val)
! # print "processEdit2 <= %s" %dates.processEdit(val, '27',2,4)
print dates.getFormattedInput(val, "_")
! print dates.getFormattedOutput(val)
--- 592,652 ----
+ #####################################################################
+ #
+ # 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')
! # input = dates.createInputHandler('07/16/01')
# val = dates.processEdit(val, '07/1601')
+ # 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, "_")
!
!
- gnue/common/src/FormatMasks BaseMask.py DateMas...,
Jason Cater <=