ZoomQuiet avatar ZoomQuiet committed 9707864

fixed KVDB key usage

Comments (0)

Files changed (1)

 # -*- coding: utf-8 -*-
-VERSION = "urisaok v11.12.28"
-'''网址云RESTful API 包装服务:
-依赖:
-    + bottle
-    + SAE
-'''
+VERSION = "urisaok v12.4.25"
 import sae
 import urllib2 as urilib
 from bottle import Bottle, request
 
-import base64
-import time
-from hashlib import md5
-from base64 import urlsafe_b64encode
+app = Bottle()
+
+@app.route('/')
+def hello():
+    return '''Hollo, there! 
+    - Bottle @ SAE 4 urisaok!
+    - {v12.04.23} from YY talking..
+    usage:
+    $ curl -d 'uri=hrrp://sina.com' http://urisaok.sinaapp.com/qchk
+    or
+    $ curl -d 'uri=hrrp://sina.com' http://urisaok.sinaapp.com/chk
+                    +-- want check url
+    '''
 
 class Borg():
     '''base http://blog.youxu.info/2010/04/29/borg
 # init all var
 cfg = Borg()
 
-app = Bottle()
-
-@app.route('/')
-def hello():
-    return '''Hollo, there! 
-    - Bottle @ SAE 4 urisaok!
-    - {v12.04.23} from YY talking..
-    usage:
-    $ curl -d 'uri=hrrp://sina.com' http://urisaok.sinaapp.com/qchk
-    or
-    $ curl -d 'uri=hrrp://sina.com' http://urisaok.sinaapp.com/chk
-                    +-- want check url
-    '''
-
 @app.route('/chk/', method="POST")
 @app.route('/chk', method="POST")
 def chk():
     uri = request.forms.get('uri')
-    #print uri
     result = _askCloud(cfg.APITYPE, uri)
     return "/chk:: %s"% cfg.PHISHTYPE[str(result)]
 
         uri = url[0]
     else:
         uri = url[2]
-    k = urlsafe_b64encode(uri)
+    #k = urlsafe_b64encode(uri)
+    k = uri
     print k
     import sae.kvdb
+    #print "kv.get_info() %s"% kv.get_info()
     kv = sae.kvdb.KVClient()
-    print "kv.get_info() %s"% kv.get_info()
     v = kv.get(k)
     print "kv.get(uri)~ type=%s var=%s"%(type(v),v)
     if None == v:
         return "/qchk(KSC)::\t %s" % cfg.PHISHTYPE[str(result)]
     else:
         return "/qchk(KVDB)::\t %s" % cfg.PHISHTYPE[str(v)]
-    #result = _askCloud(cfg.APITYPE, uri)
-    #return "/qchk"
 
+import base64
+import time
+from hashlib import md5
+from base64 import urlsafe_b64encode
 def _askCloud(api_path, url):
     args = __genQueryArgs(api_path, url)
-    key_values = [("%s=%s" % (k, v)) for k, v in args.iteritems()]
-    api_url = "http://%s/%s/"% (cfg.OPEN_HOST, api_path) + "?" + "&".join(key_values)
-    #print api_url
+    api_url = "http://%s%s?%s"% (cfg.OPEN_HOST, cfg.APITYPE ,args)
+    print api_url
     result = eval(urilib.urlopen(api_url).read())
-    #print type(result)
-    #print result
+    print result
     if result['success'] == 1:
         return result['phish']
-        #doc = result['phish']
-        #return "%s:: %s"% (doc, cfg.PHISHTYPE[str(doc)])
     else:
         return result
 
 def __genQueryArgs(api_path, url):
-    args = {}
-    args["appkey"] = cfg.APPKEY
-    args["q"] = base64.urlsafe_b64encode(url)
-    args["timestamp"] = "%.3f" % (time.time())
-    sign_base_string = __genSignString(api_path, args)
-    args["sign"] = md5(sign_base_string + cfg.SECRET).hexdigest()
-    #print args, sign_base_string
+    args = "appkey=" + cfg.APPKEY
+    args += "&q=" + base64.urlsafe_b64encode(url)
+    args += "&timestamp=" + "%.3f" % (time.time())
+    sign_base_string = api_path + "?" + args
+    args += "&sign=" + md5(sign_base_string + cfg.SECRET).hexdigest()
     return args
 
-    
-def __genSignString(api_path, args):
-    keys = args.keys()
-    keys.sort()
-    key_values = []
-    for k in keys:
-        v = args[k]
-        key_values.append("%s=%s" % (k, v))
-    base_string = api_path + "?" + "&".join(key_values)
-    return base_string
-
-
-from sae.ext.shell import ShellMiddleware
-application = sae.create_wsgi_app(ShellMiddleware(app, '1q2w3e4r5t')) 
-#application = sae.create_wsgi_app(app)
+application = sae.create_wsgi_app(app)
+#from sae.ext.shell import ShellMiddleware
+#application = sae.create_wsgi_app(ShellMiddleware(app, '1q2w3e4r5t')) 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.