Skip to content

Commit e54bec3

Browse files
committed
flake8 changes; move imports before first statements; whitespace
normalization.
1 parent 95cc560 commit e54bec3

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

roundup/xmlrpc.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
from roundup.exceptions import Unauthorised, UsageError
1010
from roundup.date import Date, Range, Interval
1111
from roundup import actions
12+
from roundup.anypy.strings import us2s
13+
from traceback import format_exc
1214
from roundup.anypy import xmlrpc_
1315
SimpleXMLRPCDispatcher = xmlrpc_.server.SimpleXMLRPCDispatcher
1416
Binary = xmlrpc_.client.Binary
15-
from roundup.anypy.strings import us2s
16-
from traceback import format_exc
17+
1718

1819
def translate(value):
1920
"""Translate value to becomes valid for XMLRPC transmission."""
@@ -38,10 +39,10 @@ def props_from_args(db, cl, args, itemid=None):
3839
for arg in args:
3940
if isinstance(arg, Binary):
4041
arg = arg.data
41-
try :
42+
try:
4243
key, value = arg.split('=', 1)
43-
except ValueError :
44-
raise UsageError('argument "%s" not propname=value'%arg)
44+
except ValueError:
45+
raise UsageError('argument "%s" not propname=value' % arg)
4546
key = us2s(key)
4647
value = us2s(value)
4748
if value:
@@ -59,6 +60,7 @@ def props_from_args(db, cl, args, itemid=None):
5960

6061
return props
6162

63+
6264
class RoundupInstance:
6365
"""The RoundupInstance provides the interface accessible through
6466
the Python XMLRPC mapping."""
@@ -73,7 +75,7 @@ def schema(self):
7375
s = {}
7476
for c in self.db.classes:
7577
cls = self.db.classes[c]
76-
props = [(n,repr(v)) for n,v in sorted(cls.properties.items())]
78+
props = [(n, repr(v)) for n, v in sorted(cls.properties.items())]
7779
s[c] = props
7880
return s
7981

@@ -84,7 +86,8 @@ def list(self, classname, propname=None):
8486
result = [cl.get(itemid, propname)
8587
for itemid in cl.list()
8688
if self.db.security.hasPermission('View', self.db.getuid(),
87-
classname, propname, itemid)
89+
classname, propname,
90+
itemid)
8891
]
8992
return result
9093

@@ -93,9 +96,9 @@ def filter(self, classname, search_matches, filterspec,
9396
cl = self.db.getclass(classname)
9497
uid = self.db.getuid()
9598
security = self.db.security
96-
filterspec = security.filterFilterspec (uid, classname, filterspec)
97-
sort = security.filterSortspec (uid, classname, sort)
98-
group = security.filterSortspec (uid, classname, group)
99+
filterspec = security.filterFilterspec(uid, classname, filterspec)
100+
sort = security.filterSortspec(uid, classname, sort)
101+
group = security.filterSortspec(uid, classname, group)
99102
result = cl.filter(search_matches, filterspec, sort=sort, group=group)
100103
check = security.hasPermission
101104
x = [id for id in result if check('View', uid, classname, itemid=id)]
@@ -108,8 +111,8 @@ def lookup(self, classname, key):
108111
search = self.db.security.hasSearchPermission
109112
access = self.db.security.hasPermission
110113
if (not search(uid, classname, prop)
111-
and not access('View', uid, classname, prop)):
112-
raise Unauthorised('Permission to lookup %s denied'%classname)
114+
and not access('View', uid, classname, prop)):
115+
raise Unauthorised('Permission to lookup %s denied' % classname)
113116
return cl.lookup(key)
114117

115118
def display(self, designator, *properties):
@@ -120,15 +123,15 @@ def display(self, designator, *properties):
120123
for p in props:
121124
if not self.db.security.hasPermission('View', self.db.getuid(),
122125
classname, p, itemid):
123-
raise Unauthorised('Permission to view %s of %s denied'%
126+
raise Unauthorised('Permission to view %s of %s denied' %
124127
(p, designator))
125128
result = [(prop, cl.get(itemid, prop)) for prop in props]
126129
return dict(result)
127130

128131
def create(self, classname, *args):
129-
130-
if not self.db.security.hasPermission('Create', self.db.getuid(), classname):
131-
raise Unauthorised('Permission to create %s denied'%classname)
132+
if not self.db.security.hasPermission('Create', self.db.getuid(),
133+
classname):
134+
raise Unauthorised('Permission to create %s denied' % classname)
132135

133136
cl = self.db.getclass(classname)
134137

@@ -138,59 +141,61 @@ def create(self, classname, *args):
138141
# check for the key property
139142
key = cl.getkey()
140143
if key and key not in props:
141-
raise UsageError('you must provide the "%s" property.'%key)
144+
raise UsageError('you must provide the "%s" property.' % key)
142145

143146
for key in props:
144147
if not self.db.security.hasPermission('Create', self.db.getuid(),
145-
classname, property=key):
146-
raise Unauthorised('Permission to create %s.%s denied'%(classname, key))
148+
classname, property=key):
149+
raise Unauthorised('Permission to create %s.%s denied' %
150+
(classname, key))
147151

148152
# do the actual create
149153
try:
150154
result = cl.create(**props)
151155
self.db.commit()
152156
except (TypeError, IndexError, ValueError) as message:
153-
# The exception we get may be a real error, log the traceback if we're debugging
157+
# The exception we get may be a real error, log the traceback
158+
# if we're debugging
154159
logger = logging.getLogger('roundup.xmlrpc')
155160
for l in format_exc().split('\n'):
156161
logger.debug(l)
157-
raise UsageError (message)
162+
raise UsageError(message)
158163
return result
159164

160165
def set(self, designator, *args):
161166

162167
classname, itemid = hyperdb.splitDesignator(designator)
163168
cl = self.db.getclass(classname)
164-
props = props_from_args(self.db, cl, args, itemid) # convert types
169+
props = props_from_args(self.db, cl, args, itemid) # convert types
165170
for p in props.keys():
166171
if not self.db.security.hasPermission('Edit', self.db.getuid(),
167172
classname, p, itemid):
168-
raise Unauthorised('Permission to edit %s of %s denied'%
173+
raise Unauthorised('Permission to edit %s of %s denied' %
169174
(p, designator))
170175
try:
171176
result = cl.set(itemid, **props)
172177
self.db.commit()
173178
except (TypeError, IndexError, ValueError) as message:
174-
# The exception we get may be a real error, log the traceback if we're debugging
179+
# The exception we get may be a real error, log the
180+
# traceback if we're debugging
175181
logger = logging.getLogger('roundup.xmlrpc')
176182
for l in format_exc().split('\n'):
177183
logger.debug(l)
178-
raise UsageError (message)
184+
raise UsageError(message)
179185
return result
180186

181-
182-
builtin_actions = dict (retire = actions.Retire, restore = actions.Restore)
187+
builtin_actions = dict(retire=actions.Retire, restore=actions.Restore)
183188

184189
def action(self, name, *args):
185190
"""Execute a named action."""
186-
191+
187192
if name in self.actions:
188193
action_type = self.actions[name]
189194
elif name in self.builtin_actions:
190195
action_type = self.builtin_actions[name]
191196
else:
192197
raise Exception('action "%s" is not supported %s'
193-
% (name, ','.join(self.actions.keys())))
198+
% (name, ','.join(self.actions.keys())))
194199
action = action_type(self.db, self.translator)
195200
return action.execute(*args)
196201

@@ -204,7 +209,6 @@ def __init__(self, db, actions, translator,
204209
SimpleXMLRPCDispatcher.__init__(self, allow_none, encoding)
205210
self.register_instance(RoundupInstance(db, actions, translator))
206211
self.register_multicall_functions()
207-
208212

209213
def dispatch(self, input):
210214
return self._marshaled_dispatch(input)
@@ -214,4 +218,3 @@ def _dispatch(self, method, params):
214218
retn = SimpleXMLRPCDispatcher._dispatch(self, method, params)
215219
retn = translate(retn)
216220
return retn
217-

0 commit comments

Comments
 (0)