Explorar el Código

[wsgi] [minor] replace os.environ by webnotes.get_request_header

version-14
Rushabh Mehta hace 11 años
padre
commit
ca5d492d8d
Se han modificado 7 ficheros con 21 adiciones y 18 borrados
  1. +3
    -3
      webnotes/__init__.py
  2. +4
    -4
      webnotes/auth.py
  3. +1
    -1
      webnotes/handler.py
  4. +1
    -1
      webnotes/modules/patch_handler.py
  5. +8
    -5
      webnotes/sessions.py
  6. +3
    -3
      webnotes/utils/__init__.py
  7. +1
    -1
      website/doctype/blog_post/blog_feed.py

+ 3
- 3
webnotes/__init__.py Ver fichero

@@ -188,11 +188,11 @@ def connect(db_name=None, password=None):
import webnotes.profile
local.user = webnotes.profile.Profile('Administrator')
def get_env_vars(env_var):
def get_request_header(key, default=None):
import os
return os.environ.get(env_var,'None')
return os.environ.get(key, default)

remote_ip = get_env_vars('REMOTE_ADDR') #Required for login from python shell
remote_ip = get_request_header('REMOTE_ADDR') #Required for login from python shell
logger = None
def get_db_password(db_name):


+ 4
- 4
webnotes/auth.py Ver fichero

@@ -14,19 +14,19 @@ class HTTPRequest:
def __init__(self):

# Get Environment variables
self.domain = webnotes.get_env_vars('HTTP_HOST')
self.domain = webnotes.get_request_header('HTTP_HOST')
if self.domain and self.domain.startswith('www.'):
self.domain = self.domain[4:]

# language
self.set_lang(webnotes.get_env_vars('HTTP_ACCEPT_LANGUAGE'))
self.set_lang(webnotes.get_request_header('HTTP_ACCEPT_LANGUAGE'))
webnotes.remote_ip = webnotes.get_env_vars('REMOTE_ADDR')
webnotes.remote_ip = webnotes.get_request_header('REMOTE_ADDR')

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

webnotes.request_method = webnotes.get_env_vars("REQUEST_METHOD")
webnotes.request_method = webnotes.get_request_header("REQUEST_METHOD")
# override request method. All request to be of type POST, but if _type == "POST" then commit
if webnotes.form_dict.get("_type"):


+ 1
- 1
webnotes/handler.py Ver fichero

@@ -210,7 +210,7 @@ def json_handler(obj):
(type(obj), repr(obj))

def accept_gzip():
if "gzip" in os.environ.get("HTTP_ACCEPT_ENCODING", ""):
if "gzip" in webnotes.get_request_header("HTTP_ACCEPT_ENCODING", ""):
return True

def compressBuf(buf):


+ 1
- 1
webnotes/modules/patch_handler.py Ver fichero

@@ -66,7 +66,7 @@ def execute_patch(patchmodule, method=None, methodargs=None):
tb = webnotes.getTraceback()
log(tb)
import os
if os.environ.get('HTTP_HOST'):
if webnotes.get_request_header('HTTP_HOST'):
add_to_patch_log(tb)

block_user(False)


+ 8
- 5
webnotes/sessions.py Ver fichero

@@ -98,10 +98,10 @@ class Session:
self.data['user'] = webnotes.local.login_manager.user
self.data['sid'] = sid
self.data['data']['user'] = webnotes.local.login_manager.user
self.data['data']['session_ip'] = os.environ.get('REMOTE_ADDR')
self.data['data']['session_ip'] = webnotes.get_request_header('REMOTE_ADDR')
self.data['data']['last_updated'] = webnotes.utils.now()
self.data['data']['session_expiry'] = self.get_expiry_period()
self.data['data']['session_country'] = get_geo_ip_country(os.environ.get('REMOTE_ADDR'))
self.data['data']['session_country'] = get_geo_ip_country(webnotes.get_request_header('REMOTE_ADDR'))
# insert session
webnotes.conn.begin()
@@ -247,7 +247,10 @@ def get_geo_ip_country(ip_addr):
import os
from webnotes.utils import get_base_path

geo_ip_file = os.path.join(get_base_path(), "lib", "data", "GeoIP.dat")
geo_ip = pygeoip.GeoIP(geo_ip_file, pygeoip.MEMORY_CACHE)
try:
geo_ip_file = os.path.join(get_base_path(), "lib", "data", "GeoIP.dat")
geo_ip = pygeoip.GeoIP(geo_ip_file, pygeoip.MEMORY_CACHE)
return geo_ip.country_name_by_addr(ip_addr)
except Exception, e:
return

return geo_ip.country_name_by_addr(ip_addr)

+ 3
- 3
webnotes/utils/__init__.py Ver fichero

@@ -71,13 +71,13 @@ def get_request_site_address(full_address=False):
host_name = conf.host_name
else:
try:
protocol = 'HTTPS' in os.environ.get('SERVER_PROTOCOL') and 'https://' or 'http://'
host_name = protocol + os.environ.get('HTTP_HOST')
protocol = 'HTTPS' in webnotes.get_request_header('SERVER_PROTOCOL') and 'https://' or 'http://'
host_name = protocol + webnotes.get_request_header('HTTP_HOST')
except TypeError:
return 'http://localhost'

if full_address:
return host_name + os.environ.get("REQUEST_URI", "")
return host_name + webnotes.get_request_header("REQUEST_URI", "")
else:
return host_name



+ 1
- 1
website/doctype/blog_post/blog_feed.py Ver fichero

@@ -35,7 +35,7 @@ def generate():
from webnotes.model.doc import Document
from webnotes.utils import escape_html
host = (os.environ.get('HTTPS') and 'https://' or 'http://') + os.environ.get('HTTP_HOST')
host = (webnotes.get_request_header('HTTPS') and 'https://' or 'http://') + webnotes.get_request_header('HTTP_HOST')
items = ''
blog_list = webnotes.conn.sql("""\


Cargando…
Cancelar
Guardar