]> granicus.if.org Git - python/commitdiff
Use the preferred form of raise statements in the docs.
authorGeorg Brandl <georg@python.org>
Wed, 3 Jun 2009 07:25:35 +0000 (07:25 +0000)
committerGeorg Brandl <georg@python.org>
Wed, 3 Jun 2009 07:25:35 +0000 (07:25 +0000)
12 files changed:
Doc/howto/sockets.rst
Doc/includes/email-unpack.py
Doc/includes/mp_pool.py
Doc/includes/mp_synchronize.py
Doc/library/crypt.rst
Doc/library/imputil.rst
Doc/library/rexec.rst
Doc/library/shutil.rst
Doc/library/signal.rst
Doc/reference/simple_stmts.rst
Doc/tools/roman.py
Doc/tools/sphinxext/suspicious.py

index 3cba020bb84171f64f2b7ec5adca52e63d554735..1928c2adfd9eaaa43b2a59639ae13fb2b61470cc 100644 (file)
@@ -204,8 +204,7 @@ length message::
            while totalsent < MSGLEN:
                sent = self.sock.send(msg[totalsent:])
                if sent == 0:
-                   raise RuntimeError, \
-                       "socket connection broken"
+                   raise RuntimeError("socket connection broken")
                totalsent = totalsent + sent
 
        def myreceive(self):
@@ -213,8 +212,7 @@ length message::
            while len(msg) < MSGLEN:
                chunk = self.sock.recv(MSGLEN-len(msg))
                if chunk == '':
-                   raise RuntimeError, \
-                       "socket connection broken"
+                   raise RuntimeError("socket connection broken")
                msg = msg + chunk
            return msg
 
index daf24708a49bb7bb8f0776fe5566c11d857ba261..8f99ded22c3a67a6d32cc18370dd1c913c61c21b 100644 (file)
@@ -37,7 +37,7 @@ Usage: %prog [options] msgfile
         os.mkdir(opts.directory)
     except OSError, e:
         # Ignore directory exists error
-        if e.errno <> errno.EEXIST:
+        if e.errno != errno.EEXIST:
             raise
 
     fp = open(msgfile)
index 9e89cbc607ff31af1f509da71f4b05504d9cd818..0a3d92ad544dc3b028ab517d9b0d45ff0da53471 100644 (file)
@@ -149,21 +149,21 @@ def test():
     except ZeroDivisionError:
         print '\tGot ZeroDivisionError as expected from pool.apply()'
     else:
-        raise AssertionError, 'expected ZeroDivisionError'
+        raise AssertionError('expected ZeroDivisionError')
 
     try:
         print pool.map(f, range(10))
     except ZeroDivisionError:
         print '\tGot ZeroDivisionError as expected from pool.map()'
     else:
-        raise AssertionError, 'expected ZeroDivisionError'
+        raise AssertionError('expected ZeroDivisionError')
 
     try:
         print list(pool.imap(f, range(10)))
     except ZeroDivisionError:
         print '\tGot ZeroDivisionError as expected from list(pool.imap())'
     else:
-        raise AssertionError, 'expected ZeroDivisionError'
+        raise AssertionError('expected ZeroDivisionError')
 
     it = pool.imap(f, range(10))
     for i in range(10):
@@ -176,7 +176,7 @@ def test():
             break
         else:
             if i == 5:
-                raise AssertionError, 'expected ZeroDivisionError'
+                raise AssertionError('expected ZeroDivisionError')
 
     assert i == 9
     print '\tGot ZeroDivisionError as expected from IMapIterator.next()'
index 2f43ad8d95712675debe8ac7712974bb1ed81b56..fd2ae77d870fafae321a381c1f859a5b903f2e3f 100644 (file)
@@ -249,7 +249,7 @@ def test(namespace=multiprocessing):
         info = multiprocessing._debug_info()
         if info:
             print info
-            raise ValueError, 'there should be no positive refcounts left'
+            raise ValueError('there should be no positive refcounts left')
 
 
 if __name__ == '__main__':
@@ -271,6 +271,6 @@ if __name__ == '__main__':
         import multiprocessing.dummy as namespace
     else:
         print 'Usage:\n\t%s [processes | manager | threads]' % sys.argv[0]
-        raise SystemExit, 2
+        raise SystemExit(2)
 
     test(namespace)
index 2f037c7e0e946959e03bed687282b05e19aa5bb7..91464efa8fdbf257b6cac88bca2513663cd99e70 100644 (file)
@@ -52,7 +52,8 @@ A simple example illustrating typical use::
        cryptedpasswd = pwd.getpwnam(username)[1]
        if cryptedpasswd:
            if cryptedpasswd == 'x' or cryptedpasswd == '*':
-               raise "Sorry, currently no support for shadow passwords"
+               raise NotImplementedError(
+                   "Sorry, currently no support for shadow passwords")
            cleartext = getpass.getpass()
            return crypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
        else:
index 09a41f69c6d6997c06b26d171bdff9b309f34e83..86089d241f18a09602ee2843807edbec688871dd 100644 (file)
@@ -160,7 +160,7 @@ This code is intended to be read, not executed.  However, it does work
            parent = None
            q = import_module(head, qname, parent)
            if q: return q, tail
-       raise ImportError, "No module named " + qname
+       raise ImportError("No module named " + qname)
 
    def load_tail(q, tail):
        m = q
@@ -171,7 +171,7 @@ This code is intended to be read, not executed.  However, it does work
            mname = "%s.%s" % (m.__name__, head)
            m = import_module(head, mname, m)
            if not m:
-               raise ImportError, "No module named " + mname
+               raise ImportError("No module named " + mname)
        return m
 
    def ensure_fromlist(m, fromlist, recursive=0):
@@ -189,7 +189,7 @@ This code is intended to be read, not executed.  However, it does work
                subname = "%s.%s" % (m.__name__, sub)
                submod = import_module(sub, subname, m)
                if not submod:
-                   raise ImportError, "No module named " + subname
+                   raise ImportError("No module named " + subname)
 
    def import_module(partname, fqname, parent):
        try:
index 773690437fb4b28e48acd8620036f96de04b6f94..2ce612aba7b2ca67d56fe45a5d049fb7cd6e05cb 100644 (file)
@@ -272,11 +272,11 @@ Let us say that we want a slightly more relaxed policy than the standard
            elif mode in ('w', 'wb', 'a', 'ab'):
                # check filename : must begin with /tmp/
                if file[:5]!='/tmp/':
-                   raise IOError, "can't write outside /tmp"
+                   raise IOError("can't write outside /tmp")
                elif (string.find(file, '/../') >= 0 or
                     file[:3] == '../' or file[-3:] == '/..'):
-                   raise IOError, "'..' in filename forbidden"
-           else: raise IOError, "Illegal open() mode"
+                   raise IOError("'..' in filename forbidden")
+           else: raise IOError("Illegal open() mode")
            return open(file, mode, buf)
 
 Notice that the above code will occasionally forbid a perfectly valid filename;
index e09b646e161f188e8b61e0bab61fb7311bc71fea..ad3ab57882a685e8332f4ac1b38fe1fd02b05a2b 100644 (file)
@@ -216,7 +216,7 @@ provided by this module. ::
        except OSError, why:
            errors.extend((src, dst, str(why)))
        if errors:
-           raise Error, errors
+           raise Error(errors)
 
 Another example that uses the :func:`ignore_patterns` helper::
 
index 3793a89b03a909bb0cbf143db057bc40ba553d1c..c039eee7169b1d04e0d0d18bc295768b63daaaf0 100644 (file)
@@ -232,7 +232,7 @@ be sent, and the handler raises an exception. ::
 
    def handler(signum, frame):
        print 'Signal handler called with signal', signum
-       raise IOError, "Couldn't open device!"
+       raise IOError("Couldn't open device!")
 
    # Set the signal handler and a 5-second alarm
    signal.signal(signal.SIGALRM, handler)
index e295552f052993549557bd6dbafe0eab9be31479..6f0f1f12eb2d9b17d229a44b6a524a279318bf4e 100644 (file)
@@ -288,7 +288,7 @@ The simple form, ``assert expression``, is equivalent to ::
 The extended form, ``assert expression1, expression2``, is equivalent to ::
 
    if __debug__:
-      if not expression1: raise AssertionError, expression2
+      if not expression1: raise AssertionError(expression2)
 
 .. index::
    single: __debug__
index 33f6db7ed3a79bc14070350bc83c138ebc221dd6..89ef617e6e71729262aa0704d025512c67ea5133 100644 (file)
@@ -40,9 +40,9 @@ romanNumeralMap = (('M',  1000),
 def toRoman(n):
     """convert integer to Roman numeral"""
     if not (0 < n < 5000):
-        raise OutOfRangeError, "number out of range (must be 1..4999)"
-    if int(n) <> n:
-        raise NotIntegerError, "decimals can not be converted"
+        raise OutOfRangeError("number out of range (must be 1..4999)")
+    if int(n) != n:
+        raise NotIntegerError("decimals can not be converted")
 
     result = ""
     for numeral, integer in romanNumeralMap:
@@ -67,9 +67,9 @@ romanNumeralPattern = re.compile("""
 def fromRoman(s):
     """convert Roman numeral to integer"""
     if not s:
-        raise InvalidRomanNumeralError, 'Input can not be blank'
+        raise InvalidRomanNumeralError('Input can not be blank')
     if not romanNumeralPattern.search(s):
-        raise InvalidRomanNumeralError, 'Invalid Roman numeral: %s' % s
+        raise InvalidRomanNumeralError('Invalid Roman numeral: %s' % s)
 
     result = 0
     index = 0
index ae11793ea54830b805dead5dabb8d1fc03fe35d9..37829c3caad89f75c4f76b16e27cdd3e3e0e301f 100644 (file)
@@ -159,7 +159,7 @@ class CheckSuspiciousMarkupBuilder(Builder):
         except IOError: return
         for i, row in enumerate(csv.reader(f)):
             if len(row) != 4:
-                raise ValueError, "wrong format in %s, line %d: %s" % (filename, i+1, row)
+                raise ValueError("wrong format in %s, line %d: %s" % (filename, i+1, row))
             docname, lineno, issue, text = row
             docname = docname.decode('utf-8')
             if lineno: lineno = int(lineno)