/[papo]/gnue/common/src/GTypecast.py
ViewVC logotype

Diff of /gnue/common/src/GTypecast.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by charlie, Tue Aug 27 18:15:52 2002 UTC revision 1.4 by styxman, Fri Nov 15 15:32:54 2002 UTC
# Line 16  Line 16 
16  # write to the Free Software Foundation, Inc., 59 Temple Place  # write to the Free Software Foundation, Inc., 59 Temple Place
17  # - Suite 330, Boston, MA 02111-1307, USA.  # - Suite 330, Boston, MA 02111-1307, USA.
18  #  #
19  # Copyright 2000 Free Software Foundation  # Copyright 2000-2002 Free Software Foundation
20  #  #
21  # FILE:  # FILE:
22  # GTypecast.py  # GTypecast.py
23  #  #
24  # DESCRIPTION:  # DESCRIPTION:
25  # Methods used to typecast data  # Methods used to typecast data
# Line 52  def text (value): Line 52  def text (value):
52  #  #
53  # name  # name
54  #  #
55  # This is for typecasting a string that  # This is for typecasting a string that
56  # will be used as a name or identifier  # will be used as a name or identifier
57  # (Characters: A-Z, a-z, 0-9, ['#$_-'])  # (Characters: A-Z, a-z, 0-9, ['#$_-'])
58  #  #
59  #######################################################  #######################################################
60  def name (value):  def name (value):
61    # TODO: name should make sure the string    # TODO: name should make sure the string
62    # TODO: containts only valid characters.    # TODO: containts only valid characters.
63    return string.strip(str(value))    return string.strip(str(value))
64    
65    
66  #######################################################  #######################################################
67  #  #
68    # uppername
69    #
70    # This is for typecasting a string that
71    # will be used as a name or identifier
72    # it will be automaticly converted to uppercase
73    # (Characters: A-Z, a-z, 0-9, ['#$_-'])
74    #
75    #######################################################
76    def uppername (value):
77      # TODO: name should make sure the string
78      # TODO: containts only valid characters.
79      return string.upper(string.strip(str(value)))
80    
81    
82    #######################################################
83    #
84  # names  # names
85  #  #
86  # This is used for typecasting a comma  # This is used for typecasting a comma
87  # separated list of names  # separated list of names
88  #  #
89  #######################################################  #######################################################
90  def names (value):  def names (value):
91    a = string.split(value,',')    a = string.split(value,',')
92    for i in range(0, len(a)):    for i in range(0, len(a)):
93       a[i] = name(a[i])       a[i] = name(a[i])
94    return str(value)    return a
95    
96    
97  #######################################################  #######################################################
# Line 91  def boolean (value): Line 107  def boolean (value):
107    
108    rv = string.strip(value)    rv = string.strip(value)
109    if len(rv):    if len(rv):
110      return not (string.lower(rv) in ('n','f','0'))      return not (rv[0] in ('N','n','F','f','0'))
111    else:    else:
112      # This may seem counter-intuitive, but if attribute was present      # This may seem counter-intuitive, but if attribute was present
113      # without a specified value, then treat as true      # without a specified value, then treat as true
# Line 102  def boolean (value): Line 118  def boolean (value):
118  #  #
119  # number  # number
120  #  #
121  # This is for typecasting numbers (real)  # This is for typecasting numbers (real)
122  #  #
123  #######################################################  #######################################################
124  def number (value):  def number (value):
125    try:    try:
126      return float("%s" % value)        return float("%s" % value)
127    except ValueError:    except ValueError:
128      raise TypecastError      raise TypecastError
129    
130    
131  #######################################################  #######################################################

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26