From 0b3aa924bd0eba199b904fb6637d37d4d05fe1ba Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Tue, 12 Jun 2018 10:19:28 +0000 Subject: [PATCH 38/39] Python 3 preparation: documentation. --- doc/customizing.txt | 36 ++++++++++++++++++------------------ doc/design.txt | 26 +++++++++++++------------- doc/developers.txt | 6 +++--- doc/upgrading.txt | 11 ++++++----- doc/xmlrpc.txt | 12 ++++++------ 5 files changed, 46 insertions(+), 45 deletions(-) diff --git a/doc/customizing.txt b/doc/customizing.txt index a9f9e1a..15a96fb 100644 --- a/doc/customizing.txt +++ b/doc/customizing.txt @@ -4374,12 +4374,12 @@ the following into ``detectors/anti_spam.py`` in your tracker:: def reject_html(db, cl, nodeid, newvalues): if newvalues['type'] == 'text/html': - raise Reject, 'not allowed' + raise Reject('not allowed') def reject_manylinks(db, cl, nodeid, newvalues): content = newvalues['content'] if content.count('http://') > 2: - raise Reject, 'not allowed' + raise Reject('not allowed') def init(db): db.file.audit('create', reject_html) @@ -4389,7 +4389,7 @@ You may also wish to block image attachments if your tracker does not need that ability:: if newvalues['type'].startswith('image/'): - raise Reject, 'not allowed' + raise Reject('not allowed') Stop "nosy" messages going to people on vacation @@ -4453,7 +4453,7 @@ vacation". Not very useful, and relatively easy to stop. if users.get(nosyid, 'username') == 'anonymous': continue # make sure they haven't seen the message already - if not seen_message.has_key(nosyid): + if nosyid not in seen_message: # send it to them sendto.append(nosyid) recipients.append(nosyid) @@ -4520,7 +4520,7 @@ move issues. You can do this by following these steps: ''' Check that the desired transition is valid for the "status" property. ''' - if not newvalues.has_key('status'): + if 'status' not in newvalues: return current = cl.get(nodeid, 'status') new = newvalues['status'] @@ -4528,8 +4528,8 @@ move issues. You can do this by following these steps: return ok = db.status.get(current, 'transitions') if new not in ok: - raise ValueError, 'Status not allowed to move from "%s" to "%s"'%( - db.status.get(current, 'name'), db.status.get(new, 'name')) + raise ValueError('Status not allowed to move from "%s" to "%s"'%( + db.status.get(current, 'name'), db.status.get(new, 'name'))) def init(db): db.issue.audit('set', checktransition) @@ -4623,7 +4623,7 @@ resolved. To achieve this: # don't do anything if there's no blockers or the status hasn't # changed - if not blockers or not newvalues.has_key('status'): + if not blockers or 'status' not in newvalues: return # get the resolved state ID @@ -4640,7 +4640,7 @@ resolved. To achieve this: # ok, see if we're trying to resolve if newvalues['status'] == resolved_id: - raise ValueError, "This issue can't be resolved until %s resolved."%s + raise ValueError("This issue can't be resolved until %s resolved."%s) def resolveblockers(db, cl, nodeid, oldvalues): @@ -4826,23 +4826,23 @@ This results in the following function:: ok = ('yes',) # old node, get the current values from the node if they haven't # changed - if not newvalues.has_key('nosy'): + if 'nosy' not in newvalues: nosy = cl.get(nodeid, 'nosy') for value in nosy: - if not current.has_key(value): + if value not in current: current[value] = 1 # if the nosy list changed in this transaction, init from the new value - if newvalues.has_key('nosy'): + if 'nosy' in newvalues: nosy = newvalues.get('nosy', []) for value in nosy: if not db.hasnode('user', value): continue - if not current.has_key(value): + if value not in current: current[value] = 1 # add users with keyword in nosy_keywords to the nosy list - if newvalues.has_key('keyword') and newvalues['keyword'] is not None: + if 'keyword' in newvalues and newvalues['keyword'] is not None: keyword_ids = newvalues['keyword'] for keyword in keyword_ids: # loop over all users, @@ -4857,7 +4857,7 @@ This results in the following function:: current[user_id] = 1 # that's it, save off the new nosy list - newvalues['nosy'] = current.keys() + newvalues['nosy'] = list(current.keys()) These two function are the only ones needed in the file. @@ -4919,7 +4919,7 @@ directory of your tracker:: def restrict_nosy_changes(db, cl, nodeid, newvalues): '''Do not permit changes to nosy via email.''' - if not (newvalues.has_key('nosy')): + if 'nosy' not in newvalues: # the nosy field has not changed so no need to check. return @@ -4999,14 +4999,14 @@ tracker ``detectors`` directory):: ''' Ensure the assignedto value in newvalues is used with the Fixer Permission ''' - if not newvalues.has_key('assignedto'): + if 'assignedto' not in newvalues: # don't care return # get the userid userid = newvalues['assignedto'] if not db.security.hasPermission('Fixer', userid, cl.classname): - raise ValueError, 'You do not have permission to edit %s'%cl.classname + raise ValueError('You do not have permission to edit %s'%cl.classname) def init(db): db.issue.audit('set', assignedtoMustBeFixer) diff --git a/doc/design.txt b/doc/design.txt index 7d58a7c..8d09d9d 100644 --- a/doc/design.txt +++ b/doc/design.txt @@ -980,27 +980,27 @@ proceeds when it has three approvals:: # Permit users only to add themselves to the "approvals" list. def check_approvals(db, cl, id, newdata): - if newdata.has_key("approvals"): + if "approvals" in newdata: if cl.get(id, "status") == db.status.lookup("approved"): - raise Reject, "You can't modify the approvals list " \ - "for a project that has already been approved." + raise Reject("You can't modify the approvals list " + "for a project that has already been approved.") old = cl.get(id, "approvals") new = newdata["approvals"] for uid in old: if uid not in new and uid != db.getuid(): - raise Reject, "You can't remove other users from " \ - "the approvals list; you can only remove " \ - "yourself." + raise Reject("You can't remove other users from " + "the approvals list; you can only remove " + "yourself.") for uid in new: if uid not in old and uid != db.getuid(): - raise Reject, "You can't add other users to the " \ - "approvals list; you can only add yourself." + raise Reject("You can't add other users to the " + "approvals list; you can only add yourself.") # When three people have approved a project, change its status from # "pending" to "approved". def approve_project(db, cl, id, olddata): - if (olddata.has_key("approvals") and + if ("approvals" in olddata and len(cl.get(id, "approvals")) == 3): if cl.get(id, "status") == db.status.lookup("pending"): cl.set(id, status=db.status.lookup("approved")) @@ -1021,12 +1021,12 @@ to "applied":: def check_new_patch(db, cl, id, newdata): if not newdata["files"]: - raise Reject, "You can't submit a new patch without " \ - "attaching a patch file." + raise Reject("You can't submit a new patch without " + "attaching a patch file.") for fileid in newdata["files"]: if db.file.get(fileid, "type") != "text/plain": - raise Reject, "Submitted patch files must be " \ - "text/plain." + raise Reject("Submitted patch files must be " + "text/plain.") # When the status is changed from "approved" to "applied", apply the # patch. diff --git a/doc/developers.txt b/doc/developers.txt index d5ffe2b..377b9fc 100644 --- a/doc/developers.txt +++ b/doc/developers.txt @@ -213,12 +213,12 @@ the following line in the module imports:: Simple translations are automatically marked by calls to builtin message translation function ``_()``:: - print _("This message is translated") + print(_("This message is translated")) Translations for messages whose grammatical depends on a number must be done by ``ngettext()`` function:: - print ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked) + print(ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked)) Deferred Translations ~~~~~~~~~~~~~~~~~~~~~ @@ -228,7 +228,7 @@ form [#note_admin.py]_ and must be translated elsewhere. Example:: for meal in ("spam", "egg", "beacon"): - print _(meal) + print(_(meal)) In such cases, strings must be marked for translation without actual call to the translating function. To mark these strings, we use Python diff --git a/doc/upgrading.txt b/doc/upgrading.txt index 007814f..fbc1088 100644 --- a/doc/upgrading.txt +++ b/doc/upgrading.txt @@ -872,7 +872,7 @@ of your tracker:: if op == '-': affected [i] = 1 break - print ', '.join(sorted(affected.iterkeys())) + print(', '.join(sorted(affected.keys()))) To find out which files where attached before you can look in the history of the affected issue. For fixing issues you can re-attach the @@ -923,6 +923,7 @@ directory, it will list for each Class and Property the roles that may search for this property:: #!/usr/bin/python + from __future__ import print_function import os from roundup import instance @@ -930,14 +931,14 @@ search for this property:: db = tracker.open('admin') for cl in sorted(db.getclasses()): - print "Class:", cl + print("Class:", cl) for p in sorted(db.getclass(cl).getprops(protected=True).keys()): - print " Property:", p + print(" Property:", p) roles = [] - for role in sorted(db.security.role.iterkeys()): + for role in sorted(db.security.role.keys()): if db.security.roleHasSearchPermission(cl,p,role): roles.append(role) - print " roles may search:", ', '.join(roles) + print(" roles may search:", ', '.join(roles)) Migrating from 1.4.x to 1.4.12 diff --git a/doc/xmlrpc.txt b/doc/xmlrpc.txt index 91323a5..79c33dd 100644 --- a/doc/xmlrpc.txt +++ b/doc/xmlrpc.txt @@ -169,13 +169,13 @@ https, replace xmlrpclib.SafeTransport with xmlrpclib.Transport:: verbose=False, allow_none=True) - print roundup_server.schema() - print roundup_server.display('user2', 'username') - print roundup_server.display('issue1', 'status') - print roundup_server.filter('user',['1','2','3'],{'username':'demo'}) + print(roundup_server.schema()) + print(roundup_server.display('user2', 'username')) + print(roundup_server.display('issue1', 'status')) + print(roundup_server.filter('user',['1','2','3'],{'username':'demo'})) # this will fail with a fault try: - print roundup_server.filter('usr',['0','2','3'],{'username':'demo'}) + print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'})) except Exception as msg: - print msg + print(msg) -- 2.7.4