Skip to content

Commit b377573

Browse files
committed
Use static methods in WebKit where appropriate. Added exception info on the application level.
1 parent 550f113 commit b377573

25 files changed

+156
-84
lines changed

.pylintrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ load-plugins=
5454

5555
# Disable the message(s) with the given id(s).
5656
#disable-msg=
57-
disable-msg=R0201,W0122,W0142,W0201,W0212,W0223,W0403,W0603,W0613,W0614,W0621,W0622,W0703
57+
disable-msg=W0122,W0142,W0201,W0212,W0223,W0403,W0603,W0613,W0614,W0621,W0622,W0703
5858

5959

6060
[REPORTS]

DocSupport/PyFontify.py

+21-22
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@
3939

4040
import re, keyword
4141

42-
# Build up a regular expression which will match anything
43-
# interesting, including multi-line triple-quoted strings.
42+
# Build up a regular expression which will match anything interesting,
43+
# including multi-line triple-quoted strings.
4444
commentPat = "#.*"
4545

4646
pat = "q[^\q\n]*(\\\\[\000-\377][^\q\n]*)*q"
@@ -68,21 +68,20 @@
6868
pat = ''.join(pat.split()) # get rid of whitespace
6969
tripleQuotePat = pat.replace("q", "'") + "|" + pat.replace('q', '"')
7070

71-
# Build up a regular expression which matches all and only
72-
# Python keywords. This will let us skip the uninteresting
73-
# identifier references.
74-
# nonKeyPat identifies characters which may legally precede
75-
# a keyword pattern.
71+
# Build up a regular expression which matches all and only Python keywords.
72+
# This will let us skip the uninteresting identifier references.
73+
# nonKeyPat identifies characters which may legally precede a keyword pattern.
7674
nonKeyPat = "(^|[^a-zA-Z0-9_.\"'])"
7775
keywordsPat = '|'.join(keyword.kwlist)
7876
keyPat = nonKeyPat + "(" + keywordsPat + ")" + nonKeyPat
7977

8078
matchPat = keyPat + "|" + commentPat + "|" + tripleQuotePat + "|" + quotePat
8179
matchRE = re.compile(matchPat)
8280

83-
idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*" # Ident w. leading whitespace.
81+
idKeyPat = "[ \t]*[A-Za-z_][A-Za-z_0-9.]*" # ident with leading whitespace
8482
idRE = re.compile(idKeyPat)
8583

84+
8685
def fontify(pytext, searchfrom=0, searchto=None):
8786
if searchto is None:
8887
searchto = len(pytext)
@@ -99,40 +98,40 @@ def fontify(pytext, searchfrom=0, searchto=None):
9998
matchObject = matchRE.search(pytext, end)
10099
if not matchObject:
101100
break
102-
(start, end) = matchObject.span()
101+
start, end = matchObject.span()
103102
match = matchObject.group(0)
104103
c = match[0]
105104
if c not in "#'\"":
106105
# Must have matched a keyword.
107-
if start != searchfrom:
108-
# there's still a redundant char before and after it, strip!
106+
if start == searchfrom:
107+
# this is the first keyword in the text
108+
match = match[:-1] # only a space at the end
109+
else:
110+
# there's still a redundant char before and after it
109111
match = match[1:-1]
110112
start += 1
111-
else:
112-
# this is the first keyword in the text.
113-
# Only a space at the end.
114-
match = match[:-1]
115113
end -= 1
116114
tags.append((keywordTag, start, end, None))
117-
# If this was a defining keyword, look ahead to the
118-
# following identifier.
119-
if match in ["def", "class"]:
115+
# If this was a defining keyword,
116+
# look ahead to the following identifier.
117+
if match in ('def', 'class'):
120118
idMatchObject = idRE.search(pytext, end)
121119
if idMatchObject:
122-
(start, end) = idMatchObject.span()
120+
start, end = idMatchObject.span()
123121
match = idMatchObject.group(0)
124-
tags.append(((match == 'def')
125-
and functionTag or classTag, start, end, None))
122+
tags.append((match == 'def' and functionTag or classTag,
123+
start, end, None))
126124
elif c == "#":
127125
tags.append((commentTag, start, end, None))
128126
else:
129127
tags.append((stringTag, start, end, None))
130128
return tags
131129

130+
132131
def test(path):
133132
f = open(path)
134133
text = f.read()
135134
f.close()
136135
tags = fontify(text)
137136
for tag, start, end, sublist in tags:
138-
print tag, `text[start:end]`, start, end
137+
print tag, repr(text[start:end]), start, end

WebKit/Application.py

+24-12
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,6 @@ def webwareVersionString(self):
360360

361361
def webKitVersion(self):
362362
"""Return the WebKit version as a tuple."""
363-
# @@ 2003-03 ib: This is synced with Webware now, should be removed
364-
# because redundant (and not that useful anyway)
365363
return self._webKitVersion
366364

367365
def webKitVersionString(self):
@@ -498,9 +496,9 @@ def webKitPath(self):
498496
"""The Path of the ``Webware/WebKit/`` directory."""
499497
return self._server.webKitPath()
500498

501-
def name(self):
499+
@staticmethod
500+
def name():
502501
"""The name by which this was started. Usually `AppServer`."""
503-
# @@ 2003-03 ib: unconfirmed
504502
return sys.argv[0]
505503

506504

@@ -584,7 +582,8 @@ def dispatchRawRequest(self, requestDict, strmOut):
584582
request.clearTransaction()
585583
return trans
586584

587-
def createRequestForDict(self, requestDict):
585+
@staticmethod
586+
def createRequestForDict(requestDict):
588587
"""Create request object for a given dictionary.
589588
590589
Create a request object (subclass of `Request`) given the raw
@@ -701,7 +700,8 @@ def runTransaction(self, trans):
701700
self.handleExceptionInTransaction(
702701
sys.exc_info(), trans)
703702

704-
def runTransactionViaServlet(self, servlet, trans):
703+
@staticmethod
704+
def runTransactionViaServlet(servlet, trans):
705705
"""Execute the transaction using the servlet.
706706
707707
This is the `awake`/`respond`/`sleep` sequence of calls, or if
@@ -806,7 +806,8 @@ def includeURL(self, trans, url):
806806
# restore current request
807807
trans.setServlet(request.pop())
808808

809-
def resolveInternalRelativePath(self, trans, url):
809+
@staticmethod
810+
def resolveInternalRelativePath(trans, url):
810811
"""Return the absolute internal path.
811812
812813
Given a URL, return the absolute internal URL.
@@ -830,7 +831,8 @@ def resolveInternalRelativePath(self, trans, url):
830831
parts.append(part)
831832
return '/'.join(parts)
832833

833-
def returnServlet(self, servlet):
834+
@staticmethod
835+
def returnServlet(servlet):
834836
"""Return the servlet to its pool."""
835837
servlet.close()
836838

@@ -893,7 +895,8 @@ def addContext(self, name, path):
893895
"""
894896
self._rootURLParser.addContext(name, path)
895897

896-
def addServletFactory(self, factory):
898+
@staticmethod
899+
def addServletFactory(factory):
897900
"""Add a ServletFactory.
898901
899902
Delegated to the `URLParser.ServletFactoryManager` singleton.
@@ -905,11 +908,20 @@ def contexts(self):
905908
"""Return a dictionary of context-name: context-path."""
906909
return self._rootURLParser._contexts
907910

911+
_exceptionReportAttrNames = ['webwareVersion', 'webwarePath',
912+
'serverSidePath', 'contexts']
913+
908914
def writeExceptionReport(self, handler):
909-
# @@ 2003-02 ib: does anyone care?
910-
pass
915+
"""Write extra information to the exception report.
916+
917+
See `WebKit.ExceptionHandler` for more information.
918+
919+
"""
920+
handler.writeTitle(self.__class__.__name__)
921+
handler.writeAttrs(self, self._exceptionReportAttrNames)
911922

912-
def removePathSession(self, trans):
923+
@staticmethod
924+
def removePathSession(trans):
913925
"""Remove a possible session identifier from the path."""
914926
request = trans.request()
915927
# Try to get automatic path session:

WebKit/AutoReloadingAppServer.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def getFAM(modules):
5353
class FAM(object):
5454
"""Simple File Alteration Monitor based on python-gamin"""
5555

56-
def name(self):
56+
@staticmethod
57+
def name():
5758
return "python-gamin"
5859

5960
def __init__(self):
@@ -100,7 +101,8 @@ def callback(self, filepath, event):
100101
class FAM(object):
101102
"""Simple File Alteration Monitor based on python-fam"""
102103

103-
def name(self):
104+
@staticmethod
105+
def name():
104106
return "python-fam"
105107

106108
def __init__(self):
@@ -269,7 +271,8 @@ def restartIfNecessary(self):
269271
if self._shouldRestart:
270272
self.restart()
271273

272-
def restart(self):
274+
@staticmethod
275+
def restart():
273276
"""Do the actual restart.
274277
275278
Call `shouldRestart` from outside the class.

WebKit/DebugAppServer.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ class DummyRequestQueue(object):
162162

163163
## Overridden methods ##
164164

165-
def put(self, handler):
165+
@staticmethod
166+
def put(handler):
166167
handler.handleRequest()
167168
handler.close()
168169

WebKit/HTTPContent.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,17 @@ def methodNameForAction(self, name):
270270
"""
271271
return name
272272

273-
def urlEncode(self, s):
273+
@staticmethod
274+
def urlEncode(s):
274275
"""Quotes special characters using the % substitutions.
275276
276277
This method does the same as the `urllib.quote_plus()` function.
277278
278279
"""
279280
return Funcs.urlEncode(s) # we could also use urllib.quote
280281

281-
def urlDecode(self, s):
282+
@staticmethod
283+
def urlDecode(s):
282284
"""Turn special % characters into actual characters.
283285
284286
This method does the same as the `urllib.unquote_plus()` function.
@@ -309,7 +311,8 @@ def includeURL(self, url):
309311
"""
310312
self.application().includeURL(self.transaction(), url)
311313

312-
def callMethodOfServlet(self, url, method, *args, **kwargs):
314+
@staticmethod
315+
def callMethodOfServlet(url, method, *args, **kwargs):
313316
"""Call a method of another servlet.
314317
315318
See `Application.callMethodOfServlet` for details.

WebKit/HTTPExceptions.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,8 @@ def __init__(self, realm=None, *args):
217217
def headers(self):
218218
return {'WWW-Authenticate': 'Basic realm="%s"' % self._realm}
219219

220-
# This is for wording mistakes. I'm unsure about their benefit.
220+
# This is for wording mistakes:
221221
HTTPAuthorizationRequired = HTTPAuthenticationRequired
222-
"""
223-
There is also an alias `HTTPAuthorizationRequired`, as it is hard
224-
to distinguish between these two names.
225-
"""
226222

227223

228224
class HTTPSessionExpired(HTTPException):

WebKit/HTTPRequest.py

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ def __init__(self, requestDict=None):
143143
print "Done setting up request, found keys %r" % fieldKeys
144144

145145

146+
## Protocol ##
147+
148+
def protocol(self):
149+
"""Return the name and version of the protocol."""
150+
return self._environ.get('SERVER_PROTOCOL', 'HTTP/1.0')
151+
152+
146153
## Security ##
147154

148155
def isSecure(self):

WebKit/HTTPResponse.py

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ def __init__(self, transaction, strmOut, headers=None):
3535
self._cookies = {}
3636

3737

38+
## Protocol ##
39+
40+
def protocol(self):
41+
"""Return the name and version of the protocol."""
42+
return self._transaction.request().protocol()
43+
44+
3845
## Headers ##
3946

4047
def header(self, name, default=NoDefault):

WebKit/HTTPServer.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""HTTP servlets"""
22

3-
import os, socket, time, errno
3+
import os, socket, errno
44
import BaseHTTPServer
55

66
from ThreadedAppServer import Handler
@@ -57,7 +57,8 @@ def handleRequest(self):
5757
do_MKCOL = do_COPY = do_MOVE = handleRequest
5858
do_PROPFIND = handleRequest
5959

60-
def headersToEnviron(self, headers, env):
60+
@staticmethod
61+
def headersToEnviron(headers, env):
6162
"""Convert headers to environment variables.
6263
6364
Use a simple heuristic to convert all the headers to

WebKit/HTTPServlet.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,12 @@ def respond(self, trans):
6464
self._methodForRequestType[httpMethodName] = method
6565
method(trans)
6666

67-
def notImplemented(self, trans):
67+
@staticmethod
68+
def notImplemented(trans):
6869
trans.response().setStatus(501, 'Not Implemented')
6970

70-
def lastModified(self, trans):
71+
@staticmethod
72+
def lastModified(trans):
7173
"""Get time of last modification.
7274
7375
Return this object's Last-Modified time (as a float),

WebKit/ImportManager.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def load_module(self, name, file, filename, info):
5353
raise
5454
return mod
5555

56-
def find_module(self, name, path=None):
56+
@staticmethod
57+
def find_module(name, path=None):
5758
"""Replaces imp.find_module."""
5859
return imp.find_module(name, path)
5960

WebKit/JSONRPCServlet.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def actions(self):
5656
actions.append('jsonCall')
5757
return actions
5858

59-
def exposedMethods(self):
59+
@staticmethod
60+
def exposedMethods():
61+
"""Return a list or a set of all exposed RPC methods."""
6062
return []
6163

6264
def writeError(self, msg):

WebKit/Message.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,28 @@ def __init__(self):
3434

3535
## Content ##
3636

37-
def contentLength(self):
37+
@staticmethod
38+
def contentLength():
3839
"""Return the length of the message body or -1 if not known."""
3940
return -1
4041

41-
def contentType(self):
42+
@staticmethod
43+
def contentType():
4244
"""Return the MIME type of the message body or None if not known."""
4345
return None
4446

4547

4648
## Protocol ##
4749

48-
def protocol(self):
49-
"""Return the protocol-
50+
@staticmethod
51+
def protocol():
52+
"""Return the protocol.
5053
5154
Returns the name and version of the protocol the message uses
5255
in the form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
5356
5457
"""
55-
# @@ 2000-04-09 ce: Move this down into HTTPSomething subclasses
56-
return 'HTTP/1.0'
58+
return None
5759

5860

5961
## Arguments ##

0 commit comments

Comments
 (0)