more py3 porting
This commit is contained in:
parent
8e27b9f76e
commit
de68f4c4c4
7 changed files with 21 additions and 15 deletions
|
@ -39,7 +39,7 @@ def find(data):
|
|||
if 'group' in q:
|
||||
names = {}
|
||||
groups = {}
|
||||
key = 'group:' + hashlib.sha1(json.dumps(data)).hexdigest()
|
||||
key = 'group:' + hashlib.sha1(json.dumps(data).encode('utf-8')).hexdigest()
|
||||
g = state.cache.get(key)
|
||||
if g is None:
|
||||
items = [i.id for i in q['qs'].options(load_only('id'))]
|
||||
|
|
|
@ -9,7 +9,7 @@ import os
|
|||
import shutil
|
||||
from glob import glob
|
||||
|
||||
#from pyPdf import PdfFileReader
|
||||
from pyPdf import PdfFileReader
|
||||
import stdnum.isbn
|
||||
|
||||
import settings
|
||||
|
|
|
@ -2,17 +2,15 @@
|
|||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
|
||||
import os
|
||||
|
||||
from tornado.web import Application
|
||||
from tornado.httpserver import HTTPServer
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
from . import oxtornado
|
||||
from .oxtornado import actions
|
||||
import oxtornado
|
||||
from oxtornado import actions
|
||||
|
||||
from . import meta
|
||||
from . import utils
|
||||
import meta
|
||||
import utils
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger('metaoml')
|
||||
|
|
|
@ -67,7 +67,7 @@ class NodeHandler(tornado.web.RequestHandler):
|
|||
content = {'status': 'not peered'}
|
||||
logger.debug('PEER %s IS UNKNOWN SEND 403', key)
|
||||
self.set_status(403)
|
||||
content = json.dumps(content)
|
||||
content = json.dumps(content).encode('utf-8')
|
||||
sig = settings.sk.sign(content, encoding='base64')
|
||||
self.set_header('X-Ed25519-Signature', sig)
|
||||
self.set_header('X-Node-Protocol', settings.NODE_PROTOCOL)
|
||||
|
|
14
oml/nodes.py
14
oml/nodes.py
|
@ -36,6 +36,7 @@ ENCODING='base64'
|
|||
class Node(Thread):
|
||||
_running = True
|
||||
_cert = None
|
||||
host = None
|
||||
online = False
|
||||
download_speed = 0
|
||||
TIMEOUT = 5
|
||||
|
@ -124,7 +125,7 @@ class Node(Thread):
|
|||
logger.debug('unable to find host %s', self.user_id)
|
||||
self.online = False
|
||||
return None
|
||||
content = json.dumps([action, args])
|
||||
content = json.dumps([action, args]).encode('utf-8')
|
||||
sig = settings.sk.sign(content, encoding=ENCODING)
|
||||
headers = {
|
||||
'User-Agent': settings.USER_AGENT,
|
||||
|
@ -137,7 +138,8 @@ class Node(Thread):
|
|||
}
|
||||
self._opener.addheaders = list(zip(list(headers.keys()), list(headers.values())))
|
||||
try:
|
||||
r = self._opener.open(url, data=content, timeout=self.TIMEOUT)
|
||||
self._opener.timeout = self.TIMEOUT
|
||||
r = self._opener.open(url, data=content)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code == 403:
|
||||
logger.debug('REMOTE ENDED PEERING')
|
||||
|
@ -172,7 +174,7 @@ class Node(Thread):
|
|||
|
||||
sig = r.headers.get('X-Ed25519-Signature')
|
||||
if sig and self._valid(data, sig):
|
||||
response = json.loads(data)
|
||||
response = json.loads(data.decode('utf-8'))
|
||||
else:
|
||||
logger.debug('invalid signature %s', data)
|
||||
response = None
|
||||
|
@ -202,7 +204,8 @@ class Node(Thread):
|
|||
'Accept-Encoding': 'gzip',
|
||||
}
|
||||
self._opener.addheaders = list(zip(list(headers.keys()), list(headers.values())))
|
||||
r = self._opener.open(url, timeout=1)
|
||||
self._opener.timeout = 1
|
||||
r = self._opener.open(url)
|
||||
version = r.headers.get('X-Node-Protocol', None)
|
||||
if version != settings.NODE_PROTOCOL:
|
||||
logger.debug('version does not match local: %s remote %s', settings.NODE_PROTOCOL, version)
|
||||
|
@ -298,7 +301,8 @@ class Node(Thread):
|
|||
t1 = datetime.utcnow()
|
||||
logger.debug('download %s', url)
|
||||
self._opener.addheaders = list(zip(list(headers.keys()), list(headers.values())))
|
||||
r = self._opener.open(url, timeout=self.TIMEOUT*2)
|
||||
self._opener.timeout = self.TIMEOUT*2
|
||||
r = self._opener.open(url)
|
||||
if r.getcode() == 200:
|
||||
if r.headers.get('content-encoding', None) == 'gzip':
|
||||
content = gzip.GzipFile(fileobj=r).read()
|
||||
|
|
|
@ -53,6 +53,10 @@ class VerifiedHTTPSHandler(urllib.request.HTTPSHandler):
|
|||
def http_class_wrapper(host, **kwargs):
|
||||
full_kwargs = dict(self._connection_args)
|
||||
full_kwargs.update(kwargs)
|
||||
print(self._connection_args)
|
||||
print(kwargs)
|
||||
if 'timeout' in full_kwargs:
|
||||
del full_kwargs['timeout']
|
||||
return CertValidatingHTTPSConnection(host, **full_kwargs)
|
||||
|
||||
try:
|
||||
|
|
|
@ -215,7 +215,7 @@ def remove_empty_tree(leaf):
|
|||
else:
|
||||
break
|
||||
|
||||
utc_0 = int(time.mktime(datetime(1970, 0o1, 0o1).timetuple()))
|
||||
utc_0 = int(time.mktime(datetime(1970, 1, 1).timetuple()))
|
||||
|
||||
def datetime2ts(dt):
|
||||
return int(time.mktime(dt.utctimetuple())) - utc_0
|
||||
|
|
Loading…
Reference in a new issue