mirror of
https://github.com/encounter/phantomjs.git
synced 2026-03-30 11:35:11 -07:00
Do a little cleanup
Improved CaseInsensitiveDict a little. Added some more messages for the method patch. Added a break in a for loop
This commit is contained in:
@@ -50,7 +50,7 @@ def debug(debug_type):
|
||||
class CaseInsensitiveDict(dict):
|
||||
def __delitem__(self, key):
|
||||
for dictKey in self:
|
||||
if self.lowerKey(key) == self.lowerKey(dictKey):
|
||||
if self.sameKey(key, dictKey):
|
||||
super(CaseInsensitiveDict, self).__delitem__(dictKey)
|
||||
return
|
||||
|
||||
@@ -58,28 +58,34 @@ class CaseInsensitiveDict(dict):
|
||||
|
||||
def __contains__(self, key):
|
||||
for dictKey in self:
|
||||
if self.lowerKey(key) == self.lowerKey(dictKey):
|
||||
if self.sameKey(key, dictKey):
|
||||
return True
|
||||
return False
|
||||
|
||||
def __getitem__(self, key):
|
||||
for dictKey, dictValue in self.items():
|
||||
if self.lowerKey(key) == self.lowerKey(dictKey):
|
||||
if self.sameKey(key, dictKey):
|
||||
return dictValue
|
||||
|
||||
raise KeyError(key)
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
for dictKey in self:
|
||||
if self.lowerKey(key) == self.lowerKey(dictKey):
|
||||
if self.sameKey(key, dictKey):
|
||||
super(CaseInsensitiveDict, self).__setitem__(dictKey, value)
|
||||
return
|
||||
|
||||
super(CaseInsensitiveDict, self).__setitem__(key, value)
|
||||
|
||||
def lowerKey(self, key):
|
||||
def sameKey(self, key, dictKey):
|
||||
if hasattr(key, 'lower'):
|
||||
return key.lower()
|
||||
return key
|
||||
key = key.lower()
|
||||
if hasattr(dictKey, 'lower'):
|
||||
dictKey = dictKey.lower()
|
||||
|
||||
if key == dictKey:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class MessageHandler(object):
|
||||
|
||||
@@ -101,9 +101,12 @@ class WebServerHandler(BaseHTTPRequestHandler):
|
||||
method error would be returned. Since we patched
|
||||
that out as well, the user can actually handle when
|
||||
a request is or isn't valid through the code.
|
||||
* Headers are automatically handled; they are sent,
|
||||
and end, after the request handling.
|
||||
* Status code is sent after the request handling.
|
||||
* Headers are automatically handled; they get sent,
|
||||
then the content-length gets sent if using HTTP/1.1,
|
||||
and then they end.
|
||||
* We automatically write the body after the end of the
|
||||
headers (otherwise the entire response gets messed up)
|
||||
'''
|
||||
try:
|
||||
self.raw_requestline = self.rfile.readline(65537)
|
||||
@@ -152,6 +155,7 @@ class WebServerHandler(BaseHTTPRequestHandler):
|
||||
response = WebServerResponse(self)
|
||||
|
||||
for server in servers:
|
||||
# verify which server this request is for
|
||||
if self.server == server.httpd:
|
||||
connectionType = Qt.BlockingQueuedConnection
|
||||
if QThread.currentThread() == server.thread():
|
||||
@@ -160,6 +164,7 @@ class WebServerHandler(BaseHTTPRequestHandler):
|
||||
QMetaObject.invokeMethod(server, 'newRequest', connectionType,
|
||||
Q_ARG(WebServerRequest, request),
|
||||
Q_ARG(WebServerResponse, response))
|
||||
break
|
||||
|
||||
def log_message(self, format, *args):
|
||||
qDebug("%s - - %s" % (self.address_string(),
|
||||
|
||||
Reference in New Issue
Block a user