[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher/HTTP - HTTPRequest.py:1.1.2.1

Shane Hathaway shane@digicool.com
Wed, 14 Nov 2001 18:50:04 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/Publisher/HTTP
In directory cvs.zope.org:/tmp/cvs-serv32497/HTTP

Added Files:
      Tag: Zope-3x-branch
	HTTPRequest.py 
Log Message:
More of publisher converted


=== Added File Zope3/lib/python/Zope/Publisher/HTTP/HTTPRequest.py === (901/1001 lines abridged)


__version__='$Revision: 1.1.2.1 $'[11:-2]

import re, sys, os, string, time, whrandom, cgi
from Zope.Publisher.BaseRequest import BaseRequest
from Zope.Publisher.Converters import get_converter
from HTTPResponse import HTTPResponse
from cgi import FieldStorage, escape
from urllib import quote, unquote, splittype, splitport

#cgi hotfix:
if not hasattr(cgi, 'valid_boundary'):
    import cgi_hotfix

isCGI_NAME = {
    # These fields are placed in request.environ instead of request.form.
    'SERVER_SOFTWARE' : 1, 
    'SERVER_NAME' : 1, 
    'GATEWAY_INTERFACE' : 1, 
    'SERVER_PROTOCOL' : 1, 
    'SERVER_PORT' : 1, 
    'REQUEST_METHOD' : 1, 
    'PATH_INFO' : 1, 
    'PATH_TRANSLATED' : 1, 
    'SCRIPT_NAME' : 1, 
    'QUERY_STRING' : 1, 
    'REMOTE_HOST' : 1, 
    'REMOTE_ADDR' : 1, 
    'AUTH_TYPE' : 1, 
    'REMOTE_USER' : 1, 
    'REMOTE_IDENT' : 1, 
    'CONTENT_TYPE' : 1, 
    'CONTENT_LENGTH' : 1,
    'SERVER_URL': 1,
    }.has_key

hide_key={
    'HTTP_AUTHORIZATION':1,
    'HTTP_CGI_AUTHORIZATION': 1,
    }.has_key

DEFAULT_PORTS = {'http': '80', 'https': '443'}

_marker=[]

class HTTPRequest(BaseRequest):
    """
    Model HTTP request data.
    

[-=- -=- -=- 901 lines omitted -=- -=- -=-]


            mo_p = parmre.match(text)

            if mo_p:
                l     = len(mo_p.group(1))
                name  = mo_p.group(2)
                value = mo_p.group(3)

            else: 
                return result 

    finally: release()

    if not already_have(name): result[name]=value

    return apply(parse_cookie,(text[l:],result))

# add class
class record:

    # TODO: declare public.

    def __getattr__(self, key, default=None):
        if key in ('get', 'keys', 'items', 'values', 'copy', 'has_key'):
            return getattr(self.__dict__, key)
        raise AttributeError, key

    def __getitem__(self, key):
        return self.__dict__[key]
            
    def __str__(self):
        L1 = self.__dict__.items()
        L1.sort()
        return ", ".join(map(lambda item: "%s: %s" % item, L1)) 

    def __repr__(self):
        L1 = self.__dict__.items()
        L1.sort()
        return ", ".join(
            map(lambda item: "%s: %s" % (item[0], repr(item[1])), L1)) 

# Flags
SEQUENCE=1
DEFAULT=2
RECORD=4
RECORDS=8
REC=RECORD|RECORDS
EMPTY=16
CONVERTED=32