Fake SMTPd
Tuesday, November 27th, 2007So I wrote a fake SMTP server for testing DrProject. Check it out.
Thanks,
Dave
So I wrote a fake SMTP server for testing DrProject. Check it out.
Thanks,
Dave
In my code for DrProject/REST, I rather like a trivial 2 lines of Python that ever so thinly wraps around property and is used for decoration.
def Property(func):
return property(doc=func.__doc__, *func())
If it’s not immediately clear what this does, you’re new to Python decorators. Here’s an silly, useless, but otherwise insightful example:
class Test(object):def __init__(self, value):
self.__data = value@Property
def data():
'''Here is my docstring'''
def fget(self):
return self.__data
def fset(self, value):
self.__data = value
def fdel(self):
raise NotImplementedError, "Cannot delete"
return fget, fset, fdel
That’s all,
Dave
reqobj.js - AJAX (XMLHttpRequst) Persistent Request Objects API.
Used for Café Chess (http://play.cafechess.com/js/reqobj.js)
(Note: All functions/variables with an underscore before them are private)
Variables:
unsupported_redirect (string)
Set this to the URL you’d like the script to redirect to if an XMLHttpRequest() object can not be created.
Example:
var unsupported_redirect = 'http://www.example.com/nosupport.html';
Functions:
do_req(postdata, url, callback, timeout_interval) (boolean)
Does a single HTTP POST call. Returns true if the call goes through, false if there is already a call in progress.
Example:
function handle_request(data) {
if (data)
document.write(data);
else
document.write('An error occurred.');
}var response = do_req('post this', 'post.php', 'handle_request', 5000);
if (!reponse)
alert('Request could not be sent');
p_do_req(callforpostdata, url, callback, interval, timeout_interval) (boolean)
Creates a persistent HTTP POST object that runs in the background. Returns true if the object could be created, false if there has already been an object created.
Example:
function handle_request(data) {
if (data)
document.write(data + '<br>');
else
document.write('An error occurred.' + '<br>');
}function get_post_data() {
return 'post_this';
}
var response = p_do_req('get_post_data', 'post.php', 'handle_request', 1250, 5000);
if (!reponse)
alert('Object could not be created');
p_kill_req() (boolean)
Attempts to destroy an already active persistent request object. Returns true if one exists and it is destroyed, returns false is there isn’t one to destroy.
Now that’s that,
Dave
(Note that this was imported from my old blog. If the formatting is messy let me know so I can change it.)