Transport w/ extra tests

John A Meinel john at arbash-meinel.com
Tue Jul 19 16:56:49 BST 2005


Aaron Bentley wrote:
> 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:

Sure, right now all of the errors inherit from TransportError, so we
could certainly create a hierarchy of errors. Or we could include an
.errno value, which could be used similarly to IOError.errno.
I suppose I prefer the individual exceptions, because I think it is
easier to catch them, than to trap an error and check the errno.

>
> 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.

Well, they all throw TransportError, but I agree, that type is too opaque.

>
> 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.

You wouldn't have to have the encode/decode. Except, in the Branch
class, there are a lot of locations that require encode/decode, and I
thought it would be easier to do that at the lower level rather than the
higher.
Certainly we can rewrite more of Branch to use a different function call
(rather than _transport.get) which wraps the return value of
_transport.get()

>
> 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)

Also far as I know, it isn't any different. I was just trying to provide
encoding support at the Transport layer, to make it easier. It certainly
isn't required.

>
> Aaron
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050719/d6e6b204/attachment.pgp 


More information about the bazaar mailing list