[RFC] Transport hints

Robert Collins robertc at robertcollins.net
Sun Jul 23 23:10:10 BST 2006


On Sun, 2006-07-23 at 07:41 -0500, John Arbash Meinel wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I've been thinking about both sftp and http lately, and how we want to
> make customized get requests.
> For sftp, we want to do a get() while disabling prefetch, and for http,
> we want to do one while disabling automatic following of redirects.
> 
> Ultimately, this means we need to parameterize Transport.get() so that
> we can pass these flags. And I realized, I don't really want to add a
> new public parameter, which then all transports need to implement, even
> if they just ignore it.
> 
> I realized that a 'hints' parameter would satisfy this nicely. By
> calling it 'hints', it makes it clear that it isn't strictly required,
> just a hint as to what should be done.
> 
> I've thought about doing it two ways:
> 
> def get(relpath, **hints):
> 
> versus
> 
> def get(relpath, hints={}):
> 
> Then all transports just need to add one more field, which they treat as
> a dict that they can extract hints from.
> 
> My question is, which way would be better? I prefer the syntax of the
> former, mostly because it is shorter, and easier to type:
> 
> a_transport.get(relpath, prefetch=False)
> 
> versus
> 
> a_transport.get(relpath, hints={'prefetch':False})
> 
> However, I kind of like that the later is more obvious that we are
> giving a hint.
> 
> Anyone have a particular preference?

I dont get what this buys us over
def get_no_prefetch(relpath) - define once, at the top
or
def get(relpath, prefetch=False): - which is clear, and language checked
for typos.
or
def get(relpath, options=None):
...
class GetOptions(object):

    def __init__(self, prefetch=False, no_redirect=False):
        self.prefetch=prefetch
        self.no_redirect=no_redirect

One could make GetOptions be factoried out from the transport - probably
a good idea.

our *interface* is what clients use, and that means a client may send
prefetch=False, or redirect=False, to any transport, so they should all
handle them.

Using an Options object is preferrable to a dict, because typos are
checked rather than silently ignored. Also it means that all the known
options are documented. Alloing Options to be made by a transport
factory means new transports can extend the base Options we have made.

Rob


-- 
GPG key available at: <http://www.robertcollins.net/keys.txt>.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060724/8ae0602a/attachment.pgp 


More information about the bazaar mailing list