HCE Project Python language Distributed Tasks Manager Application, Distributed Crawler Application and client API bindings.  2.0.0-chaika
Hierarchical Cluster Engine Python language binding
ftest_UserProxyJsonWrapper.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 
3 import sys
4 import json
5 
6 from dc_crawler.UserProxyJsonWrapper import UserProxyJsonWrapper
7 from dc.EventObjects import Proxy
8 from app.Utils import varDump
9 
10 
11 siteProperty = {"USER_PROXY": "{\"source\": 0,\"file_path\":\"\/home\/hce\/proxy.json\",\"proxies\":{\"84.23.107.195:8080\":{\"host\":\"84.23.107.195:8080\",\"domains\": [\"*\"],\"priority\":11,\"limits\":null}}}" }
12 
13 
14 jsonData = json.loads(siteProperty["USER_PROXY"])
15 
16 print jsonData, type(jsonData)
17 
18 userProxyJsonWrapper = UserProxyJsonWrapper(jsonData)
19 
20 print 'userProxyJsonWrapper.getProxies() = ', userProxyJsonWrapper.getProxies()
21 
22 # userProxyJsonWrapper.setProxyData({'host':'dev.intel.com:83', 'domains':['*'], 'priority':1, 'limits':11})
23 userProxyJsonWrapper.setProxyData({'host':'dev.intel.com:85', 'domains':'[\'.*intel.*\']', 'priority':2, 'limits':22})
24 userProxyJsonWrapper.setProxyData({'host':'dev.intel.com:85'})
25 
26 print 'userProxyJsonWrapper.getProxies() = ', userProxyJsonWrapper.getProxies()
27 
28 print 'userProxyJsonWrapper.getSource() = ', userProxyJsonWrapper.getSource()
29 print 'userProxyJsonWrapper.getFilePath() = ', userProxyJsonWrapper.getFilePath()
30 print 'userProxyJsonWrapper.getTriesCount() = ', userProxyJsonWrapper.getTriesCount()
31 
32 proxy = Proxy('12345', 'localhost')
33 proxy.priority = 1
34 userProxyJsonWrapper.addProxyList([proxy])
35 print 'userProxyJsonWrapper.getProxies() = ', userProxyJsonWrapper.getProxies()
36 print 'userProxyJsonWrapper.getSource() = ', userProxyJsonWrapper.getSource()
37 userProxyJsonWrapper.setSource(1)
38 print 'userProxyJsonWrapper.getSource() = ', userProxyJsonWrapper.getSource()
39 
40 userProxyJsonWrapper.setSource(0)
41 print 'userProxyJsonWrapper.getSource() = ', userProxyJsonWrapper.getSource()
42 print 'userProxyJsonWrapper.getProxyList() = ', userProxyJsonWrapper.getProxyList()
43 
44 for proxy in userProxyJsonWrapper.getProxyList():
45  print 'Proxy: ', varDump(proxy)
def varDump(obj, stringify=True, strTypeMaxLen=256, strTypeCutSuffix='...', stringifyType=1, ignoreErrors=False, objectsHash=None, depth=0, indent=2, ensure_ascii=False, maxDepth=10)
Definition: Utils.py:410