Zhang Huangbin
unread,Nov 15, 2009, 10:44:31 AM11/15/09Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to web.py
Hi, all.
I got a strange url mapping issue in my app, but i don't know why it
happened. Please help me to find the root case. Thanks :)
Error msg:
----
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/web/application.py", line
241, in process
return self.handle()
File "/usr/lib/python2.4/site-packages/web/application.py", line
232, in handle
return self._delegate(fn, self.fvars, args)
File "/usr/lib/python2.4/site-packages/web/application.py", line
407, in _delegate
mod = __import__(mod, globals(), locals(), [""])
ImportError: No module named /antispam/blacklist/helo/page/
controllers.policyd.wblist
----
URL mapping:
----
re_ip = r"""\b25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?\.25[0-5]|2[0-4]
[0-9]|[01]?[0-9][0-9]?|%\.25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|%\.25
[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|%$"""
re_sender = r'[\w\-][\w\-\.]*@[\w\-][\w\-\.]+[a-zA-Z]{1,4}'
re_dnsname = r'[\w\-][\w\-\.]+[a-zA-Z]{1,4}'
re_ip_f = r"""\b\d{1,3}|%$"""
urls = (
'/antispam',
'controllers.policyd.wblist.Whitelist',
#
# @/page/0 List ALL records without offset and limit in SQL.
#
# Whitelist: IP addresses.
'/antispam/(whitelist)',
'controllers.policyd.wblist.Whitelist',
'/antispam/(whitelist)/(ip)',
'controllers.policyd.wblist.Whitelist',
'/antispam/(whitelist)/(ip)/record/(%s)/(%s)/(%s)/(%s)' % (
re_ip_f, re_ip_f, re_ip_f, re_ip_f, ),
'controllers.policyd.wblist.WhitelistView',
'/antispam/(whitelist)/(ip)/page/([01-9]\d*)',
'controllers.policyd.wblist.Whitelist',
# Whitelist: Sender addresses.
'/antispam/(whitelist)/(sender)',
'controllers.policyd.wblist.Whitelist',
'/antispam/(whitelist)/(sender)/%s' % re_ip,
'controllers.policyd.wblist.Whitelist',
'/antispam/(whitelist)/(sender)/page/([01-9]\d*)',
'controllers.policyd.wblist.Whitelist',
# Whitelist: DNS name.
'/antispam/(whitelist)/(dnsname)',
'controllers.policyd.wblist.Whitelist',
'/antispam/(whitelist)/(dnsname)/%s' % re_dnsname,
'controllers.policyd.wblist.Whitelist',
'/antispam/(whitelist)/(dnsname)/page/([01-9]\d*)',
'controllers.policyd.wblist.Whitelist',
# Blacklist: IP addresses.
'/antispam/(blacklist)',
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(ip)',
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(ip)/%s' % re_ip,
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(ip)/page/([01-9]\d*)',
'controllers.policyd.wblist.Blacklist',
# Blacklist: Sender addresses.
'/antispam/(blacklist)/(sender)',
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(sender)/%s' % re_ip,
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(sender)/page/([01-9]\d*)',
'controllers.policyd.wblist.Blacklist',
# Blacklist: DNS name.
'/antispam/(blacklist)/(dnsname)',
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(dnsname)/%s' % re_dnsname,
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(dnsname)/page/([01-9]\d*)',
'controllers.policyd.wblist.Blacklist',
# Blacklist: DNS name.
'/antispam/(blacklist)/(helo)',
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(helo)/page/([01-9]\d*)',
'controllers.policyd.wblist.Blacklist',
'/antispam/(blacklist)/(helo)/(%s)' % re_dnsname,
'controllers.policyd.wblist.Blacklist',
)
----
Directory structure:
----
$ find controllers/policyd
controllers/policyd
controllers/policyd/__init__.py
controllers/policyd/urls.py
controllers/policyd/wblist.py
----
Content of controllers/policyd/wblist.py.
class Whitelist works fine, but class Blacklist doesn't work as
expected, error msg is pasted above.
----
import sys
import web
from web import ctx, render_policyd as render
from controllers import base
from libs.policyd import whitelist, blacklist
cfg = web.iredconfig
session = web.config.get('_session')
whitelistLib = whitelist.Whitelist()
blacklistLib = blacklist.Blacklist()
class Whitelist:
@base.require_global_admin
def GET(self, listname='whitelist', listcategory='ip',
cur_page=1,):
self.listname = web.safestr(listname)
self.listcategory = web.safestr(listcategory)
self.cur_page = int(cur_page)
total, entries = whitelistLib.list
(listcategory=self.listcategory, cur_page=self.cur_page,)
if self.cur_page > total and self.cur_page != 1:
# Redirect to last page if cur_page > total
if total % session.pagesizelimit > 0:
page = total/session.pagesizelimit + 1
else:
page = total/session.pagesizelimit
web.seeother(ctx.homepath + '/%s/%s/page/%d' % (listname,
listcategory, page))
else:
return render.wblist(
total=total,
entries=entries,
listname=self.listname,
listcategory=self.listcategory,
cur_page=self.cur_page,
)
class Blacklist:
@base.require_global_admin
def GET(self, listname='blacklist', listcategory='ip',
cur_page=1,):
self.listname = web.safestr(listname)
self.listcategory = web.safestr(listcategory)
self.cur_page = int(cur_page)
total, entries = blacklistLib.list
(listcategory=self.listcategory, cur_page=self.cur_page)
if self.cur_page > total and self.cur_page != 1:
# Redirect to last page if cur_page > total
if total % session.pagesizelimit > 0:
page = total/session.pagesizelimit + 1
else:
page = total/session.pagesizelimit
web.seeother(ctx.homepath + '/%s/%s/page/%d' % (listname,
listcategory, page))
else:
return render.wblist(
total=total,
entries=entries,
listname=self.listname,
listcategory=self.listcategory,
cur_page=self.cur_page,
)
----