Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c79461b

Browse files
committed
Partial py3k-ification of Doc/library/: convert has_key references into either 'k in d' or __contains__; normalize raise statements; convert print statements into print function calls.
1 parent 2ac0121 commit c79461b

31 files changed

Lines changed: 80 additions & 86 deletions

Doc/library/bsddb.rst

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ Once instantiated, hash, btree and record objects support the same methods as
105105
dictionaries. In addition, they support the methods listed below.
106106

107107

108+
.. describe:: key in bsddbobject
109+
110+
Return ``True`` if the DB file contains the argument as a key.
111+
112+
108113
.. method:: bsddbobject.close()
109114

110115
Close the underlying file. The object can no longer be accessed. Since there
@@ -119,11 +124,6 @@ dictionaries. In addition, they support the methods listed below.
119124
returned is different for different file formats.
120125

121126

122-
.. method:: bsddbobject.has_key(key)
123-
124-
Return ``1`` if the DB file contains the argument as a key.
125-
126-
127127
.. method:: bsddbobject.set_location(key)
128128

129129
Set the cursor to the item indicated by *key* and return a tuple containing the
@@ -169,7 +169,8 @@ Example::
169169

170170
>>> import bsddb
171171
>>> db = bsddb.btopen('/tmp/spam.db', 'c')
172-
>>> for i in range(10): db['%d'%i] = '%d'% (i*i)
172+
>>> for i in range(10):
173+
... db[str(i)] = '%d' % (i*i)
173174
...
174175
>>> db['3']
175176
'9'
@@ -186,7 +187,7 @@ Example::
186187
>>> db.previous()
187188
('1', '1')
188189
>>> for k, v in db.iteritems():
189-
... print k, v
190+
... print(k, v)
190191
0 0
191192
1 1
192193
2 4

Doc/library/cgi.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,19 +91,19 @@ various environment variables set according to the CGI standard). Since it may
9191
consume standard input, it should be instantiated only once.
9292

9393
The :class:`FieldStorage` instance can be indexed like a Python dictionary, and
94-
also supports the standard dictionary methods :meth:`has_key` and :meth:`keys`.
95-
The built-in :func:`len` is also supported. Form fields containing empty
96-
strings are ignored and do not appear in the dictionary; to keep such values,
97-
provide a true value for the optional *keep_blank_values* keyword parameter when
98-
creating the :class:`FieldStorage` instance.
94+
also supports the standard dictionary methods :meth:`__contains__` and
95+
:meth:`keys`. The built-in :func:`len` is also supported. Form fields
96+
containing empty strings are ignored and do not appear in the dictionary; to
97+
keep such values, provide a true value for the optional *keep_blank_values*
98+
keyword parameter when creating the :class:`FieldStorage` instance.
9999

100100
For instance, the following code (which assumes that the
101101
:mailheader:`Content-Type` header and blank line have already been printed)
102102
checks that the fields ``name`` and ``addr`` are both set to a non-empty
103103
string::
104104

105105
form = cgi.FieldStorage()
106-
if not (form.has_key("name") and form.has_key("addr")):
106+
if not ("name" in form and "addr" in form):
107107
print "<H1>Error</H1>"
108108
print "Please fill in the name and addr fields."
109109
return

Doc/library/email.message.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ included in the mapping interface.
200200
No exception is raised if the named field isn't present in the headers.
201201

202202

203-
.. method:: Message.has_key(name)
203+
.. method:: Message.__contains__(name)
204204

205205
Return true if the message contains a header field named *name*, otherwise
206206
return false.

Doc/library/imputil.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ This code is intended to be read, not executed. However, it does work
122122
return m
123123

124124
def determine_parent(globals):
125-
if not globals or not globals.has_key("__name__"):
125+
if not globals or not "__name__" in globals:
126126
return None
127127
pname = globals['__name__']
128-
if globals.has_key("__path__"):
128+
if "__path__" in globals:
129129
parent = sys.modules[pname]
130130
assert globals is parent.__dict__
131131
return parent
@@ -156,7 +156,7 @@ This code is intended to be read, not executed. However, it does work
156156
parent = None
157157
q = import_module(head, qname, parent)
158158
if q: return q, tail
159-
raise ImportError, "No module named " + qname
159+
raise ImportError("No module named " + qname)
160160

161161
def load_tail(q, tail):
162162
m = q
@@ -167,7 +167,7 @@ This code is intended to be read, not executed. However, it does work
167167
mname = "%s.%s" % (m.__name__, head)
168168
m = import_module(head, mname, m)
169169
if not m:
170-
raise ImportError, "No module named " + mname
170+
raise ImportError("No module named " + mname)
171171
return m
172172

173173
def ensure_fromlist(m, fromlist, recursive=0):
@@ -185,7 +185,7 @@ This code is intended to be read, not executed. However, it does work
185185
subname = "%s.%s" % (m.__name__, sub)
186186
submod = import_module(sub, subname, m)
187187
if not submod:
188-
raise ImportError, "No module named " + subname
188+
raise ImportError("No module named " + subname)
189189

190190
def import_module(partname, fqname, parent):
191191
try:

Doc/library/mailbox.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,7 @@ the corresponding message is subsequently removed.
188188
subclass.
189189

190190

191-
.. method:: Mailbox.has_key(key)
192-
Mailbox.__contains__(key)
191+
.. method:: Mailbox.__contains__(key)
193192

194193
Return ``True`` if *key* corresponds to a message, ``False`` otherwise.
195194

Doc/library/rfc822.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ A :class:`Message` instance has the following methods:
260260
:class:`Message` instances also support a limited mapping interface. In
261261
particular: ``m[name]`` is like ``m.getheader(name)`` but raises :exc:`KeyError`
262262
if there is no matching header; and ``len(m)``, ``m.get(name[, default])``,
263-
``m.has_key(name)``, ``m.keys()``, ``m.values()`` ``m.items()``, and
263+
``m.__contains__(name)``, ``m.keys()``, ``m.values()`` ``m.items()``, and
264264
``m.setdefault(name[, default])`` act as expected, with the one difference
265265
that :meth:`setdefault` uses an empty string as the default value.
266266
:class:`Message` instances also support the mapping writable interface ``m[name]

Doc/library/shelve.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ object)::
131131
# such key)
132132
del d[key] # delete data stored at key (raises KeyError
133133
# if no such key)
134-
flag = d.has_key(key) # true if the key exists
134+
flag = key in d # true if the key exists
135135
klist = d.keys() # a list of all existing keys (slow!)
136136

137137
# as d was opened WITHOUT writeback=True, beware:

Doc/library/shutil.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,5 +157,5 @@ provided by this module. ::
157157
except OSError as why:
158158
errors.extend((src, dst, str(why)))
159159
if errors:
160-
raise Error, errors
160+
raise Error(errors)
161161

Doc/library/signal.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ be sent, and the handler raises an exception. ::
144144

145145
def handler(signum, frame):
146146
print 'Signal handler called with signal', signum
147-
raise IOError, "Couldn't open device!"
147+
raise IOError("Couldn't open device!")
148148

149149
# Set the signal handler and a 5-second alarm
150150
signal.signal(signal.SIGALRM, handler)

Doc/library/stat.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,10 @@ Example::
157157
callback(pathname)
158158
else:
159159
# Unknown file type, print a message
160-
print 'Skipping %s' % pathname
160+
print('Skipping %s' % pathname)
161161

162162
def visitfile(file):
163-
print 'visiting', file
163+
print('visiting', file)
164164

165165
if __name__ == '__main__':
166166
walktree(sys.argv[1], visitfile)

0 commit comments

Comments
 (0)