瀏覽代碼

[wsgi] [minor]

version-14
Rushabh Mehta 12 年之前
父節點
當前提交
6a59a39006
共有 6 個檔案被更改,包括 32 行新增43 行删除
  1. +5
    -3
      webnotes/__init__.py
  2. +21
    -32
      webnotes/app.py
  3. +1
    -3
      webnotes/auth.py
  4. +3
    -3
      webnotes/handler.py
  5. +1
    -1
      webnotes/sessions.py
  6. +1
    -1
      webnotes/webutils.py

+ 5
- 3
webnotes/__init__.py 查看文件

@@ -189,9 +189,11 @@ def connect(db_name=None, password=None):
local.user = webnotes.profile.Profile('Administrator')
def get_request_header(key, default=None):
return webnotes.request.headers.get(key, default)

remote_ip = get_request_header('REMOTE_ADDR') #Required for login from python shell
try:
return request.headers.get(key, default)
except Exception, e:
return None
logger = None
def get_db_password(db_name):


+ 21
- 32
webnotes/app.py 查看文件

@@ -15,39 +15,25 @@ local_manager = LocalManager([webnotes.local])

@Request.application
def application(request):
path = os.path.join("public", request.path[1:])
if os.path.exists(path) and not os.path.isdir(path) and not path.endswith(".py"):
with open(path, "r") as static:
content = static.read()
response = Response()
response.data = content
response.headers["Content-type"] = mimetypes.guess_type(path)[0]
return response
webnotes.local.request = request
webnotes.init()
webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
for k, v in (request.form or request.args).iteritems() })
webnotes.local._response = Response()

try:
webnotes.http_request = webnotes.auth.HTTPRequest()
except webnotes.AuthenticationError, e:
pass
if webnotes.form_dict.cmd:
webnotes.handler.handle()
else:
webnotes.local.request = request
webnotes.init()
webnotes.local.form_dict = webnotes._dict({ k:v[0] if isinstance(v, (list, tuple)) else v \
for k, v in (request.form or request.args).iteritems() })
webnotes.local._response = Response()

try:
webnotes.http_request = webnotes.auth.HTTPRequest()
except webnotes.AuthenticationError, e:
pass

# cookies
print request.form
if webnotes.form_dict.cmd:
webnotes.handler.handle()
else:
webnotes.webutils.render(webnotes.request.path[1:])
return webnotes._response
webnotes.webutils.render(webnotes.request.path[1:])
return webnotes._response

application = local_manager.make_middleware(application)

@@ -55,4 +41,7 @@ if __name__ == '__main__':
import sys
from werkzeug.serving import run_simple

run_simple('localhost', 8000, application, use_reloader=True, use_debugger=True, use_evalex=True)
run_simple('localhost', 8000, application, use_reloader=True,
use_debugger=True, use_evalex=True, static_files = {
"/": os.path.join(os.path.dirname(__file__), "..", "..", "public")
})

+ 1
- 3
webnotes/auth.py 查看文件

@@ -21,8 +21,6 @@ class HTTPRequest:
# language
self.set_lang(webnotes.get_request_header('HTTP_ACCEPT_LANGUAGE'))
webnotes.remote_ip = webnotes.get_request_header('REMOTE_ADDR')

# load cookies
webnotes.local.cookie_manager = CookieManager()

@@ -173,7 +171,7 @@ class LoginManager:
ip_list = [i.strip() for i in ip_list]

for ip in ip_list:
if webnotes.remote_ip.startswith(ip):
if webnotes.get_request_header('REMOTE_ADDR', '').startswith(ip):
return
webnotes.msgprint('Not allowed from this IP Address')


+ 3
- 3
webnotes/handler.py 查看文件

@@ -165,14 +165,14 @@ def print_csv():
"text/csv; charset: utf-8"
webnotes._response.headers["Content-Disposition"] = \
"attachment; filename=%s.csv" % webnotes.response['doctype'].replace(' ', '_')
webnotes._response.response = webnotes.response['result']
webnotes._response.data = webnotes.response['result']

def print_raw():
webnotes._response.headers["Content-Type"] = \
mimetypes.guess_type(webnotes.response['filename'])[0] or "application/unknown"
webnotes._response.headers["Content-Disposition"] = \
"filename=%s" % webnotes.response['filename'].replace(' ', '_')
webnotes._response.response = webnotes.response['filecontent']
webnotes._response.data = webnotes.response['filecontent']

def make_logs():
"""make strings for msgprint and errprint"""
@@ -196,7 +196,7 @@ def print_zip(response):
webnotes._response.headers["Content-Encoding"] = "gzip"
webnotes._response.headers["Content-Length"] = str(len(response))
webnotes._response.response = response
webnotes._response.data = response
def json_handler(obj):
"""serialize non-serializable data for json"""


+ 1
- 1
webnotes/sessions.py 查看文件

@@ -109,7 +109,7 @@ class Session:

# update profile
webnotes.conn.sql("""UPDATE tabProfile SET last_login = '%s', last_ip = '%s'
where name='%s'""" % (webnotes.utils.now(), webnotes.remote_ip, self.data['user']))
where name='%s'""" % (webnotes.utils.now(), webnotes.get_request_header('REMOTE_ADDR'), self.data['user']))
webnotes.conn.commit()
# set cookies to write


+ 1
- 1
webnotes/webutils.py 查看文件

@@ -20,7 +20,7 @@ def render(page_name):
html = render_page('error')
webnotes._response.headers["Content-Type"] = "text/html; charset: utf-8"
webnotes._response.response = html
webnotes._response.data = html

def render_page(page_name):
"""get page html"""


Loading…
取消
儲存