Archives for: May 2005



Permalink 11:20:49 am, by fumanchu Email , 17 words   English (US)
Categories: General

Does your bender have a Lucy Liu?

Sure, you have the Bender wind-up tin toy, but does it have a Lucy Liu head inside?

Bender toy with Lucy Liu photo inside


Permalink 03:31:02 pm, by fumanchu Email , 542 words   English (US)
Categories: Python, WSGI

WSGI gateway for ASP (Microsoft IIS)

Update: I forgot to address buffering.

As I mentioned, I threw together an WSGI wrapper (gateway) for ASP. Here it is. Feedback welcome.

It blanks out SCRIPT_NAME to behave more like Apache. It also handles URL-rewriting, since that's pretty much the only sane way to use ASP with WSGI (or any framework, for that matter).

WSGI wrapper for ASP.

Example Global.asa for a CherryPy app called "mcontrol":

<script language=Python runat=Server> 
def Application_OnStart():
    Application.Contents("multiprocess") = False
    Application.Contents("multithread") = True
    from mcontrol import chpy

Example handler.asp:

from wsgiref.asp_gateway import handler
from cherrypy.wsgiapp import wsgiApp

handler(Application, Request, Response).run(wsgiApp)


import sys
from wsgiref.handlers import BaseCGIHandler

class ASPInputWrapper(object):
    def __init__(self, Request): = Request.BinaryRead
        size = Request.ServerVariables('CONTENT_LENGTH')
        self.remainder = self.size = int(size)
    def read(self, size=-1):
        if size lt; 0:
            size = self.remainder
        content, size =
        self.remainder -= size
        return content
    def readline(self):
        output = []
        while True:
            # Use an internal buffer instead? Still have to check for \n
            char =
            if not char:
            if char in ('\n', '\r'):
        return ''.join(output)
    def readlines(self, hint=-1):
        lines = []
        while True:
            line = self.readline()
            if not line:
        return lines
    def __iter__(self):
        line = self.readline()
        while line:
            yield line
            # Notice this won't prefetch the next line; it only
            # gets called if the generator is resumed.
            line = self.readline()

class handler(BaseCGIHandler):
    def __init__(self, Application, Request, Response, buffering=True):
        # If you set buffering to False, you must not "Enable Buffering" in
        # the current Virtual Directory, NOR in any of its parent containers
        # (directory, site, or server). IIS 5 and 6 buffer by default.
        # See;en-us;Q306805
        # and
        Response.Buffer = buffering
        env = {}
        for name in Request.ServerVariables:
                # names and values are both probably unicode. coerce them.
                env[str(name)] = str(Request.ServerVariables(name))
            except UnicodeEncodeError, x:
                # There's a potential problem lurking here, since some ASP
                # server var's which are required by WSGI may be high ASCII.
                x.args += ((u"Server Variable '%s'" % name),)
                raise x
        multiprocess = str(Application.Contents("multiprocess"))
        multithread = str(Application.Contents("multithread"))
        # You will probably need *some* form of rewriter to use ASP
        # with WSGI, since ASP requires one physical .asp file
        # per requestable-URL; so far, we support one:
        # Handle URL rewriting done by ISAPI_Rewrite Lite.
        # Note that PATH_TRANSLATED is also rewritten, but we
        # don't make any provision for unmunging that.
        old_path = env.get("HTTP_X_REWRITE_URL", None)
        if old_path:
            # Tear off any params.
            env["PATH_INFO"] = old_path.split("?")[0]
        # ASP puts the same values in SCRIPT_NAME and PATH_INFO,
        # for some odd reason. Empty one of them.
        env["SCRIPT_NAME"] = ""
        self.Response = Response
        self._write = Response.Write
    def _flush(self):
    def send_headers(self):
        self.headers_sent = True
        for key, val in self.headers.items():
            self.Response.AddHeader(key, val)


Permalink 12:20:43 pm, by fumanchu Email , 24 words   English (US)
Categories: General

Newsradio DVD just shipped!!!


I know it still says "preorder", but I just got my shipping notice from Amazon. I have been waiting 537 days for this!!!

Hoo! Ray!

Permalink 12:02:07 pm, by fumanchu Email , 191 words   English (US)
Categories: Python, CherryPy, WSGI

CherryPy going WSGI...conservatively

As I announced, I've got a new core with both a wsgiapp and the original native httpserver. They both pass all tests.

[Remi] I don't have any problem with WSGI being the preferred interface. But in that case, we need to package with CherryPy a standalone WSGI HTTP server so that people can still run their sites without any external dependencies if they want to (and the server should support thread-pooling).

I'm about to write a WSGI server for CP, so that we can run the test suite against the wsgi handler without any dependency on wsgiref. I can either:

  1. Write a new WSGI server specifically for CherryPy, or
  2. Rewrite the existing native httpserver to have a WSGI interface.

If I did (2), then CP would no longer have a non-WSGI server. I think I'll avoid that for now--it would be better to grow the new interface, test it thoroughly through at least a minor version or two, and cut the old one later if we find nobody is using it.

I should have a patch ready by Monday. :)

Permalink 10:08:40 am, by fumanchu Email , 23 words   English (US)
Categories: IT

Huffington hotlink hullabaloo

From The Huffington Post

Huffington hotlinking and getting caught by, personally

Teh funny. Here's's notice.


Permalink 02:23:49 pm, by fumanchu Email , 117 words   English (US)
Categories: Python, CherryPy, WSGI

Abstracting the CherryPy webserver

CherryPy had a great IRC meeting today. I had several issues I wanted to discuss going into it—not only were they discussed, but I didn't even have to bring them up! :)

One important outcome was: I'm not the only one who wants the included HTTPServer to be less-strongly coupled to the rest of the framework. So I'll be working on that during the rest of the week; I told everyone I'd have a draft ready by Monday. I'll be asking lots of questions on cherrpy-devel, I'm sure. ;)

My biggest hope is that I can now eliminate the "write callable" hack which I just placed in the new wsgiapp module.


Permalink 02:13:21 pm, by fumanchu Email , 45 words   English (US)
Categories: IT, Python

Content-type: text/x-json

Update: it really should be "text/x-json", not "text/json".

Funny that I haven't seen anyone recommend this before. It sure would make XMLHttpRequest parsing a snap, on both ends.

I think I'll try using that in my CherryPy JSON library.


Permalink 11:18:48 pm, by fumanchu Email , 200 words   English (US)
Categories: Python, WSGI

Discarded WSGI wrappers

Last year I threw together a preliminary mod_python handler for WSGI (with much help from PJE, of course). Looks like Steven Armstrong has polished it up a bit. Good show!

Here's another adaptation. Anyone interested in consolidating them so a standard can be placed in wsgiref itself?

I've also been thinking about an ASP handler again. Now that I've moved my own Python ASP apps to using a URL rewriter, one of the two strikes against an ASP handler is gone.

The other strike was that the server doesn't have any facility for telling the application whether it's being run multithreaded or multiprocess. The mod_python wrapper dealt with this (in versions less than 3.1) by checking PythonOption directives for the necessary parameters; I think an ASP wrapper could do the same by requiring all ASP+WSGI apps to stuff that metadata into Application.Contents within a mandatory Global.asa. Ugly, but it would nicely round out the WSGI-server offerings.


Permalink 04:25:31 pm, by fumanchu Email , 370 words   English (US)
Categories: IT, Cation

RESTful re-treat

I've been looking around recently at Python web frameworks (again). But I keep remembering the reasons why I wrote Cation in the first place:

  1. When all of your users access network files using a Windows network password, it's very nice to be able to use the same password for a web application—this means using IIS on the server side in its "Integrated Windows authentication" mode. Using IIS means rejecting the vast majority of all existing web frameworks.
  2. A persistent server process is a Good Thing, so "dumb" CGI is right out.
  3. Pure ISAPI handlers for IIS generally suck, due mostly to requiring the deployer(!) to compile a DLL, or costs which I-as-framework-developer don't wish to foist upon others.
  4. ...which leaves ASP. Fortunately, Python can be used as an ASP language. Unfortunately, IIS/ASP has no built-in URL rewriting, so you need a separate .asp file for each URL you expect to serve.

I've been re-examining that set of assumptions lately, because I want to develop more RESTful representations of our data. Many of my current web forms suck, because they pull large sets of data in the interest of not-reloading-the-page. The prevalence of XMLHttpRequest is leading me to investigate alternatives.

The problem with a more-RESTful approach is that I'm currently stuck with the side-effects of #4, above; each URL needs a separate .asp file. So, if I want to publish the URL /app/directory/45987, I've got to create a file named /app/directory/45987! This is Not Good. In addition, I don't think I can serve a resource without a file extension (like ".asp"), but don't quote me on that one.

Therefore, it looks like the choices are:

  1. Ditch IIS and work solely with Apache. This may make some users mad when they get passwords out of sync. But it would mean I could drop my web framework completely and develop a REST+JSON plugin for an existing, major Python framework.

  2. Bite the bullet and use ISAPI rewriting. I found a simple ISAPI rewriter today: ISAPI_Rewrite, which has a freeware "Lite" version.

Tough choices like this make me pine for my own personal hypnotoad.

Permalink 09:48:52 am, by fumanchu Email , 17 words   English (US)
Categories: IT

The new VAIO must-have accessory

For those new ultralight, compact, "portable" VAIO's. Combination docking station and wheeled luggage. Only $599.99! Supplies are limited.

Hand truck for VAIO laptop

Permalink 09:41:31 am, by fumanchu Email , 41 words   English (US)
Categories: General

In the Amor kitchen

Shawn asked if the "development cage" still existed. Short answer: no. Long answer: no, but Hilary almost killed herself taking it out.

So now we have a lovely kitchen/lunchroom.

Kitchen area of HQ



Permalink 03:29:19 pm, by fumanchu Email , 25 words   English (US)
Categories: General


Moramor. It doesn't mean anything...yet. I just wanted to get the term out there. Hopefully I'll be the #1 hit on Google for it, soon. ;)


Permalink 11:37:01 pm, by fumanchu Email , 80 words   English (US)
Categories: IT

The Software shall be used for Good, not Evil


From the JSON-for-Javascript library:

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The Software shall be used for Good, not Evil.

May 2005
Sun Mon Tue Wed Thu Fri Sat
 << < Current> >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        


The requested Blog doesn't exist any more!

XML Feeds

powered by b2evolution