Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
urls can now have keyword params parsed out i.e. /contact/1
- Loading branch information
Jon Dunleavy
committed
Apr 13, 2012
1 parent
0bc7653
commit 34be90f
Showing
4 changed files
with
61 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__author__ = 'jond' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
__author__ = 'jond' | ||
|
||
from PySide import QtCore, QtNetwork | ||
|
||
class FakeReply(QtNetwork.QNetworkReply): | ||
""" | ||
The reply class that is used when a url is to be dealt with by the application | ||
and is not to be dealt with by the usual method | ||
""" | ||
def __init__(self, parent, request, operation, f, args={}): | ||
""" | ||
@type args: dict | ||
""" | ||
QtNetwork.QNetworkReply.__init__(self, parent) | ||
self.setRequest(request) | ||
self.setUrl(request.url()) | ||
self.setOperation(operation) | ||
self.open(self.ReadOnly | self.Unbuffered) | ||
# if any are lists of 1 item then just send the item through | ||
for k, v in args.items(): | ||
if type(v) is type([]): | ||
if len(v) is 1: | ||
args[k] = v[0] | ||
self.content = f(**args) | ||
self.offset = 0 | ||
|
||
self.setHeader(QtNetwork.QNetworkRequest.ContentTypeHeader, "application/json; charset=UTF-8") | ||
self.setHeader(QtNetwork.QNetworkRequest.ContentLengthHeader, len(self.content)) | ||
|
||
QtCore.QTimer.singleShot(0, self, QtCore.SIGNAL("readyRead()")) | ||
QtCore.QTimer.singleShot(0, self, QtCore.SIGNAL("finished()")) | ||
|
||
|
||
def abort(self): | ||
pass | ||
|
||
def bytesAvailable(self): | ||
return len(self.content) - self.offset | ||
|
||
def isSequential(self): | ||
return True | ||
|
||
def readData(self, maxSize): | ||
if self.offset < len(self.content): | ||
end = min(self.offset + maxSize, len(self.content)) | ||
data = self.content[self.offset:end] | ||
self.offset = end | ||
return data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters