nutools/lib/pyulib/devel/web.py-0.33.patch

166 lines
6.1 KiB
Diff

diff -ur -x .svn -x '*.pyc' web.py-0.33/web/application.py ../src/ulib/ext/web/application.py
--- web.py-0.33/web/application.py 2009-10-28 09:45:10.000000000 +0400
+++ ../src/ulib/ext/web/application.py 2009-11-18 08:54:43.000000000 +0400
@@ -352,7 +352,7 @@
ctx.realhome = ctx.home
ctx.ip = env.get('REMOTE_ADDR')
ctx.method = env.get('REQUEST_METHOD')
- ctx.path = env.get('PATH_INFO')
+ ctx.path = env.get('PATH_INFO') or ''
# http://trac.lighttpd.net/trac/ticket/406 requires:
if env.get('SERVER_SOFTWARE', '').startswith('lighttpd/'):
ctx.path = lstrips(env.get('REQUEST_URI').split('?')[0], ctx.homepath)
@@ -376,6 +376,15 @@
ctx.app_stack = []
+ _handler_configurator = None
+
+ def set_handler_configurator(self, handler_configurator):
+ self._handler_configurator = handler_configurator
+
+ def configure_handler(self, handler):
+ if self._handler_configurator is not None:
+ self._handler_configurator(handler)
+
def _delegate(self, f, fvars, args=[]):
def handle_class(cls):
meth = web.ctx.method
@@ -383,7 +392,9 @@
meth = 'GET'
if not hasattr(cls, meth):
raise web.nomethod(cls)
- tocall = getattr(cls(), meth)
+ handler = cls()
+ self.configure_handler(handler)
+ tocall = getattr(handler, meth)
return tocall(*args)
def is_class(o): return isinstance(o, (types.ClassType, type))
diff -ur -x .svn -x '*.pyc' web.py-0.33/web/httpserver.py ../src/ulib/ext/web/httpserver.py
--- web.py-0.33/web/httpserver.py 2009-10-28 09:45:10.000000000 +0400
+++ ../src/ulib/ext/web/httpserver.py 2009-11-18 08:54:44.000000000 +0400
@@ -1,6 +1,8 @@
__all__ = ["runsimple"]
import sys, os
+from os import path
+import urlparse, posixpath, urllib
from SimpleHTTPServer import SimpleHTTPRequestHandler
import webapi as web
@@ -126,7 +128,7 @@
self.app = func
self.serverShuttingDown = 0
- print "http://%s:%d/" % server_address
+ #print "http://%s:%d/" % server_address
WSGIServer(func, server_address).serve_forever()
def runsimple(func, server_address=("0.0.0.0", 8080)):
@@ -141,7 +143,7 @@
server = WSGIServer(server_address, func)
- print "http://%s:%d/" % server_address
+ #print "http://%s:%d/" % server_address
try:
server.start()
except KeyboardInterrupt:
@@ -161,6 +163,19 @@
self.environ = environ
self.start_response = start_response
+ def translate_path(self, path):
+ path = urlparse.urlparse(path)[2]
+ path = posixpath.normpath(urllib.unquote(path))
+ words = path.split('/')
+ words = filter(None, words)
+ path = web.config.get('BASEDIR', os.getcwd())
+ for word in words:
+ _, word = os.path.splitdrive(word)
+ _, word = os.path.split(word)
+ if word in (os.curdir, os.pardir): continue
+ path = os.path.join(path, word)
+ return path
+
def send_response(self, status, msg=""):
self.status = str(status) + " " + msg
diff -ur -x .svn -x '*.pyc' web.py-0.33/web/__init__.py ../src/ulib/ext/web/__init__.py
--- web.py-0.33/web/__init__.py 2009-10-28 09:45:10.000000000 +0400
+++ ../src/ulib/ext/web/__init__.py 2009-11-18 08:54:43.000000000 +0400
@@ -26,7 +26,7 @@
from debugerror import *
from application import *
from browser import *
-import test
+#import test
try:
import webopenid as openid
except ImportError:
diff -ur -x .svn -x '*.pyc' web.py-0.33/web/template.py ../src/ulib/ext/web/template.py
--- web.py-0.33/web/template.py 2009-10-28 09:45:10.000000000 +0400
+++ ../src/ulib/ext/web/template.py 2009-11-18 10:00:17.314384800 +0400
@@ -382,6 +382,21 @@
readline = iter([text]).next
tokens = tokenize.generate_tokens(readline)
return [t[1] for t in tokens]
+
+ def tabsout(self, line, indent):
+ indent = indent.replace('\t', ' ')
+ re_tabs = re_compile(r'^\t+')
+ mo = re_tabs.match(line)
+ if mo is None:
+ return line, 0
+ else:
+ actual_nbtabs = len(mo.group(0))
+ nbtabs = max(0, actual_nbtabs - len(indent) / 4)
+ return re_compile(r'\t').sub(' ', line, actual_nbtabs), nbtabs
+
+ def tabsin(self, line, nbtabs):
+ if nbtabs > 0: line = re_compile(r' ').sub('\t', line, nbtabs)
+ return line
def read_indented_block(self, text, indent):
r"""Read a block of text. A block is what typically follows a for or it statement.
@@ -400,11 +415,13 @@
block = ""
while text:
- line, text2 = splitline(text)
+ oline, text2 = splitline(text)
+ line, nbtabs = self.tabsout(oline, indent)
if line.strip() == "":
block += '\n'
elif line.startswith(indent):
- block += line[len(indent):]
+ line = line[len(indent):]
+ block += self.tabsin(line, nbtabs)
else:
break
text = text2
@@ -446,10 +463,12 @@
return first_indent or ""
# find the indentation of the block by looking at the first line
+ text, nbtabs = self.tabsout(text, begin_indent)
first_indent = find_indent(text)[len(begin_indent):]
indent = begin_indent + min(first_indent, INDENT)
block, text = self.read_indented_block(text, indent)
+ text = self.tabsin(text, nbtabs)
return self.create_block_node(keyword, stmt, block, begin_indent), text
@@ -520,7 +539,7 @@
return self.defwith + self.suite.emit(indent + INDENT)
def __repr__(self):
- return "<defwith: %s, %s>" % (self.defwith, self.nodes)
+ return "<defwith: %s, %s>" % (self.defwith, self.suite)
class TextNode:
def __init__(self, value):
Seulement dans ../src/ulib/ext/web/wsgiserver: LICENSE.txt