[PATCH 2 of 9] url.py: removed 'file' inheritance in the httpsendfile class
Martin Geisler
mg at lazybytes.net
Thu Jul 15 06:50:25 CDT 2010
Renato Cunha <renatoc at gmail.com> writes:
> # HG changeset patch
> # User Renato Cunha <renatoc at gmail.com>
> # Date 1279159128 10800
> # Branch stable
> # Node ID c819375205632865c65a92eac72266f3bc84cd3a
> # Parent 21e794287623b1ae539d0213be2c8720797e256d
> url.py: removed 'file' inheritance in the httpsendfile class
>
> Since py3k doesn't have a "file" builtin and, consequently, doesn't support
> inheriting from it, this patch refactors the httpsendfile class to wrap the
> objects returned by the builtin "open" function while adding the necessary
> methods (__len__ for constructing the Content-Length header and read, write,
> close and seek for the file-like interface).
>
> diff --git a/mercurial/url.py b/mercurial/url.py
> --- a/mercurial/url.py
> +++ b/mercurial/url.py
> @@ -8,6 +8,7 @@
> # GNU General Public License version 2 or any later version.
>
> import urllib, urllib2, urlparse, httplib, os, re, socket, cStringIO
> +import __builtin__
> from i18n import _
> import keepalive, util
>
> @@ -250,9 +251,22 @@
>
> return urllib2.ProxyHandler.proxy_open(self, req, proxy, type_)
>
> -class httpsendfile(file):
> +class httpsendfile(object):
> + """This is a wrapper around the objects returned by python's "open".
> +
> + Its purpose is to send file-like objects via HTTP and, to do so, it
> + defines a __len__ attribute to feed the Content-Length header.
> + """
> +
> + def __init__(self, *args, **kwargs):
> + self._data = __builtin__.open(*args, **kwargs)
Small question -- would just using
self._data = open(*args, **kwargs)
here not do the same?
--
Martin Geisler
Mercurial links: http://mercurial.ch/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20100715/b2e1503d/attachment.pgp>
More information about the Mercurial-devel
mailing list