Browse Source

test.py: update auth on every call, output easier to handle, some convenience functions

master
arian.sanusi@pep.foundation Arian Sanusi (p≡p Foundation) 2 years ago
parent
commit
131e67e701
No known key found for this signature in database GPG Key ID: 49B08FCFF6BC3B2
1 changed files with 31 additions and 4 deletions
  1. +31
    -4
      test.py

+ 31
- 4
test.py View File

@@ -5,11 +5,14 @@ import json
import os
import io

fd = open('%s/.pEp/json-token'%(os.getenv('HOME')))
token = json.load(fd)
url = 'http://%s:%s/ja/0.1/callFunction'%(token['address'],token['port'])
# want these global
token = ''
url = ''

def call(method,*params):
fd = open('%s/.pEp/json-token'%(os.getenv('HOME')))
token = json.load(fd)
url = 'http://%s:%s/ja/0.1/callFunction'%(token['address'],token['port'])
call_d = dict(method=method, params=params, jsonrpc="2.0",)
call_d['security_token'] = token['security_token']
ans = requests.post(url,json=call_d)
@@ -17,4 +20,28 @@ def call(method,*params):
print(ans.errorstack)
raise ValueError(ans.status_code)
ans = json.load(io.StringIO(ans.content.decode('utf8')))
return {i:ans['result'][i] for i in ('return','outParams')}
if ans['result']['return']['status'] not in (0,):
raise IOError(ans)
ans = ans['result']['outParams']
if len(ans)==1:
return ans[0]
else:
return ans

def idrating(address):
return call('identity_rating',dict(address=address),0)

def decryptMime(msg):
if os.path.exists(msg):
msg = open(msg).read()
return call('MIME_decrypt_message',msg,len(msg),0,0,0,0)

def encryptMime(msg):
if os.path.exists(msg):
msg = open(msg).read()
return call('MIME_encrypt_message',msg,len(msg),0,0,0,0)

def forcetrust(address):
identity = call('update_identity',{'address': address})
del identity['comm_type']
return call('trust_personal_key',identity)

Loading…
Cancel
Save