Commit 5558feea authored by Vincent Pelletier's avatar Vincent Pelletier

Add docstrings.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@16171 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6d82a8c0
...@@ -28,6 +28,11 @@ ...@@ -28,6 +28,11 @@
from DateTime import DateTime from DateTime import DateTime
"""
Define the types available in property sheets and a typecasting method for
each.
"""
# By setting ATTRIBUTE_PREFIX to '_', properties become private # By setting ATTRIBUTE_PREFIX to '_', properties become private
# which allows to force users to use accessors only. # which allows to force users to use accessors only.
ATTRIBUTE_PREFIX = '' ATTRIBUTE_PREFIX = ''
...@@ -37,6 +42,9 @@ def identity(value): ...@@ -37,6 +42,9 @@ def identity(value):
return value return value
def asFloat(value): def asFloat(value):
"""
Return the value as a float or a type-specific default value if it fails.
"""
try: try:
result = float(value) result = float(value)
except TypeError: except TypeError:
...@@ -44,6 +52,9 @@ def asFloat(value): ...@@ -44,6 +52,9 @@ def asFloat(value):
return result return result
def asDate(value): def asDate(value):
"""
Return the value as a date or a type-specific default value if it fails.
"""
try: try:
if isinstance(value,DateTime): if isinstance(value,DateTime):
result = value result = value
...@@ -54,6 +65,9 @@ def asDate(value): ...@@ -54,6 +65,9 @@ def asDate(value):
return result return result
def asInt(value): def asInt(value):
"""
Return the value as an int or a type-specific default value if it fails.
"""
try: try:
result = int(value) result = int(value)
except TypeError: except TypeError:
...@@ -61,6 +75,9 @@ def asInt(value): ...@@ -61,6 +75,9 @@ def asInt(value):
return result return result
def asLong(value): def asLong(value):
"""
Return the value as a long or a type-specific default value if it fails.
"""
try: try:
result = long(value) result = long(value)
except TypeError: except TypeError:
...@@ -68,6 +85,9 @@ def asLong(value): ...@@ -68,6 +85,9 @@ def asLong(value):
return result return result
def asString(value): def asString(value):
"""
Return the value as a string or a type-specific default value if it fails.
"""
try: try:
if value is None: if value is None:
result = '' result = ''
...@@ -78,6 +98,9 @@ def asString(value): ...@@ -78,6 +98,9 @@ def asString(value):
return result return result
def asList(value): def asList(value):
"""
Return the value as a list or a type-specific default value if it fails.
"""
if type(value) in (type([]), type(())): if type(value) in (type([]), type(())):
result = list(value) result = list(value)
elif type(value) is type('a'): elif type(value) is type('a'):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment