simple (I hope!) problem

Jean-Michel Pichavant jeanmichel at
Tue Aug 3 12:09:21 CEST 2010

samwyse wrote:
> I'm writing for the Google app engine and have stubbed my toe yet
> again on a simple obstacle.  Non-trivial app engines programs require
> the import of several modules that aren't normally in my PYTHONPATH.
> I'd like to be able to test my code outside of the app engine
> framework.  I've tried several solutions in the past that worked but
> weren't particularly elegant or portable.  Now I've had a new idea.
> Here's my latest attempt:
> import os, re
> if __name__ == '__main__':
>     pass
> else
>     from google.appengine.ext import webapp
>     register = webapp.template.create_template_register()
> This works great, except my code makes use of the resister object in
> several places, like this:
> register.filter(emptylines)
> Fortunately, I don't need the functionality of the object, I just want
> something that won't generate an error when I use it.  So, what is the
> quickest way to to create such an object (replacing the 'pass' in my
> first snippet).  My solution is this:
>     class C:
>         def filter(self, *args, **kwds):
>             pass
>     register = C()
> but it seems like I should be able to do something "better", as
> measured by lines of code, faking more than just a 'filter' method, or
> both.  Any ideas?  Thanks!

here is a class that accepts any method call without generating an error:

class Stub(object):
    def stub(*arg, **kwarg):
    def __getattribute__(self, name):
        return Stub.stub

s = Stub()'bar')'', '', 5)


More information about the Python-list mailing list