##// END OF EJS Templates
merge with stable
Matt Mackall -
r15159:85322c19 merge default
parent child Browse files
Show More
@@ -22,8 +22,9 b' from mercurial.i18n import _'
22 class httpsendfile(object):
22 class httpsendfile(object):
23 """This is a wrapper around the objects returned by python's "open".
23 """This is a wrapper around the objects returned by python's "open".
24
24
25 Its purpose is to send file-like objects via HTTP and, to do so, it
25 Its purpose is to send file-like objects via HTTP.
26 defines a __len__ attribute to feed the Content-Length header.
26 It do however not define a __len__ attribute because the length
27 might be more than Py_ssize_t can handle.
27 """
28 """
28
29
29 def __init__(self, ui, *args, **kwargs):
30 def __init__(self, ui, *args, **kwargs):
@@ -35,9 +36,9 b' class httpsendfile(object):'
35 self.seek = self._data.seek
36 self.seek = self._data.seek
36 self.close = self._data.close
37 self.close = self._data.close
37 self.write = self._data.write
38 self.write = self._data.write
38 self._len = os.fstat(self._data.fileno()).st_size
39 self.length = os.fstat(self._data.fileno()).st_size
39 self._pos = 0
40 self._pos = 0
40 self._total = self._len / 1024 * 2
41 self._total = self.length / 1024 * 2
41
42
42 def read(self, *args, **kwargs):
43 def read(self, *args, **kwargs):
43 try:
44 try:
@@ -54,9 +55,6 b' class httpsendfile(object):'
54 unit=_('kb'), total=self._total)
55 unit=_('kb'), total=self._total)
55 return ret
56 return ret
56
57
57 def __len__(self):
58 return self._len
59
60 # moved here from url.py to avoid a cycle
58 # moved here from url.py to avoid a cycle
61 def readauthforuri(ui, uri, user):
59 def readauthforuri(ui, uri, user):
62 # Read configuration
60 # Read configuration
@@ -73,9 +73,14 b' class httprepository(wireproto.wirerepos'
73 if cmd == 'pushkey':
73 if cmd == 'pushkey':
74 args['data'] = ''
74 args['data'] = ''
75 data = args.pop('data', None)
75 data = args.pop('data', None)
76 size = 0
77 if util.safehasattr(data, 'length'):
78 size = data.length
79 elif data is not None:
80 size = len(data)
76 headers = args.pop('headers', {})
81 headers = args.pop('headers', {})
77
82
78 if data and self.ui.configbool('ui', 'usehttp2', False):
83 if size and self.ui.configbool('ui', 'usehttp2', False):
79 headers['Expect'] = '100-Continue'
84 headers['Expect'] = '100-Continue'
80 headers['X-HgHttp2'] = '1'
85 headers['X-HgHttp2'] = '1'
81
86
@@ -104,9 +109,6 b' class httprepository(wireproto.wirerepos'
104 cu = "%s%s" % (self._url, qs)
109 cu = "%s%s" % (self._url, qs)
105 req = urllib2.Request(cu, data, headers)
110 req = urllib2.Request(cu, data, headers)
106 if data is not None:
111 if data is not None:
107 # len(data) is broken if data doesn't fit into Py_ssize_t
108 # add the header ourself to avoid OverflowError
109 size = data.__len__()
110 self.ui.debug("sending %s bytes\n" % size)
112 self.ui.debug("sending %s bytes\n" % size)
111 req.add_unredirected_header('Content-Length', '%d' % size)
113 req.add_unredirected_header('Content-Length', '%d' % size)
112 try:
114 try:
@@ -188,7 +188,7 b' def extract(ui, fileobj):'
188 pend = subject.find(']')
188 pend = subject.find(']')
189 if pend >= 0:
189 if pend >= 0:
190 subject = subject[pend + 1:].lstrip()
190 subject = subject[pend + 1:].lstrip()
191 subject = subject.replace('\n\t', ' ')
191 subject = re.sub(r'\n[ \t]+', ' ', subject)
192 ui.debug('Subject: %s\n' % subject)
192 ui.debug('Subject: %s\n' % subject)
193 if user:
193 if user:
194 ui.debug('From: %s\n' % user)
194 ui.debug('From: %s\n' % user)
@@ -913,7 +913,12 b" def datestr(date=None, format='%a %b %d "
913 minutes = abs(tz) // 60
913 minutes = abs(tz) // 60
914 format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
914 format = format.replace("%1", "%c%02d" % (sign, minutes // 60))
915 format = format.replace("%2", "%02d" % (minutes % 60))
915 format = format.replace("%2", "%02d" % (minutes % 60))
916 s = time.strftime(format, time.gmtime(float(t) - tz))
916 try:
917 t = time.gmtime(float(t) - tz)
918 except ValueError:
919 # time was out of range
920 t = time.gmtime(sys.maxint)
921 s = time.strftime(format, t)
917 return s
922 return s
918
923
919 def shortdate(date=None):
924 def shortdate(date=None):
General Comments 0
You need to be logged in to leave comments. Login now