Show More
@@ -17,7 +17,7 b' def get_mtime(repo_path):' | |||||
17 | else: |
|
17 | else: | |
18 | return os.stat(hg_path).st_mtime |
|
18 | return os.stat(hg_path).st_mtime | |
19 |
|
19 | |||
20 | def staticfile(directory, fname): |
|
20 | def staticfile(directory, fname, req): | |
21 | """return a file inside directory with guessed content-type header |
|
21 | """return a file inside directory with guessed content-type header | |
22 |
|
22 | |||
23 | fname always uses '/' as directory separator and isn't allowed to |
|
23 | fname always uses '/' as directory separator and isn't allowed to | |
@@ -36,7 +36,9 b' def staticfile(directory, fname):' | |||||
36 | try: |
|
36 | try: | |
37 | os.stat(path) |
|
37 | os.stat(path) | |
38 | ct = mimetypes.guess_type(path)[0] or "text/plain" |
|
38 | ct = mimetypes.guess_type(path)[0] or "text/plain" | |
39 | return "Content-type: %s\n\n%s" % (ct, file(path).read()) |
|
39 | req.header([('Content-type', ct), | |
|
40 | ('Content-length', os.path.getsize(path))]) | |||
|
41 | return file(path).read() | |||
40 | except (TypeError, OSError): |
|
42 | except (TypeError, OSError): | |
41 | # illegal fname or unreadable file |
|
43 | # illegal fname or unreadable file | |
42 | return "" |
|
44 | return "" |
@@ -10,7 +10,7 b' import os' | |||||
10 | import os.path |
|
10 | import os.path | |
11 | import mimetypes |
|
11 | import mimetypes | |
12 | from mercurial.demandload import demandload |
|
12 | from mercurial.demandload import demandload | |
13 | demandload(globals(), "re zlib ConfigParser cStringIO sys tempfile") |
|
13 | demandload(globals(), "re zlib ConfigParser mimetools cStringIO sys tempfile") | |
14 | demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater") |
|
14 | demandload(globals(), "mercurial:mdiff,ui,hg,util,archival,templater") | |
15 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") |
|
15 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") | |
16 | from mercurial.node import * |
|
16 | from mercurial.node import * | |
@@ -652,7 +652,10 b' class hgweb(object):' | |||||
652 |
|
652 | |||
653 | def run(self, req): |
|
653 | def run(self, req): | |
654 | def header(**map): |
|
654 | def header(**map): | |
655 |
|
|
655 | header_file = cStringIO.StringIO(''.join(self.t("header", **map))) | |
|
656 | msg = mimetools.Message(header_file, 0) | |||
|
657 | req.header(msg.items()) | |||
|
658 | yield header_file.read() | |||
656 |
|
659 | |||
657 | def footer(**map): |
|
660 | def footer(**map): | |
658 | yield self.t("footer", |
|
661 | yield self.t("footer", | |
@@ -828,7 +831,7 b' class hgweb(object):' | |||||
828 | static = self.repo.ui.config("web", "static", |
|
831 | static = self.repo.ui.config("web", "static", | |
829 | os.path.join(self.templatepath, |
|
832 | os.path.join(self.templatepath, | |
830 | "static")) |
|
833 | "static")) | |
831 | req.write(staticfile(static, fname) |
|
834 | req.write(staticfile(static, fname, req) | |
832 | or self.t("error", error="%r not found" % fname)) |
|
835 | or self.t("error", error="%r not found" % fname)) | |
833 |
|
836 | |||
834 | def do_capabilities(self, req): |
|
837 | def do_capabilities(self, req): |
@@ -8,7 +8,7 b'' | |||||
8 |
|
8 | |||
9 | import os |
|
9 | import os | |
10 | from mercurial.demandload import demandload |
|
10 | from mercurial.demandload import demandload | |
11 | demandload(globals(), "ConfigParser") |
|
11 | demandload(globals(), "ConfigParser mimetools cStringIO") | |
12 | demandload(globals(), "mercurial:ui,hg,util,templater") |
|
12 | demandload(globals(), "mercurial:ui,hg,util,templater") | |
13 | demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb") |
|
13 | demandload(globals(), "mercurial.hgweb.hgweb_mod:hgweb") | |
14 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") |
|
14 | demandload(globals(), "mercurial.hgweb.common:get_mtime,staticfile") | |
@@ -48,7 +48,10 b' class hgwebdir(object):' | |||||
48 |
|
48 | |||
49 | def run(self, req): |
|
49 | def run(self, req): | |
50 | def header(**map): |
|
50 | def header(**map): | |
51 |
|
|
51 | header_file = cStringIO.StringIO(''.join(tmpl("header", **map))) | |
|
52 | msg = mimetools.Message(header_file, 0) | |||
|
53 | req.header(msg.items()) | |||
|
54 | yield header_file.read() | |||
52 |
|
55 | |||
53 | def footer(**map): |
|
56 | def footer(**map): | |
54 | yield tmpl("footer", motd=self.motd, **map) |
|
57 | yield tmpl("footer", motd=self.motd, **map) | |
@@ -132,7 +135,7 b' class hgwebdir(object):' | |||||
132 | if req.form.has_key('static'): |
|
135 | if req.form.has_key('static'): | |
133 | static = os.path.join(templater.templatepath(), "static") |
|
136 | static = os.path.join(templater.templatepath(), "static") | |
134 | fname = req.form['static'][0] |
|
137 | fname = req.form['static'][0] | |
135 | req.write(staticfile(static, fname) |
|
138 | req.write(staticfile(static, fname, req) | |
136 | or tmpl("error", error="%r not found" % fname)) |
|
139 | or tmpl("error", error="%r not found" % fname)) | |
137 | else: |
|
140 | else: | |
138 | sortable = ["name", "description", "contact", "lastchange"] |
|
141 | sortable = ["name", "description", "contact", "lastchange"] |
@@ -57,20 +57,21 b' class _wsgirequest(object):' | |||||
57 | return self.inp.read(count) |
|
57 | return self.inp.read(count) | |
58 |
|
58 | |||
59 | def write(self, *things): |
|
59 | def write(self, *things): | |
60 | if self.server_write is None: |
|
|||
61 | if not self.headers: |
|
|||
62 | self.header() |
|
|||
63 | self.server_write = self.start_response('200 Script output follows', |
|
|||
64 | self.headers) |
|
|||
65 | self.start_response = None |
|
|||
66 | self.headers = None |
|
|||
67 | for thing in things: |
|
60 | for thing in things: | |
68 | if hasattr(thing, "__iter__"): |
|
61 | if hasattr(thing, "__iter__"): | |
69 | for part in thing: |
|
62 | for part in thing: | |
70 | self.write(part) |
|
63 | self.write(part) | |
71 | else: |
|
64 | else: | |
|
65 | thing = str(thing) | |||
|
66 | if self.server_write is None: | |||
|
67 | if not self.headers: | |||
|
68 | raise RuntimeError("request.write called before headers sent (%s)." % thing) | |||
|
69 | self.server_write = self.start_response('200 Script output follows', | |||
|
70 | self.headers) | |||
|
71 | self.start_response = None | |||
|
72 | self.headers = None | |||
72 | try: |
|
73 | try: | |
73 |
self.server_write( |
|
74 | self.server_write(thing) | |
74 | except socket.error, inst: |
|
75 | except socket.error, inst: | |
75 | if inst[0] != errno.ECONNRESET: |
|
76 | if inst[0] != errno.ECONNRESET: | |
76 | raise |
|
77 | raise |
General Comments 0
You need to be logged in to leave comments.
Login now