-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlibtahoe.py
More file actions
61 lines (52 loc) · 1.39 KB
/
libtahoe.py
File metadata and controls
61 lines (52 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import re
'''
victor:
help to fetch proper service section by check requesting hostname
an experience: checking remote ip is not a good way, because it is always
127.0.0.1 when request by a domain name instead an ip address
usage:
- in view:
from libtahoe import *
if isdev(request):
do something
- in template
<%! from libtahoe import isdev,isdemo1,isdemo2 %>
% if isdemo1(request):
do something
% endif
'''
def isdev(request):
ip=request.META['REMOTE_ADDR']
dn=request.META['HTTP_HOST'] # request.get_host()
if re.match('127.0.0.1',dn):
return True
if re.match('localhost',dn):
return True
if re.match('www0',dn):
return True
if re.match('studio0',dn):
return True
def isdemo1(request):
ip=request.META['REMOTE_ADDR']
dn=request.META['HTTP_HOST'] # request.get_host()
if re.match('www1',dn):
return True
if re.match('studio1',dn):
return True
if re.match('l1',dn):
return True
if re.match('c1',dn):
return True
if re.match('demo',dn):
return True
def isdemo2(request):
ip=request.META['REMOTE_ADDR']
dn=request.META['HTTP_HOST'] # request.get_host()
if re.match('www1',dn):
return True
if re.match('studio1',dn):
return True
if re.match('l1',dn):
return True
if re.match('c1',dn):
return True