Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5d3306d

Browse files
author
meig
committed
including spider frame primarily
0 parents  commit5d3306d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3507
-0
lines changed

‎pub/__init__.py‎

Whitespace-only changes.

‎pub/common/__init__.py‎

Whitespace-only changes.

‎pub/common/__init__.pyc‎

148 Bytes
Binary file not shown.

‎pub/common/error.py‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/python
2+
# -*- coding:utf-8 -*-
3+
4+
importjson
5+
6+
#protocal exception
7+
ERROR_HTTP_URL_NOT_SUPPORTED= ("00.00","url not supported")
8+
ERROR_HTTP_METHOD_NOT_SUPPORTED= ("00.01","http method not supported")
9+
10+
#businiess base protocal exception
11+
ERROR_JSON_SYNTAX_ERROR= ("01.00","syntax error to json")
12+
13+
#business logic error
14+
ERROR_PARAM_NO_PRIMARY_KEY= ("02.00","primary key missing")
15+
ERROR_PARAM_INVALID_VALUE= ("02.01","invalid value to key")
16+
ERROR_PARAM_NO_KEY= ("02.02","no such key")
17+
ERROR_PARAM_ARG_MISSING= ("02.03","parameter missing")
18+
19+
ERROR_PARAM_INVALID_PARAMETER= ("10.00","invalid parameter parameter")
20+
ERROR_PARAM_INVALID_KEY= ("10.01","invalid field")
21+
ERROR_PARAM_KEY_ALREADY_EXISTS= ("10.02","specified key already exists")
22+
ERROR_PARAM_KEY_NOT_EXIST= ("10.03","specified key not exists")
23+
ERROR_PARAM_UNIQUE_ID_REPEATED= ("10.04","unique identification repeated")
24+
25+
ERROR_SYSTEM_DATABASE= ("20.00","database throwed exception")
26+
27+
#http
28+
ERROR_HTTP_REQUEST_INVALID= ("30.00","invalid http request")
29+
ERROR_HTTP_REQUEST_TIMEOUT= ("30.01","http request time out")
30+
ERROR_HTTP_RESPONSE_INVALID= ("30.02","invalid http response")
31+
ERROR_HTTP_RESPONSE_TIMEOUT= ("30.03","http response time out")
32+
33+
ERROR_INTERNAL_SERVER_ERROR= ("90.00","server internal error")
34+
ERROR_INTERNAL_UNKNOWN_ERROR= ("90.91","unknown error")
35+
36+
37+
defpack_errinfo_json(error,detail=None):
38+
result= {"result":"fail","err":{}}
39+
result["err"]["code"]=error[0]
40+
result["err"]["info"]=error[1]
41+
ifdetail:
42+
result["err"]["parameter"]=detail
43+
result=json.dumps(result)
44+
returnresult
45+
46+
defmatch(code,error_tuple):
47+
returncode==error_tuple[0]
48+
49+
if__name__=="__main__":
50+
printpack_errinfo_json(ERROR_INTERNAL_SERVER_ERROR,"shit")
51+
raw_input()

‎pub/common/error.pyc‎

2.86 KB
Binary file not shown.

‎pub/common/utils.py‎

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
#!/usr/bin/python
2+
# -*- coding:utf-8 -*-
3+
#!/usr/bin/python
4+
# -*- coding:utf-8 -*-
5+
importsys
6+
importos
7+
importplatform
8+
9+
defget_cur_info_within_exception():
10+
f=sys.exc_info()[2].tb_frame.f_back
11+
filename=f.f_code.co_filename
12+
index=filename.rfind('/')
13+
ifindex<0 :
14+
index=filename.rfind('\\')
15+
filename=filename[(index+1):]
16+
lineno=f.f_lineno
17+
return (filename,lineno)
18+
19+
defget_cur_info():
20+
try:
21+
raiseException
22+
except:
23+
returnget_cur_info_within_exception()
24+
25+
##the unit is G (Only works on Linux)
26+
#def get_disk_free(path):
27+
# import os
28+
# import platform
29+
# try:
30+
# stat = os.statvfs(path)
31+
# freesize = stat.f_bsize*stat.f_bfree/(1024*1024*1024)
32+
# return freesize
33+
# except OSError,e:
34+
# return -1
35+
36+
#get all local ip addresses (Only works on Linux)
37+
defget_local_addr():
38+
importplatform
39+
ifplatform.system()=="Linux":
40+
importsubprocess
41+
ip_list= []
42+
content=subprocess.check_output(["/sbin/ifconfig|grep 'inet addr'|awk '{print $2}'"],shell=True)
43+
ifnotcontentorlen(content)==0:
44+
returnip_list
45+
index=0
46+
start=-1
47+
whileindex<len(content):
48+
ifcontent[index]==':':
49+
start=index+1
50+
elifcontent[index]=='\n'andstart!=-1:
51+
ip_list.append(content[start:index])
52+
start=-1
53+
index+=1
54+
returnip_list
55+
elifplatform.system()=="windows":
56+
return []
57+
else:
58+
return []
59+
60+
#verify the ip
61+
defis_ipv4_addr(ip):
62+
segs=ip.split(".")
63+
iflen(segs)!=4:
64+
returnFalse
65+
forseginsegs:
66+
try:
67+
value=int(seg)
68+
ifvalue<0orvalue>255:
69+
returnFalse
70+
exceptValueError,e:
71+
returnFalse
72+
returnTrue
73+
74+
#verify the port
75+
defis_valid_port(port):
76+
try:
77+
value=int(port)
78+
ifvalue<0orvalue>65535:
79+
returnFalse
80+
exceptValueError,e:
81+
returnFalse
82+
returnTrue
83+
84+
#code below is just for testing
85+
deftest():
86+
info=get_cur_info()
87+
printinfo[0]
88+
printinfo[1]
89+
90+
#detect and create directory. WARNNING:this is not an atomic operation!!!!!!!!!!!!!!!
91+
deftest_directory(test_dir):
92+
ifnotos.path.exists(test_dir):
93+
try:
94+
os.mkdir(test_dir)
95+
except:
96+
returnFalse
97+
elifnotos.path.isdir(test_dir):
98+
returnFalse
99+
ifplatform.system()!="Windows"andnotos.access(test_dir,os.R_OK|os.W_OK|os.X_OK):
100+
returnFalse
101+
returnTrue
102+
103+
104+
105+
if__name__=='__main__':
106+
test()
107+
printget_local_addr()
108+
os.system("pause")

‎pub/common/utils.pyc‎

2.95 KB
Binary file not shown.

‎pub/network/syncrequest.py‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/usr/bin/python
2+
# -*- coding:utf-8 -*-
3+
importtornado.httpclient
4+
importjson
5+
6+
7+
defpost_txt(request_url,data):
8+
client=tornado.httpclient.HTTPClient()
9+
try:
10+
request=tornado.httpclient.HTTPRequest(url=request_url,method="POST",body=data)
11+
response=client.fetch(request)
12+
returnresponse
13+
excepttornado.httpclient.HTTPError,e:
14+
returnNone
15+
16+
defpost_json(request_url,json_data):
17+
try:
18+
data=json.dumps(json_data)
19+
returnpost_txt(request_url,data)
20+
except:
21+
returnNone
22+
23+
defget(request_url):
24+
client=tornado.httpclient.HTTPClient()
25+
try:
26+
request=tornado.httpclient.HTTPRequest(url=request_url,method="GET")
27+
response=client.fetch(request)
28+
returnresponse
29+
excepttornado.httpclient.HTTPError,e:
30+
returnNone
31+
32+

‎pub/pirate/__init__.py‎

Whitespace-only changes.

‎pub/pirate/__init__.pyc‎

112 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp