Mercurial > hg > mercurial-crew-with-dirclash
comparison mercurial/hgweb.py @ 825:0108c602feb9
Add an option to hg serve to serve file using IPv6
author | Samuel Tardieu <sam@rfc1149.net> |
---|---|
date | Thu, 04 Aug 2005 13:21:27 -0800 |
parents | 8760d0c83b9b |
children | 1fe3b14c7044 |
comparison
equal
deleted
inserted
replaced
824:0932bc2fb2be | 825:0108c602feb9 |
---|---|
4 # Copyright 2005 Matt Mackall <mpm@selenic.com> | 4 # Copyright 2005 Matt Mackall <mpm@selenic.com> |
5 # | 5 # |
6 # This software may be used and distributed according to the terms | 6 # This software may be used and distributed according to the terms |
7 # of the GNU General Public License, incorporated herein by reference. | 7 # of the GNU General Public License, incorporated herein by reference. |
8 | 8 |
9 import os, cgi, time, re, difflib, sys, zlib | 9 import os, cgi, time, re, difflib, socket, sys, zlib |
10 from mercurial.hg import * | 10 from mercurial.hg import * |
11 from mercurial.ui import * | 11 from mercurial.ui import * |
12 | 12 |
13 def templatepath(): | 13 def templatepath(): |
14 for f in "templates", "../templates": | 14 for f in "templates", "../templates": |
697 sys.stdout.write(z.flush()) | 697 sys.stdout.write(z.flush()) |
698 | 698 |
699 else: | 699 else: |
700 write(self.t("error")) | 700 write(self.t("error")) |
701 | 701 |
702 def create_server(path, name, templates, address, port, | 702 def create_server(path, name, templates, address, port, use_ipv6 = False, |
703 accesslog = sys.stdout, errorlog = sys.stderr): | 703 accesslog = sys.stdout, errorlog = sys.stderr): |
704 | 704 |
705 import BaseHTTPServer | 705 import BaseHTTPServer |
706 | |
707 class IPv6HTTPServer(BaseHTTPServer.HTTPServer): | |
708 address_family = socket.AF_INET6 | |
706 | 709 |
707 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): | 710 class hgwebhandler(BaseHTTPServer.BaseHTTPRequestHandler): |
708 def log_error(self, format, *args): | 711 def log_error(self, format, *args): |
709 errorlog.write("%s - - [%s] %s\n" % (self.address_string(), | 712 errorlog.write("%s - - [%s] %s\n" % (self.address_string(), |
710 self.log_date_time_string(), | 713 self.log_date_time_string(), |
772 hg.run() | 775 hg.run() |
773 finally: | 776 finally: |
774 sys.argv, sys.stdin, sys.stdout, sys.stderr = save | 777 sys.argv, sys.stdin, sys.stdout, sys.stderr = save |
775 | 778 |
776 hg = hgweb(path, name, templates) | 779 hg = hgweb(path, name, templates) |
777 return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) | 780 if use_ipv6: |
778 | 781 return IPv6HTTPServer((address, port), hgwebhandler) |
779 def server(path, name, templates, address, port, | 782 else: |
783 return BaseHTTPServer.HTTPServer((address, port), hgwebhandler) | |
784 | |
785 def server(path, name, templates, address, port, use_ipv6 = False, | |
780 accesslog = sys.stdout, errorlog = sys.stderr): | 786 accesslog = sys.stdout, errorlog = sys.stderr): |
781 httpd = create_server(path, name, templates, address, port, | 787 httpd = create_server(path, name, templates, address, port, use_ipv6, |
782 accesslog, errorlog) | 788 accesslog, errorlog) |
783 httpd.serve_forever() | 789 httpd.serve_forever() |