[Python-checkins] CVS: python/nondist/peps pep-0222.txt,1.5,1.6
A.M. Kuchling
python-dev@python.org
Tue, 12 Dec 2000 09:34:42 -0800
Update of /cvsroot/python/python/nondist/peps
In directory slayer.i.sourceforge.net:/tmp/cvs-serv12545
Modified Files:
pep-0222.txt
Log Message:
Add a first cut at a proposed new interface (still incomplete)
Index: pep-0222.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0222.txt,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** pep-0222.txt 2000/11/10 17:06:53 1.5
--- pep-0222.txt 2000/12/12 17:34:39 1.6
***************
*** 57,70 ****
seems to me that the main reason it is there is to accomodate
! form['field'].file syntax. How about the following:
! form['field'] = '' #no values for key
! form['field'] = 'string' #one value in submission for key
! form['field'] = ['string', 'string', ....] #multiple values
! form['field'] = {'fileName':'remote/path',
! 'binaryValue':'@UIHJBV29489erht...'} #one file
! form['field'] = [{'fileName':'remote/path',
! 'binaryValue':'@UIHJBV29489erht...'},
! {'fileName':'another/path',
! 'binaryValue':'7r7w7@@@@'}] #multiple files
cgi.py: I'd prefer "input" or "submission" for the suggested
--- 57,70 ----
seems to me that the main reason it is there is to accomodate
! form['field'].file syntax. How about the following:
! form['field'] = '' #no values for key
! form['field'] = 'string' #one value in submission for key
! form['field'] = ['string', 'string', ....] #multiple values
! form['field'] = {'fileName':'remote/path',
! 'binaryValue':'@UIHJBV29489erht...'} #one file
! form['field'] = [{'fileName':'remote/path',
! 'binaryValue':'@UIHJBV29489erht...'},
! {'fileName':'another/path',
! 'binaryValue':'7r7w7@@@@'}] #multiple files
cgi.py: I'd prefer "input" or "submission" for the suggested
***************
*** 130,136 ****
inappropriate.
- Copyright
This document has been placed in the public domain.
--- 130,269 ----
inappropriate.
+ * None yet
+ Proposed Interface
+
+ XXX open issues: naming convention (studlycaps or underline-separated?);
+ no interface for file uploads yet; need to look at all the various
+ packages to see if there's anything else missing; need to look at
+ the cgi.parse*() functions and see if they can be simplified, too.
+
+ Parsing functions: carry over most of the parse* functions from cgi.py
+
+ # The Response class borrows most of its methods from Zope's
+ # HTTPResponse class.
+
+ class Response:
+ """
+ Attributes:
+ status: HTTP status code to return
+ headers: dictionary of response headers
+ body: string containing the body of the HTTP response
+ """
+
+ def __init__(self, status=200, headers={}, body=""):
+ pass
+
+ def setStatus(self, status, reason=None):
+ "Set the numeric HTTP response code"
+ pass
+
+ def setHeader(self, name, value):
+ "Set an HTTP header"
+ pass
+
+ def setBody(self, body):
+ "Set the body of the response"
+ pass
+
+ def setCookie(self, name, value,
+ path = XXX, # What to use as defaults?
+ comment = XXX,
+ domain = XXX,
+ max-age = XXX,
+ expires = XXX,
+ secure = XXX
+ ):
+ "Set a cookie"
+ pass
+
+ def expireCookie(self, name):
+ "Remove a cookie from the user"
+ pass
+
+ def redirect(self, url):
+ "Redirect the browser to another URL"
+ pass
+
+ def __str__(self):
+ "Convert entire response to a string"
+ pass
+
+ def dump(self):
+ "Return a string representation useful for debugging"
+ pass
+
+ # XXX methods for specific classes of error:serverError, badRequest, etc.?
+
+
+ class Request:
+
+ """
+ Attributes:
+ .headers : dictionary containing HTTP headers
+ .cookies : dictionary of cookies
+ .form : data from the form
+ .env : environment dictionary
+ """
+
+ def __init__(self, environ=os.environ, stdin=sys.stdin,
+ keep_blank_values=0, strict_parsing=0):
+ """Initialize the request object, using the provided environment
+ and standard input."""
+ pass
+
+ # Should people just use the dictionaries directly?
+ def getHeader(self, name, default=None):
+ pass
+
+ def getCookie(self, name, default=None):
+ pass
+
+ def getField(self, name, default=None):
+ pass
+
+ def getURL(self, n=0, query_string=0):
+ """Return the URL of the current request, chopping off 'n' path
+ components from the right. Eg. if the URL is
+ "http://foo.com/bar/baz/qux", n=2 would return
+ "http://foo.com/bar". Does not include the query string (if
+ any)
+ """
+
+ def getBaseURL(self, n=0):
+ """Return the base URL of the current request, adding 'n' path
+ components to the end to recreate more of the whole URL.
+
+ Eg. if the request URL is
+ "http://foo.com/q/bar/baz/qux", n=0 would return
+ "http://foo.com/", and n=2 "http://foo.com/q/bar".
+
+ Returned URL does not include the query string, if any.
+ """
+
+ def dump(self):
+ "String representation suitable for debugging output"
+ pass
+
+ # Possibilities?
+ def getBrowser(self):
+ "Returns Mozilla/IE/Lynx/Opera/whatever"
+
+ def isSecure(self):
+ "Return true if this is an SSLified request"
+
+
+ def wrapper(func, logfile=None):
+ """
+ Calls the function 'func', passing it the arguments
+ (request, response, logfile). Exceptions are trapped and
+ sent to the file 'logfile'.
+ """
+ pass
+
+
+ Copyright
+
This document has been placed in the public domain.