Transport w/ extra tests

Aaron Bentley aaron.bentley at utoronto.ca
Tue Jul 19 15:22:56 BST 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi John,

One thing that would be really nice to see would be unified error
handling for Transports.  It would be nice if you could call
my_transport.get() and know that the possible errors are something like:
ResourceUnavailable (dns lookup failed, could not contact server) or
NoSuchFile.  The errors themselves could contain the explanation, and
maybe the root error.  E.g. for LocalTransport:

class LocalTransport(Transport):
...
    def get(self, relpath):
        try:
            return file(self.abspath(relpath), 'rb')
        except OSError, e:
            if e.errno == errno.ENOENT:
                raise NoSuchFile("The file %s does not exist" % relpath,

                                 orig_error=e)
            else:
                raise

That way, on a higher level, you can do
try:
    file = transport.get("foo")
except NoSuchFile:
    file = GzipFile(transport.get("foo.gz"))

And the error handling doesn't depend on the underlying transport.

Also, do we need those encode/decode parameters?  I'd expect the
Transport to worry about delivering the right bitstream, and let higher
levels worry about what it means.

It doesn't look like codecs.open is much more than:
def open(filename, mode, encoding, errors, buffering):
    getreader(encoding)(file(filename, mode, buffering), errors=errors)

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFC3QzA0F+nu1YWqI0RArkuAJ9Fe4nJuM19EO0A1Q+DIOYR+5kAiACcCZhs
08vWQPV5Jq2ibnhaW7EKASo=
=Qjus
-----END PGP SIGNATURE-----




More information about the bazaar mailing list