Fix py3 incompatibilities in api:
- bytes in BMXMLRPCRequestHandler (copied relevant lines from xmlrpc.server once again), - used @six.add_metaclass for the metaclass and six.iteritems() Closes: #1900
This commit is contained in:
parent
1b7a642d6a
commit
2501212a82
20
src/api.py
20
src/api.py
|
@ -1,5 +1,5 @@
|
||||||
# Copyright (c) 2012-2016 Jonathan Warren
|
# Copyright (c) 2012-2016 Jonathan Warren
|
||||||
# Copyright (c) 2012-2022 The Bitmessage developers
|
# Copyright (c) 2012-2023 The Bitmessage developers
|
||||||
|
|
||||||
"""
|
"""
|
||||||
This is not what you run to start the Bitmessage API.
|
This is not what you run to start the Bitmessage API.
|
||||||
|
@ -68,6 +68,7 @@ import time
|
||||||
from binascii import hexlify, unhexlify
|
from binascii import hexlify, unhexlify
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
|
|
||||||
|
import six
|
||||||
from six.moves import configparser, http_client, xmlrpc_server
|
from six.moves import configparser, http_client, xmlrpc_server
|
||||||
|
|
||||||
import defaults
|
import defaults
|
||||||
|
@ -98,7 +99,7 @@ try:
|
||||||
except ImportError:
|
except ImportError:
|
||||||
network_stats = None
|
network_stats = None
|
||||||
|
|
||||||
from network.threads import StoppableThread
|
from network import StoppableThread
|
||||||
from version import softwareVersion
|
from version import softwareVersion
|
||||||
|
|
||||||
try: # TODO: write tests for XML vulnerabilities
|
try: # TODO: write tests for XML vulnerabilities
|
||||||
|
@ -160,7 +161,7 @@ class ErrorCodes(type):
|
||||||
|
|
||||||
def __new__(mcs, name, bases, namespace):
|
def __new__(mcs, name, bases, namespace):
|
||||||
result = super(ErrorCodes, mcs).__new__(mcs, name, bases, namespace)
|
result = super(ErrorCodes, mcs).__new__(mcs, name, bases, namespace)
|
||||||
for code in mcs._CODES.iteritems():
|
for code in six.iteritems(mcs._CODES):
|
||||||
# beware: the formatting is adjusted for list-table
|
# beware: the formatting is adjusted for list-table
|
||||||
result.__doc__ += """ * - %04i
|
result.__doc__ += """ * - %04i
|
||||||
- %s
|
- %s
|
||||||
|
@ -388,10 +389,14 @@ class BMXMLRPCRequestHandler(xmlrpc_server.SimpleXMLRPCRequestHandler):
|
||||||
L = []
|
L = []
|
||||||
while size_remaining:
|
while size_remaining:
|
||||||
chunk_size = min(size_remaining, max_chunk_size)
|
chunk_size = min(size_remaining, max_chunk_size)
|
||||||
L.append(self.rfile.read(chunk_size))
|
chunk = self.rfile.read(chunk_size)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
L.append(chunk)
|
||||||
size_remaining -= len(L[-1])
|
size_remaining -= len(L[-1])
|
||||||
data = ''.join(L)
|
data = b''.join(L)
|
||||||
|
|
||||||
|
# data = self.decode_request_content(data)
|
||||||
# pylint: disable=attribute-defined-outside-init
|
# pylint: disable=attribute-defined-outside-init
|
||||||
self.cookies = []
|
self.cookies = []
|
||||||
|
|
||||||
|
@ -448,7 +453,8 @@ class BMXMLRPCRequestHandler(xmlrpc_server.SimpleXMLRPCRequestHandler):
|
||||||
if 'Authorization' in self.headers:
|
if 'Authorization' in self.headers:
|
||||||
# handle Basic authentication
|
# handle Basic authentication
|
||||||
encstr = self.headers.get('Authorization').split()[1]
|
encstr = self.headers.get('Authorization').split()[1]
|
||||||
emailid, password = encstr.decode('base64').split(':')
|
emailid, password = base64.b64decode(
|
||||||
|
encstr).decode('utf-8').split(':')
|
||||||
return (
|
return (
|
||||||
emailid == config.get(
|
emailid == config.get(
|
||||||
'bitmessagesettings', 'apiusername'
|
'bitmessagesettings', 'apiusername'
|
||||||
|
@ -464,9 +470,9 @@ class BMXMLRPCRequestHandler(xmlrpc_server.SimpleXMLRPCRequestHandler):
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=no-self-use,no-member,too-many-public-methods
|
# pylint: disable=no-self-use,no-member,too-many-public-methods
|
||||||
|
@six.add_metaclass(CommandHandler)
|
||||||
class BMRPCDispatcher(object):
|
class BMRPCDispatcher(object):
|
||||||
"""This class is used to dispatch API commands"""
|
"""This class is used to dispatch API commands"""
|
||||||
__metaclass__ = CommandHandler
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _decode(text, decode_type):
|
def _decode(text, decode_type):
|
||||||
|
|
Reference in New Issue
Block a user