Sunday, May 23, 2010

Cancel turning email address into links in zim

find file /usr/lib/pymodules/python2.6/zim/parsing.py

delete @ pattern

url_re = Re(r'''(
    \b \w[\w\+\-\.]+:// %(c)s* \[ %(c)s+ \] (?: %(c)s+ [\w/] )?  |
    \b \w[\w\+\-\.]+:// %(c)s+ [\w/]                             |
    \b mailto: %(c)s+ \@ %(c)s* \[ %(c)s+ \] (?: %(c)s+ [\w/] )? |
    \b mailto: %(c)s+ \@ %(c)s+ [\w/]
)''' % _classes, re.X)

#url_re = Re(r'''(
#    \b \w[\w\+\-\.]+:// %(c)s* \[ %(c)s+ \] (?: %(c)s+ [\w/] )?  |
#    \b \w[\w\+\-\.]+:// %(c)s+ [\w/]                             |
#    \b mailto: %(c)s+ \@ %(c)s* \[ %(c)s+ \] (?: %(c)s+ [\w/] )? |
#    \b mailto: %(c)s+ \@ %(c)s+ [\w/]                            |
#    \b %(c)s+ \@ %(c)s+ \. \w+ \b
#)''' % _classes, re.X)

Wednesday, May 19, 2010

pylons middleware to strip HTML comments

import re
from webob import Request

class StripHtmlCommentsMiddleware:
    """
    Strips all html comments from response content.
    """
    def __init__(self, app):
        self.app = app
        self.htmlcomments = re.compile(
            '\<![ \r\n\t]*(--([^\-]|[\r\n]|-[^\-])*--[ \r\n\t]*)\>')

    def __call__(self, environ, start_response):
        req = Request(environ)
        rsp = req.get_response(self.app)
        if "text/html" == rsp.content_type:
            new_content = self.htmlcomments.sub('', rsp.unicode_body)
            rsp.unicode_body = new_content
        return rsp(environ, start_response)

Thursday, May 13, 2010

when the default value of args assigned?

>>> def getid():
... print "in getid"
... return uuid.uuid1()
...
>>> class test(object):
... def __init__(self, id = getid()):
... self.id = id
...
in getid
>>>
>>> a = test()
>>>
>>> a.id
UUID('f20f40b2-5e8a-11df-be97-001f161eed5b')
>>>
>>> b = test()
>>>
>>> b.id
UUID('f20f40b2-5e8a-11df-be97-001f161eed5b')

Saturday, May 1, 2010

little tip of associating amule to firefox

sudo apt-get install amule-gnome-support

"network.protocol-handler" items take no  effect on my firefox 3.5...