changeset 10491:d7e582cab6b6 stable

http: len(x) fails if it doesn't fit into an int, use __len__() instead len(x) raises OverflowError if it's bigger than 2**31-1, we need to call __len__() ourself instead.
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 17 Feb 2010 11:00:48 +0100
parents f2618cacb485
children 0e64d814d7d0
files mercurial/httprepo.py
diffstat 1 files changed, 8 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/httprepo.py	Tue Feb 16 21:04:04 2010 +0100
+++ b/mercurial/httprepo.py	Wed Feb 17 11:00:48 2010 +0100
@@ -74,10 +74,15 @@
         q.update(args)
         qs = '?%s' % urllib.urlencode(q)
         cu = "%s%s" % (self._url, qs)
+        req = urllib2.Request(cu, data, headers)
+        if data is not None:
+            # len(data) is broken if data doesn't fit into Py_ssize_t
+            # add the header ourself to avoid OverflowError
+            size = data.__len__()
+            self.ui.debug("sending %s bytes\n" % size)
+            req.add_unredirected_header('Content-Length', '%d' % size)
         try:
-            if data:
-                self.ui.debug("sending %s bytes\n" % len(data))
-            resp = self.urlopener.open(urllib2.Request(cu, data, headers))
+            resp = self.urlopener.open(req)
         except urllib2.HTTPError, inst:
             if inst.code == 401:
                 raise util.Abort(_('authorization failed'))