Mercurial > p > roundup > code
comparison roundup/cgi/client.py @ 1562:b975da59cd11
handle invalid data input in forms better
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Wed, 26 Mar 2003 06:46:17 +0000 |
| parents | 68ef6deefcf1 |
| children | 07a6b8587bc2 |
comparison
equal
deleted
inserted
replaced
| 1561:cf5a5357a7ea | 1562:b975da59cd11 |
|---|---|
| 1 # $Id: client.py,v 1.110 2003-03-26 03:35:00 richard Exp $ | 1 # $Id: client.py,v 1.111 2003-03-26 06:46:17 richard Exp $ |
| 2 | 2 |
| 3 __doc__ = """ | 3 __doc__ = """ |
| 4 WWW request handler (also used in the stand-alone server). | 4 WWW request handler (also used in the stand-alone server). |
| 5 """ | 5 """ |
| 6 | 6 |
| 1730 if not nodeid or nodeid.startswith('-'): | 1730 if not nodeid or nodeid.startswith('-'): |
| 1731 continue | 1731 continue |
| 1732 # other types should be None'd if there's no value | 1732 # other types should be None'd if there's no value |
| 1733 value = None | 1733 value = None |
| 1734 else: | 1734 else: |
| 1735 if isinstance(proptype, hyperdb.String): | 1735 # handle ValueErrors for all these in a similar fashion |
| 1736 if (hasattr(value, 'filename') and | 1736 try: |
| 1737 value.filename is not None): | 1737 if isinstance(proptype, hyperdb.String): |
| 1738 # skip if the upload is empty | 1738 if (hasattr(value, 'filename') and |
| 1739 if not value.filename: | 1739 value.filename is not None): |
| 1740 continue | 1740 # skip if the upload is empty |
| 1741 # this String is actually a _file_ | 1741 if not value.filename: |
| 1742 # try to determine the file content-type | 1742 continue |
| 1743 filename = value.filename.split('\\')[-1] | 1743 # this String is actually a _file_ |
| 1744 if propdef.has_key('name'): | 1744 # try to determine the file content-type |
| 1745 props['name'] = filename | 1745 fn = value.filename.split('\\')[-1] |
| 1746 # use this info as the type/filename properties | 1746 if propdef.has_key('name'): |
| 1747 if propdef.has_key('type'): | 1747 props['name'] = fn |
| 1748 props['type'] = mimetypes.guess_type(filename)[0] | 1748 # use this info as the type/filename properties |
| 1749 if not props['type']: | 1749 if propdef.has_key('type'): |
| 1750 props['type'] = "application/octet-stream" | 1750 props['type'] = mimetypes.guess_type(fn)[0] |
| 1751 # finally, read the content | 1751 if not props['type']: |
| 1752 value = value.value | 1752 props['type'] = "application/octet-stream" |
| 1753 else: | 1753 # finally, read the content |
| 1754 # normal String fix the CRLF/CR -> LF stuff | 1754 value = value.value |
| 1755 value = fixNewlines(value) | 1755 else: |
| 1756 | 1756 # normal String fix the CRLF/CR -> LF stuff |
| 1757 elif isinstance(proptype, hyperdb.Date): | 1757 value = fixNewlines(value) |
| 1758 value = date.Date(value, offset=timezone) | 1758 |
| 1759 elif isinstance(proptype, hyperdb.Interval): | 1759 elif isinstance(proptype, hyperdb.Date): |
| 1760 value = date.Interval(value) | 1760 value = date.Date(value, offset=timezone) |
| 1761 elif isinstance(proptype, hyperdb.Boolean): | 1761 elif isinstance(proptype, hyperdb.Interval): |
| 1762 value = value.lower() in ('yes', 'true', 'on', '1') | 1762 value = date.Interval(value) |
| 1763 elif isinstance(proptype, hyperdb.Number): | 1763 elif isinstance(proptype, hyperdb.Boolean): |
| 1764 value = float(value) | 1764 value = value.lower() in ('yes', 'true', 'on', '1') |
| 1765 elif isinstance(proptype, hyperdb.Number): | |
| 1766 value = float(value) | |
| 1767 except ValueError, msg: | |
| 1768 raise ValueError, _('Error with %s property: %s')%( | |
| 1769 propname, msg) | |
| 1765 | 1770 |
| 1766 # get the old value | 1771 # get the old value |
| 1767 if nodeid and not nodeid.startswith('-'): | 1772 if nodeid and not nodeid.startswith('-'): |
| 1768 try: | 1773 try: |
| 1769 existing = cl.get(nodeid, propname) | 1774 existing = cl.get(nodeid, propname) |
