/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Jelmer Vernooij
  • Date: 2017-02-05 15:38:26 UTC
  • mto: (6621.2.1 py3)
  • mto: This revision was merged to the branch mainline in revision 6624.
  • Revision ID: jelmer@jelmer.uk-20170205153826-rnrd0m3iqoizqvrw
Apply 2to3 except fix.

Show diffs side-by-side

added added

removed removed

Lines of Context:
124
124
        # It is probably faster to just do the chmod, rather than
125
125
        # doing a stat, and then trying to compare
126
126
        os.chmod(filename, mode)
127
 
    except (IOError, OSError),e:
 
127
    except (IOError, OSError) as e:
128
128
        # Permission/access denied seems to commonly happen on smbfs; there's
129
129
        # probably no point warning about it.
130
130
        # <https://bugs.launchpad.net/bzr/+bug/606537>
213
213
            stat = getattr(os, 'lstat', os.stat)
214
214
            stat(f)
215
215
            return True
216
 
        except OSError, e:
 
216
        except OSError as e:
217
217
            if e.errno == errno.ENOENT:
218
218
                return False;
219
219
            else:
247
247
    file_existed = False
248
248
    try:
249
249
        rename_func(new, tmp_name)
250
 
    except (errors.NoSuchFile,), e:
 
250
    except (errors.NoSuchFile,) as e:
251
251
        pass
252
 
    except IOError, e:
 
252
    except IOError as e:
253
253
        # RBC 20060103 abstraction leakage: the paramiko SFTP clients rename
254
254
        # function raises an IOError with errno is None when a rename fails.
255
255
        # This then gets caught here.
256
256
        if e.errno not in (None, errno.ENOENT, errno.ENOTDIR):
257
257
            raise
258
 
    except Exception, e:
 
258
    except Exception as e:
259
259
        if (getattr(e, 'errno', None) is None
260
260
            or e.errno not in (errno.ENOENT, errno.ENOTDIR)):
261
261
            raise
270
270
            # not be set.
271
271
            rename_func(old, new)
272
272
            success = True
273
 
        except (IOError, OSError), e:
 
273
        except (IOError, OSError) as e:
274
274
            # source and target may be aliases of each other (e.g. on a
275
275
            # case-insensitive filesystem), so we may have accidentally renamed
276
276
            # source by when we tried to rename target
436
436
    """
437
437
    try:
438
438
        fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
439
 
    except OSError, e:
 
439
    except OSError as e:
440
440
        if e.errno in (errno.EPERM, errno.EACCES, errno.EBUSY, errno.EINVAL):
441
441
            # If we try to rename a non-existant file onto cwd, we get
442
442
            # EPERM or EACCES instead of ENOENT, this will raise ENOENT
460
460
    def _rename_wrapper(old, new):
461
461
        try:
462
462
            rename_func(old, new)
463
 
        except OSError, e:
 
463
        except OSError as e:
464
464
            detailed_error = OSError(e.errno, e.strerror +
465
465
                                " [occurred when renaming '%s' to '%s']" %
466
466
                                (old, new))
1102
1102
 
1103
1103
try:
1104
1104
    from bzrlib._chunks_to_lines_pyx import chunks_to_lines
1105
 
except ImportError, e:
 
1105
except ImportError as e:
1106
1106
    failed_to_load_extension(e)
1107
1107
    from bzrlib._chunks_to_lines_py import chunks_to_lines
1108
1108
 
1141
1141
        return
1142
1142
    try:
1143
1143
        os.link(src, dest)
1144
 
    except (OSError, IOError), e:
 
1144
    except (OSError, IOError) as e:
1145
1145
        if e.errno != errno.EXDEV:
1146
1146
            raise
1147
1147
        shutil.copyfile(src, dest)
1154
1154
    """
1155
1155
    try:
1156
1156
       _delete_file_or_dir(path)
1157
 
    except (OSError, IOError), e:
 
1157
    except (OSError, IOError) as e:
1158
1158
        if e.errno in (errno.EPERM, errno.EACCES):
1159
1159
            # make writable and try again
1160
1160
            try:
1778
1778
        append = dirblock.append
1779
1779
        try:
1780
1780
            names = sorted(map(decode_filename, _listdir(top)))
1781
 
        except OSError, e:
 
1781
        except OSError as e:
1782
1782
            if not _is_error_enotdir(e):
1783
1783
                raise
1784
1784
        else:
1852
1852
            try:
1853
1853
                from bzrlib._readdir_pyx import UTF8DirReader
1854
1854
                _selected_dir_reader = UTF8DirReader()
1855
 
            except ImportError, e:
 
1855
            except ImportError as e:
1856
1856
                failed_to_load_extension(e)
1857
1857
                pass
1858
1858
 
1988
1988
    try:
1989
1989
        s = os.stat(src)
1990
1990
        chown(dst, s.st_uid, s.st_gid)
1991
 
    except OSError, e:
 
1991
    except OSError as e:
1992
1992
        trace.warning(
1993
1993
            'Unable to copy ownership from "%s" to "%s". '
1994
1994
            'You may want to set it manually.', src, dst)
2105
2105
    while 1:
2106
2106
        try:
2107
2107
            bytes = sock.recv(max_read_size)
2108
 
        except socket.error, e:
 
2108
        except socket.error as e:
2109
2109
            eno = e.args[0]
2110
2110
            if eno in _end_of_stream_errors:
2111
2111
                # The connection was closed by the other side.  Callers expect
2158
2158
    while sent_total < byte_count:
2159
2159
        try:
2160
2160
            sent = sock.send(buffer(bytes, sent_total, MAX_SOCKET_CHUNK))
2161
 
        except (socket.error, IOError), e:
 
2161
        except (socket.error, IOError) as e:
2162
2162
            if e.args[0] in _end_of_stream_errors:
2163
2163
                raise errors.ConnectionReset(
2164
2164
                    "Error trying to write to socket", e)
2189
2189
            sock.connect(sa)
2190
2190
            return sock
2191
2191
 
2192
 
        except socket.error, err:
 
2192
        except socket.error as err:
2193
2193
            # 'err' is now the most recent error
2194
2194
            if sock is not None:
2195
2195
                sock.close()
2252
2252
        try:
2253
2253
            from bzrlib._readdir_pyx import UTF8DirReader
2254
2254
            file_kind_from_stat_mode = UTF8DirReader().kind_from_mode
2255
 
        except ImportError, e:
 
2255
        except ImportError as e:
2256
2256
            # This is one time where we won't warn that an extension failed to
2257
2257
            # load. The extension is never available on Windows anyway.
2258
2258
            from bzrlib._readdir_py import (
2265
2265
    try:
2266
2266
        # XXX cache?
2267
2267
        return _lstat(f)
2268
 
    except OSError, e:
 
2268
    except OSError as e:
2269
2269
        if getattr(e, 'errno', None) in (errno.ENOENT, errno.ENOTDIR):
2270
2270
            raise errors.NoSuchFile(f)
2271
2271
        raise
2291
2291
    while True:
2292
2292
        try:
2293
2293
            return f(*a, **kw)
2294
 
        except (IOError, OSError), e:
 
2294
        except (IOError, OSError) as e:
2295
2295
            if e.errno == errno.EINTR:
2296
2296
                continue
2297
2297
            raise
2313
2313
        re_obj = re.compile(re_string, flags)
2314
2314
        re_obj.search("")
2315
2315
        return re_obj
2316
 
    except errors.InvalidPattern, e:
 
2316
    except errors.InvalidPattern as e:
2317
2317
        if where:
2318
2318
            where = ' in ' + where
2319
2319
        # despite the name 'error' is a type
2533
2533
    try:
2534
2534
        # Special meaning of unix kill: just check if it's there.
2535
2535
        os.kill(pid, 0)
2536
 
    except OSError, e:
 
2536
    except OSError as e:
2537
2537
        if e.errno == errno.ESRCH:
2538
2538
            # On this machine, and really not found: as sure as we can be
2539
2539
            # that it's dead.
2569
2569
    if fn is not None:
2570
2570
        try:
2571
2571
            fn(fileno)
2572
 
        except IOError, e:
 
2572
        except IOError as e:
2573
2573
            # See bug #1075108, on some platforms fdatasync exists, but can
2574
2574
            # raise ENOTSUP. However, we are calling fdatasync to be helpful
2575
2575
            # and reduce the chance of corruption-on-powerloss situations. It
2587
2587
    """
2588
2588
    try:
2589
2589
        os.mkdir(path)
2590
 
    except OSError, e:
 
2590
    except OSError as e:
2591
2591
        if e.errno != errno.EEXIST:
2592
2592
            raise
2593
2593
        if os.listdir(path) != []: