Skip to content

Commit beb755b

Browse files
author
Jürgen Hermann
committed
typeof() instead of type(): avoid clash with database field(?) "type"
Fixes this traceback: Traceback (most recent call last): File "roundup\cgi_client.py", line 535, in newnode self._post_editnode(nid) File "roundup\cgi_client.py", line 415, in _post_editnode if type(value) != type([]): value = [value] UnboundLocalError: local variable 'type' referenced before assignment
1 parent 8ee4a95 commit beb755b

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

roundup/cgi_client.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: cgi_client.py,v 1.61 2001-11-22 15:46:42 jhermann Exp $
18+
# $Id: cgi_client.py,v 1.62 2001-11-24 00:45:42 jhermann Exp $
1919

2020
__doc__ = """
2121
WWW request handler (also used in the stand-alone server).
2222
"""
2323

2424
import os, cgi, pprint, StringIO, urlparse, re, traceback, mimetypes
25-
import binascii, Cookie, time
25+
import binascii, Cookie, time, __builtin__
2626

2727
import roundupdb, htmltemplate, date, hyperdb, password
2828
from roundup.i18n import _
2929

30+
# avoid clash with database field "type"
31+
typeof = __builtin__.type
32+
3033
class Unauthorised(ValueError):
3134
pass
3235

@@ -152,7 +155,7 @@ def pagefoot(self):
152155
self.write('<dt><b>Form entries</b></dt>')
153156
for k in self.form.keys():
154157
v = self.form.getvalue(k, "<empty>")
155-
if type(v) is type([]):
158+
if typeof(v) is typeof([]):
156159
# Multiple username fields specified
157160
v = "|".join(v)
158161
self.write('<dd><em>%s</em>=%s</dd>'%(k, cgi.escape(v)))
@@ -183,7 +186,7 @@ def index_arg(self, arg):
183186
'''
184187
if self.form.has_key(arg):
185188
arg = self.form[arg]
186-
if type(arg) == type([]):
189+
if typeof(arg) == typeof([]):
187190
return [arg.value for arg in arg]
188191
return arg.value.split(',')
189192
return []
@@ -205,7 +208,7 @@ def index_filterspec(self, filter):
205208
value = self.form[key]
206209
if (isinstance(prop, hyperdb.Link) or
207210
isinstance(prop, hyperdb.Multilink)):
208-
if type(value) == type([]):
211+
if typeof(value) == typeof([]):
209212
value = [arg.value for arg in value]
210213
else:
211214
value = value.value.split(',')
@@ -389,10 +392,10 @@ def showfile(self):
389392
'''
390393
nodeid = self.nodeid
391394
cl = self.db.file
392-
type = cl.get(nodeid, 'type')
393-
if type == 'message/rfc822':
394-
type = 'text/plain'
395-
self.header(headers={'Content-Type': type})
395+
mimetype = cl.get(nodeid, 'type')
396+
if mimetype == 'message/rfc822':
397+
mimetype = 'text/plain'
398+
self.header(headers={'Content-Type': mimetype})
396399
self.write(cl.get(nodeid, 'content'))
397400

398401
def _createnode(self):
@@ -412,7 +415,7 @@ def _post_editnode(self, nid, changes=None):
412415
for key in keys:
413416
if key == ':multilink':
414417
value = self.form[key].value
415-
if type(value) != type([]): value = [value]
418+
if typeof(value) != typeof([]): value = [value]
416419
for value in value:
417420
designator, property = value.split(':')
418421
link, nodeid = roundupdb.splitDesignator(designator)
@@ -422,7 +425,7 @@ def _post_editnode(self, nid, changes=None):
422425
link.set(nodeid, **{property: value})
423426
elif key == ':link':
424427
value = self.form[key].value
425-
if type(value) != type([]): value = [value]
428+
if typeof(value) != typeof([]): value = [value]
426429
for value in value:
427430
designator, property = value.split(':')
428431
link, nodeid = roundupdb.splitDesignator(designator)
@@ -946,7 +949,7 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
946949
key, value, link)
947950
elif isinstance(proptype, hyperdb.Multilink):
948951
value = form[key]
949-
if type(value) != type([]):
952+
if typeof(value) != typeof([]):
950953
value = [i.strip() for i in value.value.split(',')]
951954
else:
952955
value = [i.value.strip() for i in value]
@@ -982,6 +985,9 @@ def parsePropsFromForm(db, cl, form, nodeid=0):
982985

983986
#
984987
# $Log: not supported by cvs2svn $
988+
# Revision 1.61 2001/11/22 15:46:42 jhermann
989+
# Added module docstrings to all modules.
990+
#
985991
# Revision 1.60 2001/11/21 22:57:28 jhermann
986992
# Added dummy hooks for I18N and some preliminary (test) markup of
987993
# translatable messages

0 commit comments

Comments
 (0)