Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
1625d887
Commit
1625d887
authored
Oct 30, 2012
by
Andrew Svetlov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16341: convert examples to use except ... as ... syntax.
parent
5c89c19e
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
21 additions
and
22 deletions
+21
-22
Doc/howto/urllib2.rst
Doc/howto/urllib2.rst
+5
-5
Doc/includes/email-unpack.py
Doc/includes/email-unpack.py
+1
-1
Doc/includes/sqlite3/complete_statement.py
Doc/includes/sqlite3/complete_statement.py
+1
-1
Doc/library/csv.rst
Doc/library/csv.rst
+1
-1
Doc/library/getopt.rst
Doc/library/getopt.rst
+1
-1
Doc/library/shutil.rst
Doc/library/shutil.rst
+3
-3
Doc/library/socket.rst
Doc/library/socket.rst
+4
-4
Doc/library/ssl.rst
Doc/library/ssl.rst
+1
-1
Doc/library/xdrlib.rst
Doc/library/xdrlib.rst
+1
-2
Doc/library/xmlrpclib.rst
Doc/library/xmlrpclib.rst
+3
-3
No files found.
Doc/howto/urllib2.rst
View file @
1625d887
...
...
@@ -201,7 +201,7 @@ e.g. ::
>>> req = urllib2.Request('http://www.pretend_server.org')
>>> try: urllib2.urlopen(req)
... except URLError
,
e:
... except URLError
as
e:
... print e.reason #doctest: +SKIP
...
(4, 'getaddrinfo failed')
...
...
@@ -310,7 +310,7 @@ geturl, and info, methods. ::
>>> req = urllib2.Request('http://www.python.org/fish.html')
>>> try:
... urllib2.urlopen(req)
... except urllib2.HTTPError
,
e:
... except urllib2.HTTPError
as
e:
... print e.code
... print e.read() #doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
...
...
...
@@ -338,10 +338,10 @@ Number 1
req = Request(someurl)
try:
response = urlopen(req)
except HTTPError
,
e:
except HTTPError
as
e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
except URLError
,
e:
except URLError
as
e:
print 'We failed to reach a server.'
print 'Reason: ', e.reason
else:
...
...
@@ -362,7 +362,7 @@ Number 2
req = Request(someurl)
try:
response = urlopen(req)
except URLError
,
e:
except URLError
as
e:
if hasattr(e, 'reason'):
print 'We failed to reach a server.'
print 'Reason: ', e.reason
...
...
Doc/includes/email-unpack.py
View file @
1625d887
...
...
@@ -35,7 +35,7 @@ Usage: %prog [options] msgfile
try
:
os
.
mkdir
(
opts
.
directory
)
except
OSError
,
e
:
except
OSError
as
e
:
# Ignore directory exists error
if
e
.
errno
!=
errno
.
EEXIST
:
raise
...
...
Doc/includes/sqlite3/complete_statement.py
View file @
1625d887
...
...
@@ -23,7 +23,7 @@ while True:
if
buffer
.
lstrip
().
upper
().
startswith
(
"SELECT"
):
print
cur
.
fetchall
()
except
sqlite3
.
Error
,
e
:
except
sqlite3
.
Error
as
e
:
print
"An error occurred:"
,
e
.
args
[
0
]
buffer
=
""
...
...
Doc/library/csv.rst
View file @
1625d887
...
...
@@ -480,7 +480,7 @@ A slightly more advanced use of the reader --- catching and reporting errors::
try:
for row in reader:
print row
except csv.Error
,
e:
except csv.Error
as
e:
sys.exit('file %s, line %d: %s' % (filename, reader.line_num, e))
And while the module doesn't directly support parsing strings, it can easily be
...
...
Doc/library/getopt.rst
View file @
1625d887
...
...
@@ -126,7 +126,7 @@ In a script, typical usage is something like this::
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="])
except getopt.GetoptError
,
err:
except getopt.GetoptError
as
err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
...
...
Doc/library/shutil.rst
View file @
1625d887
...
...
@@ -219,18 +219,18 @@ provided by this module. ::
else:
copy2(srcname, dstname)
# XXX What about devices, sockets etc.?
except (IOError, os.error)
,
why:
except (IOError, os.error)
as
why:
errors.append((srcname, dstname, str(why)))
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error
,
err:
except Error
as
err:
errors.extend(err.args[0])
try:
copystat(src, dst)
except WindowsError:
# can't copy file access times on Windows
pass
except OSError
,
why:
except OSError
as
why:
errors.extend((src, dst, str(why)))
if errors:
raise Error(errors)
...
...
Doc/library/socket.rst
View file @
1625d887
...
...
@@ -920,13 +920,13 @@ sends traffic to the first one connected successfully. ::
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error
,
msg:
except socket.error
as
msg:
s = None
continue
try:
s.bind(sa)
s.listen(1)
except socket.error
,
msg:
except socket.error
as
msg:
s.close()
s = None
continue
...
...
@@ -955,12 +955,12 @@ sends traffic to the first one connected successfully. ::
af, socktype, proto, canonname, sa = res
try:
s = socket.socket(af, socktype, proto)
except socket.error
,
msg:
except socket.error
as
msg:
s = None
continue
try:
s.connect(sa)
except socket.error
,
msg:
except socket.error
as
msg:
s.close()
s = None
continue
...
...
Doc/library/ssl.rst
View file @
1625d887
...
...
@@ -361,7 +361,7 @@ SSLSocket Objects
try:
s.do_handshake()
break
except ssl.SSLError
,
err:
except ssl.SSLError
as
err:
if err.args[0] == ssl.SSL_ERROR_WANT_READ:
select.select([s], [], [])
elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
...
...
Doc/library/xdrlib.rst
View file @
1625d887
...
...
@@ -274,6 +274,5 @@ Here is an example of how you would catch one of these exceptions::
p = xdrlib.Packer()
try:
p.pack_double(8.01)
except xdrlib.ConversionError
,
instance:
except xdrlib.ConversionError
as
instance:
print 'packing the double failed:', instance.msg
Doc/library/xmlrpclib.rst
View file @
1625d887
...
...
@@ -380,7 +380,7 @@ The client code for the preceding server::
proxy = xmlrpclib.ServerProxy("http://localhost:8000/")
try:
proxy.add(2, 5)
except xmlrpclib.Fault
,
err:
except xmlrpclib.Fault
as
err:
print "A fault occurred"
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString
...
...
@@ -427,7 +427,7 @@ by providing an URI that doesn't point to an XMLRPC server::
try:
proxy.some_method()
except xmlrpclib.ProtocolError
,
err:
except xmlrpclib.ProtocolError
as
err:
print "A protocol error occurred"
print "URL: %s" % err.url
print "HTTP/HTTPS headers: %s" % err.headers
...
...
@@ -545,7 +545,7 @@ Example of Client Usage
try:
print server.examples.getStateName(41)
except Error
,
v:
except Error
as
v:
print "ERROR", v
To access an XML-RPC server through a proxy, you need to define a custom
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment