comparison roundup/xmlrpc.py @ 5395:23b8e6067f7c

Python 3 preparation: update calls to dict methods. Tool-assisted patch. Changes of iterkeys / itervalues / iteritems to keys / values / items are fully automated, but may make things less efficient in Python 2. Automated tools want to add list() around many calls to keys / values / items, but I thought most such list() additions were unnecessary because it seemed the result of keys / values / items was just iterated over while the set of dict keys remained unchanged, rather than used in a way requiring an actual list, or used while the set of keys in the dict could change. It's quite possible I missed some cases where list() was really needed, or left in some unnecessary list() calls. In cases where list() was only needed because the resulting list was then sorted in-place, I changed the code to use calls to sorted().
author Joseph Myers <jsm@polyomino.org.uk>
date Tue, 24 Jul 2018 23:04:42 +0000
parents 0942fe89e82e
children e46ce04d5bbc
comparison
equal deleted inserted replaced
5394:c26d88ec071e 5395:23b8e6067f7c
116 return cl.lookup(key) 116 return cl.lookup(key)
117 117
118 def display(self, designator, *properties): 118 def display(self, designator, *properties):
119 classname, itemid = hyperdb.splitDesignator(designator) 119 classname, itemid = hyperdb.splitDesignator(designator)
120 cl = self.db.getclass(classname) 120 cl = self.db.getclass(classname)
121 props = properties and list(properties) or cl.properties.keys() 121 props = properties and list(properties) or list(cl.properties.keys())
122 props.sort() 122 props.sort()
123 for p in props: 123 for p in props:
124 if not self.db.security.hasPermission('View', self.db.getuid(), 124 if not self.db.security.hasPermission('View', self.db.getuid(),
125 classname, p, itemid): 125 classname, p, itemid):
126 raise Unauthorised('Permission to view %s of %s denied'% 126 raise Unauthorised('Permission to view %s of %s denied'%
163 def set(self, designator, *args): 163 def set(self, designator, *args):
164 164
165 classname, itemid = hyperdb.splitDesignator(designator) 165 classname, itemid = hyperdb.splitDesignator(designator)
166 cl = self.db.getclass(classname) 166 cl = self.db.getclass(classname)
167 props = props_from_args(self.db, cl, args, itemid) # convert types 167 props = props_from_args(self.db, cl, args, itemid) # convert types
168 for p in props.iterkeys(): 168 for p in props.keys():
169 if not self.db.security.hasPermission('Edit', self.db.getuid(), 169 if not self.db.security.hasPermission('Edit', self.db.getuid(),
170 classname, p, itemid): 170 classname, p, itemid):
171 raise Unauthorised('Permission to edit %s of %s denied'% 171 raise Unauthorised('Permission to edit %s of %s denied'%
172 (p, designator)) 172 (p, designator))
173 try: 173 try:

Roundup Issue Tracker: http://roundup-tracker.org/