Commit Graph

56 Commits

Author SHA1 Message Date
Augie Fackler
321287c10b cleanup: use urllibcompat for renamed methods on urllib request objects
Differential Revision: https://phab.mercurial-scm.org/D891
2017-10-01 12:14:21 -04:00
Alex Gaynor
dd422bc1d6 style: never put multiple statements on one line
Differential Revision: https://phab.mercurial-scm.org/D905
2017-09-29 15:49:20 +00:00
Augie Fackler
3d427e2c85 keepalive: python 3 portability tweaks
Differential Revision: https://phab.mercurial-scm.org/D888
2017-10-01 12:15:53 -04:00
Alex Gaynor
3f0d5f185a style: always use x is not None instead of not x is None
Differential Revision: https://phab.mercurial-scm.org/D842
2017-09-29 15:49:43 +00:00
Gregory Szorc
5398902f94 keepalive: add more context to bad status line errors
As the TODO in the test said, the previous error message was not
very helpful. Let's improve things.

Differential Revision: https://phab.mercurial-scm.org/D811
2017-09-25 11:05:16 +02:00
Kyle Lippincott
91ebfaffc5 keepalive: set buffering=True to do more efficient reads of headers
Support for buffering was added to python in d09d6fe31b61, first released with
python2.7.  Without this, the entirety of the response headers is read
byte-by-byte (it does more efficient reads when it gets to the non-header part
of the response).
2017-06-02 14:08:26 -07:00
Kyle Lippincott
01d7c04db6 keepalive: pass the correct arguments to HTTPResponse
python2.7's httplib.HTTPResponse takes the arguments in the following order:
    sock, debuglevel, strict, method, buffering

This was previously passing them in as positional and skipped strict, so we set
strict=method.  I'm explicitly setting strict=True now to preserve the previous
behavior that has been there since this file was created.
2017-06-01 18:23:20 -07:00
Gregory Szorc
2ccb65a5bc keepalive: send HTTP request headers in a deterministic order
An upcoming patch will add low-level testing of the bytes being sent
over the wire. As part of developing that test, I discovered that the
order of headers in HTTP requests wasn't deterministic. This patch
makes the order deterministic to make things easier to test.
2017-04-13 18:04:38 -07:00
John Mulligan
744b475308 keepalive: honor urllib2 style get_method overrides
In urllib2 docs and discussions it can be found that in order
to make a request other than GET or POST the get_method of a
Request object can be overriden. Make Mercurial's internal
version of this honor the return value of get_method.

Please see the followup patch to the bugzilla extension for
the reason for this change. Marking RFC because I'm not entirely
sure this is the right way make the HTTP requests.
2017-02-13 15:12:17 -05:00
Gregory Szorc
5990668745 keepalive: rewrite readline()
The old method was performing string concatenation, which is slower than
collecting raw chunks in a list and joining at the end.
2015-10-07 16:02:45 -07:00
Gregory Szorc
db31b0bb10 keepalive: remove limit argument from readline()
It is unused and adds complexity.
2015-10-07 15:53:58 -07:00
Gregory Szorc
4285ee0716 keepalive: don't concatenate strings when reading chunked transfer
Surprisingly, this didn't appear to speed up HTTP-based stream cloning
on my machine. I suspect this has more to do with the fact we're using
small HTTP chunks and string concatenation overhead isn't so bad.
However, the reasons for this change are solid: we know string
concatenation can be a performance sink.
2015-10-07 15:33:52 -07:00
Augie Fackler
f3e514fca2 keepalive: discard legacy Python support for error handling
We never changed the behavior defined by this attribute anyway, so
just jettison all of this support.
2016-11-21 22:17:45 -05:00
Yuya Nishihara
47f9c8b52e py3: bulk replace sys.stdin/out/err by util's
Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's.
There are a few exceptions:

 - lsprof.py and statprof.py are untouched since they are a kind of vendor
   code and they never import mercurial modules right now.
 - ui._readline() needs to replace sys.stdin and stdout to pass them to
   raw_input(). We'll need another workaround here.
2016-10-20 23:53:36 +09:00
Gregory Szorc
15c4fa9d37 keepalive: reorder header precedence
There are 3 sources of headers used by this function:

* The default headers defined by the URL opener
* Headers that are copied on redirects
* Headers that aren't copied on redirects

Previously, we applied the default headers from the URL
opener last. This feels wrong to me as those headers are
the most low level and something built on top of the URL
opener may wish to override them. So, this commit changes
the order to apply them with the least precedence.

While I was here, I removed a Python version test that is
no longer necessary.
2016-11-19 17:11:12 -08:00
Pulkit Goyal
123aebf3ce keepalive: switch from thread to threading module
The thread module in py3 is renamed to _thread, but we can use
 the high level threading module instead.
2016-07-01 19:17:16 +05:30
Pulkit Goyal
af9d7f66d0 py3: conditionalize httplib import
The httplib library is renamed to http.client in python 3. So the
import is conditionalized and a test is added in check-code to warn
to use util.httplib
2016-06-28 16:01:53 +05:30
Augie Fackler
ad67b99d20 cleanup: replace uses of util.(md5|sha1|sha256|sha512) with hashlib.\1
All versions of Python we support or hope to support make the hash
functions available in the same way under the same name, so we may as
well drop the util forwards.
2016-06-10 00:12:33 -04:00
timeless
109fcbc79e pycompat: switch to util.urlreq/util.urlerr for py3 compat 2016-04-06 23:22:12 +00:00
Gregory Szorc
2ef42b9dfb keepalive: remove useless parentheses around exception type 2016-02-28 00:00:13 -08:00
Gregory Szorc
73c33b60d4 keepalive: use print function 2015-06-21 23:14:54 -07:00
Gregory Szorc
ccd1a37a31 keepalive: use absolute_import 2015-12-22 16:28:28 -08:00
Gregory Szorc
5380dea2a7 global: mass rewrite to use modern exception syntax
Python 2.6 introduced the "except type as instance" syntax, replacing
the "except type, instance" syntax that came before. Python 3 dropped
support for the latter syntax. Since we no longer support Python 2.4 or
2.5, we have no need to continue supporting the "except type, instance".

This patch mass rewrites the exception syntax to be Python 2.6+ and
Python 3 compatible.

This patch was produced by running `2to3 -f except -w -n .`.
2015-06-23 22:20:08 -07:00
Mike Hommey
9741dad0cc util: move md5 back next to sha1 and allow to call it without an argument
This effectively backs out changeset 7582042d6cce.

The API change is done so that both util.sha1 and util.md5 can be called the
same way. The function is moved in order to use it for md5 checksumming for
an upcoming bundle2 feature.
2014-09-24 16:00:47 +09:00
Mike Hommey
d177b1d78f keepalive: fix how md5 is used
The code in keepalive dates from when it was importing the md5 module directly
and uses md5.new. Since then, what 'md5' means has been changed from an import
of the md5 module to being a function using the right module between hashlib
and md5, so the md5.new idiom doesn't work anymore.
2014-09-24 15:52:40 +09:00
Mads Kiilerich
1e900bb145 check-code: check for spaces around = for named parameters 2013-10-03 14:50:47 +02:00
Bryan O'Sullivan
e6925c17ab keepalive: drop python 2.2 legacy code 2012-10-02 14:27:13 -07:00
Mads Kiilerich
2f4504e446 fix trivial spelling errors 2012-08-15 22:38:42 +02:00
Mads Kiilerich
377db36818 help: fix some instances of 'the the' 2012-07-26 02:54:13 +02:00
Brodie Rao
7f47d4e347 check-code: ignore naked excepts with a "re-raise" comment
This also promotes the naked except check from a warning to an error.
2012-05-13 13:18:06 +02:00
Brodie Rao
c577fac135 cleanup: replace naked excepts with more specific ones 2012-05-12 16:02:45 +02:00
Brodie Rao
92158e04de cleanup: "raise SomeException()" -> "raise SomeException" 2012-05-12 16:00:58 +02:00
Brodie Rao
a7ef0a0cc5 cleanup: "not x in y" -> "x not in y" 2012-05-12 16:00:57 +02:00
Martin Geisler
d8334151e6 Remove FSF mailing address from GPL headers
The GPLv3 FAQ suggests to upgrade by

  [...] replace all your existing v2 license notices (usually at the
  top of each file) with the new recommended text available on the GNU
  licenses howto. It's more future-proof because it no longer includes
  the FSF's postal mailing address.

This removes the postal address, but leaves the version number at 2+.
2012-01-06 16:27:13 +01:00
Augie Fackler
c47e760250 keepalive: use safehasattr instead of hasattr 2011-07-25 20:36:59 -05:00
Thomas Arendsen Hein
692a53d202 classes: fix class style problems found by 06e968819ac9
This makes test-wireprotocol.py work on Python 2.4
2011-06-29 15:00:00 +02:00
Martin Geisler
af8a35e078 check-code: flag 0/1 used as constant Boolean expression 2011-06-01 12:38:46 +02:00
Benoit Boissinot
328394047f fix coding style (reported by pylint) 2010-02-08 15:36:34 +01:00
Matt Mackall
8d99be19f0 many, many trivial check-code fixups 2010-01-25 00:05:27 -06:00
Augie Fackler
c66ce37035 keepalive: handle broken pipes gracefully during large POSTs 2009-11-02 11:03:22 -05:00
Martin Geisler
6533e94352 util: remove md5
This hash function is broken and should not be used by new code. It is
currently only used by keepalive.
2009-05-04 21:30:39 +02:00
Patrick Mezard
af0fa1531e keepalive: fix a82d2fe41c70, reintroduce unredirected_hdrs
The previous fix dropped unredirected_hdrs which contain authentication
headers. Removing them break POST request requiring authentication (like
unbundle calls to bitbucket.org).
2009-04-27 22:15:36 +02:00
Matt Mackall
72994b59d3 keepalive: attempt to fix issue1003
This is a reimport of the relevant piece of the upstream urlgrabber,
which appears to be more correct.
2009-04-23 15:40:10 -05:00
Peter Arrenbrecht
19591b6a8c cleanup: drop unused assignments 2009-03-23 13:13:06 +01:00
Peter Arrenbrecht
a2d3e23eef cleanup: drop variables for unused return values
They are unnecessary. I did leave them in localrepo.py where there is
something like:

  _junk = foo()
  _junk = None

to free memory early. I don't know if just `foo()` will free the return
value as early.
2009-03-23 13:13:02 +01:00
Peter Arrenbrecht
b1f5d67640 keepalive: fix reference to IncompleteRead 2009-03-23 11:12:01 +01:00
Matt Mackall
b649059d2b keepalive: borrow code from newer httplib to patch ValueError (issue1088) 2009-02-16 17:37:23 -06:00
Dirkjan Ochtman
574603a8c0 use dict.iteritems() rather than dict.items()
This should be faster and more future-proof. Calls where the result is to be
sorted using util.sort() have been left unchanged. Calls to .items() on
configparser objects have been left as-is, too.
2009-01-12 09:16:03 +01:00
Dirkjan Ochtman
34d6bea8db python 2.6 compatibility: compatibility wrappers for hash functions 2008-04-04 22:36:40 +02:00
Alexis S. L. Carvalho
961a45df72 merge with crew-stable 2008-02-03 21:47:07 -02:00