Ticket #5004: web.patch

File web.patch, 5.7 KB (added by Juan A. Diaz, 11 years ago)

patch

  • twisted/web/server.py

    diff --git a/twisted/web/server.py b/twisted/web/server.py
    index 447d578..4ea8895 100644
    a b infrastructure. 
    1111# System Imports
    1212
    1313import warnings
    14 import string
    1514import types
    1615import copy
    1716import os
    class Request(pb.Copyable, http.Request, components.Componentized): 
    121120
    122121        # Resource Identification
    123122        self.prepath = []
    124         self.postpath = map(unquote, string.split(self.path[1:], '/'))
     123        self.postpath = map(unquote, self.path[1:].split('/'))
    125124        try:
    126125            resrc = self.site.getResourceFor(self)
    127126            self.render(resrc)
    class Request(pb.Copyable, http.Request, components.Componentized): 
    181180                    'URI': escape(self.uri),
    182181                    'method': self.method,
    183182                    'plural': ((len(allowedMethods) > 1) and 's') or '',
    184                     'allowed': string.join(allowedMethods, ', ')
     183                    'allowed': ', '.join(allowedMethods)
    185184                    })
    186185                epage = resource.ErrorPage(http.NOT_ALLOWED,
    187186                                           "Method Not Allowed", s)
    class Request(pb.Copyable, http.Request, components.Componentized): 
    287286    def getSession(self, sessionInterface = None):
    288287        # Session management
    289288        if not self.session:
    290             cookiename = string.join(['TWISTED_SESSION'] + self.sitepath, "_")
     289            cookiename = "_".join(['TWISTED_SESSION'] + self.sitepath)
    291290            sessionCookie = self.getCookie(cookiename)
    292291            if sessionCookie:
    293292                try:
  • twisted/web/twcgi.py

    diff --git a/twisted/web/twcgi.py b/twisted/web/twcgi.py
    index 1bdc402..eab658e 100644
    a b I hold resource classes and helper classes that deal with CGI scripts. 
    88"""
    99
    1010# System Imports
    11 import string
    1211import os
    1312import urllib
    1413
    class CGIScript(resource.Resource): 
    6867        @type request: L{twisted.web.http.Request}
    6968        @param request: An HTTP request.
    7069        """
    71         script_name = "/"+string.join(request.prepath, '/')
    72         serverName = string.split(request.getRequestHostname(), ':')[0]
     70        script_name = "/"+"/".join(request.prepath)
     71        serverName = request.getRequestHostname().split(':')[0]
    7372        env = {"SERVER_SOFTWARE":   server.version,
    7473               "SERVER_NAME":       serverName,
    7574               "GATEWAY_INTERFACE": "CGI/1.1",
    class CGIScript(resource.Resource): 
    8988            env['REMOTE_ADDR'] = ip
    9089        pp = request.postpath
    9190        if pp:
    92             env["PATH_INFO"] = "/"+string.join(pp, '/')
     91            env["PATH_INFO"] = "/"+"/".join(pp)
    9392
    9493        if hasattr(request, "content"):
    9594            # request.content is either a StringIO or a TemporaryFile, and
    class CGIScript(resource.Resource): 
    9998            request.content.seek(0,0)
    10099            env['CONTENT_LENGTH'] = str(length)
    101100
    102         qindex = string.find(request.uri, '?')
     101        qindex = request.uri.find('?')
    103102        if qindex != -1:
    104103            qs = env['QUERY_STRING'] = request.uri[qindex+1:]
    105104            if '=' in qs:
    class CGIScript(resource.Resource): 
    112111
    113112        # Propogate HTTP headers
    114113        for title, header in request.getAllHeaders().items():
    115             envname = string.upper(string.replace(title, '-', '_'))
     114            envname = title.replace('-', '_').upper()
    116115            if title not in ('content-type', 'content-length'):
    117116                envname = "HTTP_" + envname
    118117            env[envname] = header
    class CGIProcessProtocol(protocol.ProcessProtocol, pb.Viewable): 
    276275            text = self.headertext + output
    277276            headerEnds = []
    278277            for delimiter in '\n\n','\r\n\r\n','\r\r', '\n\r\n':
    279                 headerend = string.find(text,delimiter)
     278                headerend = text.find(delimiter)
    280279                if headerend != -1:
    281280                    headerEnds.append((headerend, delimiter))
    282281            if headerEnds:
    class CGIProcessProtocol(protocol.ProcessProtocol, pb.Viewable): 
    289288                self.headertext = text[:headerend]
    290289                # This is a final version of the header text.
    291290                linebreak = delimiter[:len(delimiter)/2]
    292                 headers = string.split(self.headertext, linebreak)
     291                headers = self.headertext.split(linebreak)
    293292                for header in headers:
    294                     br = string.find(header,': ')
     293                    br = header.find(': ')
    295294                    if br == -1:
    296295                        log.msg( 'ignoring malformed CGI header: %s' % header )
    297296                    else:
    298                         headerName = string.lower(header[:br])
     297                        headerName = header[:br].lower()
    299298                        headerText = header[br+2:]
    300299                        if headerName == 'location':
    301300                            self.request.setResponseCode(http.FOUND)
  • twisted/web/util.py

    diff --git a/twisted/web/util.py b/twisted/web/util.py
    index 719b161..ce25a9d 100644
    a b  
    55
    66from cStringIO import StringIO
    77import linecache
    8 import string, re
     8import re
    99import types
    1010
    1111from twisted.python import failure
    htmlReprTypes = {types.DictType: htmlDict, 
    289289
    290290
    291291def htmlIndent(snippetLine):
    292     ret = string.replace(string.replace(html.escape(string.rstrip(snippetLine)),
    293                                   '  ', ' '),
    294                    '\t', '        ')
     292    ret = html.escape(snippetLine.rstrip())\
     293            .replace('  ', ' ')\
     294            .replace('\t', '        ')
    295295    return ret
    296296
    297297def formatFailure(myFailure):