Commit Graph

55 Commits

Author SHA1 Message Date
Yuya Nishihara
47690f822c hgweb: use absolute_import 2015-10-31 22:07:40 +09:00
Anton Shestakov
9b60cbd85f hgweb: replace some str.split() calls by str.partition() or str.rpartition()
Since Python 2.5 str has new methods: partition and rpartition. They are more
specialized than the usual split and rsplit, and they sometimes convey the
intent of code better and also are a bit faster (faster than split/rsplit with
maxsplit specified). Let's use them in appropriate places for a small speedup.

Example performance (partition):

$ python -m timeit 'assert "apple|orange|banana".split("|")[0] == "apple"'
1000000 loops, best of 3: 0.376 usec per loop

$ python -m timeit 'assert "apple|orange|banana".split("|", 1)[0] == "apple"'
1000000 loops, best of 3: 0.327 usec per loop

$ python -m timeit 'assert "apple|orange|banana".partition("|")[0] == "apple"'
1000000 loops, best of 3: 0.214 usec per loop

Example performance (rpartition):

$ python -m timeit 'assert "apple|orange|banana".rsplit("|")[-1] == "banana"'
1000000 loops, best of 3: 0.372 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rsplit("|", 1)[-1] == "banana"'
1000000 loops, best of 3: 0.332 usec per loop

$ python -m timeit 'assert "apple|orange|banana".rpartition("|")[-1] == "banana"'
1000000 loops, best of 3: 0.219 usec per loop
2015-11-02 23:37:49 +08:00
timeless@mozdev.org
9059b84547 hgweb: remove ErrorResponse.message
BaseException.message is deprecated:
https://www.python.org/dev/peps/pep-0352/#retracted-ideas
2015-09-08 14:56:29 -04:00
Gregory Szorc
962145920a hgweb: add some documentation
It took longer than I wanted to grok how the various parts of hgweb
worked. So I added some class and method documentation to help whoever
hacks on this next.
2015-08-22 13:58:59 -07: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
Mads Kiilerich
202753eeb5 hgweb: pass the actual response body to request.response, not just the length
This makes it less likely to send a response that doesn't match Content-Length.
2013-01-15 01:07:03 +01:00
Mads Kiilerich
e3bf5c6dbe hgweb: don't pass empty response chunks on
hgweb internals will often produce empty writes - especially when returning
compressed data.  hgweb is no middleware application and there is thus no
reason to pass them on to be processed in other layers.
2013-01-15 01:05:12 +01:00
Mads Kiilerich
00d7d25679 hgweb: remove handling of any else than strings from request.write
Iterators should be returned WSGI style, not written. And apparently all of
hgweb do that.
2013-01-15 01:05:12 +01:00
Mads Kiilerich
ab33fcb117 hgweb: simplify wsgirequest header handling
Remove leaky header abstraction and prepare for other encodings.
2013-01-15 01:05:12 +01:00
Mads Kiilerich
5b3ff65d9e hgweb: make type a mandatory parameter to request.respond
There will thus always be headers and the runtime check can be removed.
2013-01-15 01:05:12 +01:00
Mads Kiilerich
14dc808b35 hgweb: send Content-Length 0 for zero length response
Before, Content-Length wasn't sent for 0 length responses. Now it is.

This could in principle prevent some unnecessary http connection close.
2013-01-15 01:05:12 +01:00
Augie Fackler
2e41c2e64a globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__') 2011-07-25 15:30:19 -05:00
Dirkjan Ochtman
43eea49bf4 hgweb: pmezard thinks one default is enough 2011-03-12 16:00:54 +01:00
Dirkjan Ochtman
d17590d4e7 deal with empty Content-Length headers 2011-03-12 15:21:45 +01:00
Augie Fackler
4ec8b25214 hgweb: don't send a body or illegal headers during 304 response
Without this fix, mod_wsgi and spawning get in a wedged state after
sending a 304 response. Not sending a body fixed that problem. The
header change was discovered by using wsgiref.validate.validator to
check for other errors.
2010-10-16 17:29:04 -05:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Nicolas Dumazet
92d5d992fc hgweb: request: strip() form values
Entering "<correct_cset_hash> " in the search form was not returning anything.
This happens relatively often, due to HTML formatting: when copy/pasting a cset
hash from the web, selection might contain surrounding spaces.
2009-12-28 12:14:26 +09:00
Sune Foldager
ee001cdc90 hgweb: send proper error messages to the client
Fixes a bug in protocol which caused an exception during exception handling in
some cases on Windows. Also makes sure the server error message is correctly
propagated to the client, instead of being thrown away.
2009-11-02 10:20:04 +01:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Dirkjan Ochtman
2ab2fbac87 hgweb: commit forgotten update to 94505a170e84 2009-02-09 13:08:32 +01:00
Sune Foldager
190a26b26d hgweb: support custom http headers in ErrorResponse 2009-02-09 11:31:52 +01:00
Dirkjan Ochtman
e7f8861527 hgweb: be sure to drain request data even in early error conditions
Thanks to Mads Kiilerich with noticing this. The hg client can only read data
after all the sent data has been read, so we have to read all the request data
even if we're not going to do anything with it (in error conditions). This
is not easy to fix in the client, because we're using Python's httplib, which
is strictly stateful. Abstracted the draining into a separate method.
2008-10-20 10:15:26 +02:00
Dirkjan Ochtman
f174f95f70 hgweb: move shortcut expansion to request instantiation 2008-06-26 13:45:39 +02:00
Joel Rosdahl
4f8012378a Remove unused imports 2008-03-06 22:23:41 +01:00
Thomas Arendsen Hein
b04d324f97 hgweb: Quote filenames when downloading raw files. 2008-02-16 18:12:30 +01:00
Thomas Arendsen Hein
a285a14d02 hgweb: Pass only filename instead of full path when downloading raw files.
Before this patch "filename=foo/bar" was sent and e.g. Firefox offered to save
the file as "foo-bar" instead of just "bar".
2008-02-16 17:51:30 +01:00
Dirkjan Ochtman
3d668210f2 hgweb: explicit response status 2008-02-01 10:31:13 +01:00
Dirkjan Ochtman
4ea6b6bcae send conservatively capitalized HTTP headers 2008-01-23 14:28:25 +01:00
Dirkjan Ochtman
a51e4d434d hgweb: revert to showing file instead of offering for download 2008-01-22 10:45:52 +01:00
Dirkjan Ochtman
54cd7309f5 hgweb: be sure to send a valid content-type for raw files 2008-01-22 12:31:55 +01:00
Dirkjan Ochtman
0b45850058 hgweb: cleanup buglet introduced in 7ec4fd3d8731 2008-01-22 09:11:06 +01:00
Dirkjan Ochtman
e43716d86a hgweb: separate out start_response() calling 2008-01-18 19:53:38 +01:00
Dirkjan Ochtman
54b4ea87f1 hgweb: return iterable, add deprecation note 2008-01-18 19:53:38 +01:00
Dirkjan Ochtman
0d71615663 hgweb: remove some legacy code 2008-01-18 19:53:38 +01:00
Thomas Arendsen Hein
347da85c36 Removed tabs and trailing whitespace in python files 2007-12-29 19:49:48 +01:00
Dirkjan Ochtman
eb63af80e4 Less indirection in the WSGI web interface. This simplifies some code, and makes it more compliant with WSGI. 2007-11-30 18:23:18 +01:00
Bryan O'Sullivan
9ae1a2c354 hgweb: fix breaking tests on Python < 2.5 2007-11-28 09:39:17 -08:00
Bryan O'Sullivan
e19dabc11f hgweb: return meaningful HTTP status codes instead of nonsense 2007-11-28 08:38:42 -08:00
Thomas Arendsen Hein
483231d996 Cleanup of whitespace, indentation and line continuation. 2007-06-19 08:06:37 +02:00
Alexis S. L. Carvalho
4bb1d039c5 Merge with crew-stable. 2007-03-19 19:16:35 -03:00
Alexis S. L. Carvalho
3082154fa5 avoid _wsgioutputfile <-> _wsgirequest circular reference
We use the _wsgirequest object itself as the output file object.

To avoid a "self.out = self" which would create another circular
reference, we make the "out" attribute a trivial property.
2007-03-19 19:07:39 -03:00
Benoit Boissinot
cd66ae056f remove various unused import 2006-12-25 13:37:00 +01:00
Matt Mackall
f17a4e1934 Replace demandload with new demandimport 2006-12-13 13:27:09 -06:00
Thomas Arendsen Hein
411d64ce3e white space and line break cleanups 2006-11-17 08:06:54 +01:00
Vadim Gelfer
dc377b58c1 update copyrights. 2006-08-12 12:30:02 -07:00
Eric Hopper
cbbc59972c Arrange for old copies of CGI scripts to still work. 2006-06-29 19:06:18 -07:00
Eric Hopper
a557f02a71 Really fix http headers for web UI and issue 254.
This also arranges for static content to allow a keepalive connection.
2006-06-27 09:33:12 -07:00
Eric Hopper
000dcf2978 Fix two small bugs that would've prevented the web interface and IPv6
from working.
2006-06-27 00:09:35 -07:00
Eric Hopper
4498f60ff4 This patch make several WSGI related alterations.
First, it changes the server to be almost a generic WSGI server.

Second, it changes request.py to have wsgiapplication and
_wsgirequest.  wsgiapplication is a class that creates _wsgirequests
when called by a WSGI compliant server.  It needs to know whether
or not it should create hgwebdir or hgweb requests.

Lastly, wsgicgi.py is added, and the CGI scripts are altered to
use it to launch wsgiapplications in a WSGI compliant way.

As a side effect, all the keepalive code has been removed from
request.py.  This code needs to be moved so that it is exclusively
in server.py
2006-06-27 00:09:33 -07:00
Vadim Gelfer
9420a748d4 push over http: server side authorization support.
new hgrc entries allow_push, deny_push, push_ssl control push over http.

allow_push list controls push.  if empty or not set, no user can push.
if "*", any user (incl. unauthenticated user) can push.  if list of user
names, only authenticated users in list can push.

deny_push list examined before allow_push.  if "*", no user can push.
if list of user names, no unauthenticated user can push, and no users
in list can push.

push_ssl requires https connection for push.  default is true, so password
sniffing can not be done.
2006-06-20 15:23:01 -07:00