Skip to content

Commit 31b8fb5

Browse files
committed
Applied patch 0038 from issue2550960 to upgrade code examples in
documentation to be compatible with both python 2 and 3. Patch supplied by Joseph Myers.
1 parent b81254d commit 31b8fb5

File tree

6 files changed

+48
-45
lines changed

6 files changed

+48
-45
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ Features:
233233
through the python logger module (using roundup.http). This allows
234234
automatic log rotation. Without it, log file rotation requires restarting
235235
the server. (John Rouillard)
236+
- Part of issue2550960. Applied patch 0038 to upgrade documentation
237+
code examples to support both python 2 and 3. (Joseph Myers)
236238

237239
Fixed:
238240

doc/customizing.txt

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4374,12 +4374,12 @@ the following into ``detectors/anti_spam.py`` in your tracker::
43744374

43754375
def reject_html(db, cl, nodeid, newvalues):
43764376
if newvalues['type'] == 'text/html':
4377-
raise Reject, 'not allowed'
4377+
raise Reject('not allowed')
43784378

43794379
def reject_manylinks(db, cl, nodeid, newvalues):
43804380
content = newvalues['content']
43814381
if content.count('http://') > 2:
4382-
raise Reject, 'not allowed'
4382+
raise Reject('not allowed')
43834383

43844384
def init(db):
43854385
db.file.audit('create', reject_html)
@@ -4389,7 +4389,7 @@ You may also wish to block image attachments if your tracker does not
43894389
need that ability::
43904390

43914391
if newvalues['type'].startswith('image/'):
4392-
raise Reject, 'not allowed'
4392+
raise Reject('not allowed')
43934393

43944394

43954395
Stop "nosy" messages going to people on vacation
@@ -4453,7 +4453,7 @@ vacation". Not very useful, and relatively easy to stop.
44534453
if users.get(nosyid, 'username') == 'anonymous':
44544454
continue
44554455
# make sure they haven't seen the message already
4456-
if not seen_message.has_key(nosyid):
4456+
if nosyid not in seen_message:
44574457
# send it to them
44584458
sendto.append(nosyid)
44594459
recipients.append(nosyid)
@@ -4520,16 +4520,16 @@ move issues. You can do this by following these steps:
45204520
''' Check that the desired transition is valid for the "status"
45214521
property.
45224522
'''
4523-
if not newvalues.has_key('status'):
4523+
if 'status' not in newvalues:
45244524
return
45254525
current = cl.get(nodeid, 'status')
45264526
new = newvalues['status']
45274527
if new == current:
45284528
return
45294529
ok = db.status.get(current, 'transitions')
45304530
if new not in ok:
4531-
raise ValueError, 'Status not allowed to move from "%s" to "%s"'%(
4532-
db.status.get(current, 'name'), db.status.get(new, 'name'))
4531+
raise ValueError('Status not allowed to move from "%s" to "%s"'%(
4532+
db.status.get(current, 'name'), db.status.get(new, 'name')))
45334533

45344534
def init(db):
45354535
db.issue.audit('set', checktransition)
@@ -4623,7 +4623,7 @@ resolved. To achieve this:
46234623

46244624
# don't do anything if there's no blockers or the status hasn't
46254625
# changed
4626-
if not blockers or not newvalues.has_key('status'):
4626+
if not blockers or 'status' not in newvalues:
46274627
return
46284628

46294629
# get the resolved state ID
@@ -4640,7 +4640,7 @@ resolved. To achieve this:
46404640

46414641
# ok, see if we're trying to resolve
46424642
if newvalues['status'] == resolved_id:
4643-
raise ValueError, "This issue can't be resolved until %s resolved."%s
4643+
raise ValueError("This issue can't be resolved until %s resolved."%s)
46444644

46454645

46464646
def resolveblockers(db, cl, nodeid, oldvalues):
@@ -4826,23 +4826,23 @@ This results in the following function::
48264826
ok = ('yes',)
48274827
# old node, get the current values from the node if they haven't
48284828
# changed
4829-
if not newvalues.has_key('nosy'):
4829+
if 'nosy' not in newvalues:
48304830
nosy = cl.get(nodeid, 'nosy')
48314831
for value in nosy:
4832-
if not current.has_key(value):
4832+
if value not in current:
48334833
current[value] = 1
48344834

48354835
# if the nosy list changed in this transaction, init from the new value
4836-
if newvalues.has_key('nosy'):
4836+
if 'nosy' in newvalues:
48374837
nosy = newvalues.get('nosy', [])
48384838
for value in nosy:
48394839
if not db.hasnode('user', value):
48404840
continue
4841-
if not current.has_key(value):
4841+
if value not in current:
48424842
current[value] = 1
48434843

48444844
# add users with keyword in nosy_keywords to the nosy list
4845-
if newvalues.has_key('keyword') and newvalues['keyword'] is not None:
4845+
if 'keyword' in newvalues and newvalues['keyword'] is not None:
48464846
keyword_ids = newvalues['keyword']
48474847
for keyword in keyword_ids:
48484848
# loop over all users,
@@ -4857,7 +4857,7 @@ This results in the following function::
48574857
current[user_id] = 1
48584858

48594859
# that's it, save off the new nosy list
4860-
newvalues['nosy'] = current.keys()
4860+
newvalues['nosy'] = list(current.keys())
48614861

48624862
These two function are the only ones needed in the file.
48634863

@@ -4919,7 +4919,7 @@ directory of your tracker::
49194919
def restrict_nosy_changes(db, cl, nodeid, newvalues):
49204920
'''Do not permit changes to nosy via email.'''
49214921

4922-
if not (newvalues.has_key('nosy')):
4922+
if 'nosy' not in newvalues:
49234923
# the nosy field has not changed so no need to check.
49244924
return
49254925

@@ -4999,14 +4999,14 @@ tracker ``detectors`` directory)::
49994999
''' Ensure the assignedto value in newvalues is used with the
50005000
Fixer Permission
50015001
'''
5002-
if not newvalues.has_key('assignedto'):
5002+
if 'assignedto' not in newvalues:
50035003
# don't care
50045004
return
50055005

50065006
# get the userid
50075007
userid = newvalues['assignedto']
50085008
if not db.security.hasPermission('Fixer', userid, cl.classname):
5009-
raise ValueError, 'You do not have permission to edit %s'%cl.classname
5009+
raise ValueError('You do not have permission to edit %s'%cl.classname)
50105010

50115011
def init(db):
50125012
db.issue.audit('set', assignedtoMustBeFixer)

doc/design.txt

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -980,27 +980,27 @@ proceeds when it has three approvals::
980980
# Permit users only to add themselves to the "approvals" list.
981981

982982
def check_approvals(db, cl, id, newdata):
983-
if newdata.has_key("approvals"):
983+
if "approvals" in newdata:
984984
if cl.get(id, "status") == db.status.lookup("approved"):
985-
raise Reject, "You can't modify the approvals list " \
986-
"for a project that has already been approved."
985+
raise Reject("You can't modify the approvals list "
986+
"for a project that has already been approved.")
987987
old = cl.get(id, "approvals")
988988
new = newdata["approvals"]
989989
for uid in old:
990990
if uid not in new and uid != db.getuid():
991-
raise Reject, "You can't remove other users from " \
992-
"the approvals list; you can only remove " \
993-
"yourself."
991+
raise Reject("You can't remove other users from "
992+
"the approvals list; you can only remove "
993+
"yourself.")
994994
for uid in new:
995995
if uid not in old and uid != db.getuid():
996-
raise Reject, "You can't add other users to the " \
997-
"approvals list; you can only add yourself."
996+
raise Reject("You can't add other users to the "
997+
"approvals list; you can only add yourself.")
998998

999999
# When three people have approved a project, change its status from
10001000
# "pending" to "approved".
10011001

10021002
def approve_project(db, cl, id, olddata):
1003-
if (olddata.has_key("approvals") and
1003+
if ("approvals" in olddata and
10041004
len(cl.get(id, "approvals")) == 3):
10051005
if cl.get(id, "status") == db.status.lookup("pending"):
10061006
cl.set(id, status=db.status.lookup("approved"))
@@ -1021,12 +1021,12 @@ to "applied"::
10211021

10221022
def check_new_patch(db, cl, id, newdata):
10231023
if not newdata["files"]:
1024-
raise Reject, "You can't submit a new patch without " \
1025-
"attaching a patch file."
1024+
raise Reject("You can't submit a new patch without "
1025+
"attaching a patch file.")
10261026
for fileid in newdata["files"]:
10271027
if db.file.get(fileid, "type") != "text/plain":
1028-
raise Reject, "Submitted patch files must be " \
1029-
"text/plain."
1028+
raise Reject("Submitted patch files must be "
1029+
"text/plain.")
10301030

10311031
# When the status is changed from "approved" to "applied", apply the
10321032
# patch.

doc/developers.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,12 +213,12 @@ the following line in the module imports::
213213
Simple translations are automatically marked by calls to builtin
214214
message translation function ``_()``::
215215

216-
print _("This message is translated")
216+
print(_("This message is translated"))
217217

218218
Translations for messages whose grammatical depends on a number
219219
must be done by ``ngettext()`` function::
220220

221-
print ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked)
221+
print(ngettext("Nuked %i file", "Nuked %i files", number_of_files_nuked))
222222

223223
Deferred Translations
224224
~~~~~~~~~~~~~~~~~~~~~
@@ -228,7 +228,7 @@ form [#note_admin.py]_ and must be translated elsewhere.
228228
Example::
229229

230230
for meal in ("spam", "egg", "beacon"):
231-
print _(meal)
231+
print(_(meal))
232232

233233
In such cases, strings must be marked for translation without actual
234234
call to the translating function. To mark these strings, we use Python

doc/upgrading.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ of your tracker::
872872
if op == '-':
873873
affected [i] = 1
874874
break
875-
print ', '.join(sorted(affected.iterkeys()))
875+
print(', '.join(sorted(affected.keys())))
876876

877877
To find out which files where attached before you can look in the
878878
history of the affected issue. For fixing issues you can re-attach the
@@ -923,21 +923,22 @@ directory, it will list for each Class and Property the roles that may
923923
search for this property::
924924

925925
#!/usr/bin/python
926+
from __future__ import print_function
926927
import os
927928
from roundup import instance
928929

929930
tracker = instance.open(os.getcwd ())
930931
db = tracker.open('admin')
931932

932933
for cl in sorted(db.getclasses()):
933-
print "Class:", cl
934+
print("Class:", cl)
934935
for p in sorted(db.getclass(cl).getprops(protected=True).keys()):
935-
print " Property:", p
936+
print(" Property:", p)
936937
roles = []
937-
for role in sorted(db.security.role.iterkeys()):
938+
for role in sorted(db.security.role.keys()):
938939
if db.security.roleHasSearchPermission(cl,p,role):
939940
roles.append(role)
940-
print " roles may search:", ', '.join(roles)
941+
print(" roles may search:", ', '.join(roles))
941942

942943

943944
Migrating from 1.4.x to 1.4.12

doc/xmlrpc.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,13 @@ https, replace xmlrpclib.SafeTransport with xmlrpclib.Transport::
169169
verbose=False,
170170
allow_none=True)
171171

172-
print roundup_server.schema()
173-
print roundup_server.display('user2', 'username')
174-
print roundup_server.display('issue1', 'status')
175-
print roundup_server.filter('user',['1','2','3'],{'username':'demo'})
172+
print(roundup_server.schema())
173+
print(roundup_server.display('user2', 'username'))
174+
print(roundup_server.display('issue1', 'status'))
175+
print(roundup_server.filter('user',['1','2','3'],{'username':'demo'}))
176176

177177
# this will fail with a fault
178178
try:
179-
print roundup_server.filter('usr',['0','2','3'],{'username':'demo'})
179+
print(roundup_server.filter('usr',['0','2','3'],{'username':'demo'}))
180180
except Exception as msg:
181-
print msg
181+
print(msg)

0 commit comments

Comments
 (0)