view mercurial/hgweb/ @ 2394:a8f1049d1d2d

hgweb: fix errors and warnings found by pychecker - fix missing import - use type_ instead of type - remove unused variable
author Benoit Boissinot <>
date Sun, 04 Jun 2006 12:19:51 +0200
parents d351a3be3371
line wrap: on
line source

# hgweb/ - An http request from either CGI or the standalone server.
# Copyright 21 May 2005 - (c) 2005 Jake Edge <>
# Copyright 2005 Matt Mackall <>
# This software may be used and distributed according to the terms
# of the GNU General Public License, incorporated herein by reference.

from mercurial.demandload import demandload
demandload(globals(), "socket sys cgi os errno")
from mercurial.i18n import gettext as _

class hgrequest(object):
    def __init__(self, inp=None, out=None, env=None):
        self.inp = inp or sys.stdin
        self.out = out or sys.stdout
        self.env = env or os.environ
        self.form = cgi.parse(self.inp, self.env, keep_blank_values=1)

    def write(self, *things):
        for thing in things:
            if hasattr(thing, "__iter__"):
                for part in thing:
                except socket.error, inst:
                    if inst[0] != errno.ECONNRESET:

    def header(self, headers=[('Content-type','text/html')]):
        for header in headers:
            self.out.write("%s: %s\r\n" % header)

    def httphdr(self, type, file="", size=0):

        headers = [('Content-type', type)]
        if file:
            headers.append(('Content-disposition', 'attachment; filename=%s' % file))
        if size > 0:
            headers.append(('Content-length', str(size)))