[PATCH 4 of 8] opener: add read & write utility methods

Dan Villiom Podlaski Christiansen danchr at gmail.com
Mon Dec 27 10:02:15 CST 2010


On 27 Dec 2010, at 16:05, Adrian Buehlmann wrote:

> On 2010-12-26 12:51, Dan Villiom Podlaski Christiansen wrote:
>> A similar method for reading is added to the opener used by static
>> HTTP repositories. It doesn't do any actual closing, as the opener
>> doesn't have access to any underlying files.
>>
>> diff --git a/mercurial/statichttprepo.py b/mercurial/ 
>> statichttprepo.py
>> --- a/mercurial/statichttprepo.py
>> +++ b/mercurial/statichttprepo.py
>> @@ -75,6 +75,8 @@ def build_opener(ui, authinfo):
>>                 raise IOError('Permission denied')
>>             f = "/".join((p, urllib.quote(path)))
>>             return httprangereader(f, urlopener)
>> +        # for compatibility with regular file openers
>> +        o.read = lambda *args, **kwargs: o(*args, **kwargs).read()
>>         return o
>>
>>     opener.options = {'nonlazy': 1}
>
> is needed, then I'm fairly convinced that having to add read and write
> member functions to every kind of opener is fishy.

I've identified four kinds of opener in the Mercurial codebase:

- regular openers that use the class
- store openers for preprocessing the filename with a function
- static HTTP openers — read-only
- urllib openers

The three first I've updated; the last one is irrelevant to this  
change. Are there any other openers I need to be aware of?

--

Dan Villiom Podlaski Christiansen
danchr at gmail.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 1943 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20101227/b2f346f3/attachment.bin>


More information about the Mercurial-devel mailing list