Skip to content

Commit 7f0b40e

Browse files
committed
Switched to Py3 compatible meta classes
1 parent b5e269d commit 7f0b40e

File tree

8 files changed

+18
-33
lines changed

8 files changed

+18
-33
lines changed

ipv8/attestation/trustchain/listener.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import abc
2+
import six
23

34
from .block import TrustChainBlock
45

56

6-
class BlockListener(object):
7+
class BlockListener(six.with_metaclass(abc.ABCMeta, object)):
78
"""
89
This class defines a listener for TrustChain blocks with a specific type.
910
"""
1011

11-
__metaclass__ = abc.ABCMeta
12-
1312
BLOCK_CLASS = TrustChainBlock
1413

1514
@abc.abstractmethod

ipv8/database.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from collections import defaultdict
99
import logging
1010
import os
11+
import six
1112
import sys
1213
from threading import RLock
1314
from abc import ABCMeta, abstractmethod
@@ -68,9 +69,7 @@ class DatabaseException(RuntimeError):
6869
pass
6970

7071

71-
class Database(object):
72-
73-
__metaclass__ = ABCMeta
72+
class Database(six.with_metaclass(ABCMeta, object)):
7473

7574
def __init__(self, file_path):
7675
"""

ipv8/keyvault/keys.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import abc
22
from hashlib import sha1
3+
import six
34

45

5-
class Key(object):
6+
class Key(six.with_metaclass(abc.ABCMeta, object)):
67
"""
78
Interface for a public or private key.
89
"""
910

10-
__metaclass__ = abc.ABCMeta
11-
1211
@abc.abstractmethod
1312
def pub(self):
1413
pass
@@ -27,13 +26,11 @@ def key_to_hash(self):
2726
return sha1(self.key_to_bin()).digest()
2827

2928

30-
class PrivateKey(Key):
29+
class PrivateKey(six.with_metaclass(abc.ABCMeta, Key)):
3130
"""
3231
Interface for a private key.
3332
"""
3433

35-
__metaclass__ = abc.ABCMeta
36-
3734
def has_secret_key(self):
3835
return True
3936

@@ -42,13 +39,11 @@ def signature(self, msg):
4239
pass
4340

4441

45-
class PublicKey(Key):
42+
class PublicKey(six.with_metaclass(abc.ABCMeta, Key)):
4643
"""
4744
Interface for a public key.
4845
"""
4946

50-
__metaclass__ = abc.ABCMeta
51-
5247
def pub(self):
5348
return self
5449

ipv8/messaging/interfaces/endpoint.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import abc
22
import logging
33
import netifaces
4+
import six
45
import socket
56
import struct
67

@@ -9,13 +10,11 @@
910
from ...util import blockingCallFromThread
1011

1112

12-
class Endpoint(object):
13+
class Endpoint(six.with_metaclass(abc.ABCMeta, object)):
1314
"""
1415
Interface for sending messages over the Internet.
1516
"""
1617

17-
__metaclass__ = abc.ABCMeta
18-
1918
def __init__(self):
2019
self._logger = logging.getLogger(self.__class__.__name__)
2120
self._listeners = []
@@ -81,13 +80,11 @@ def close(self):
8180
pass
8281

8382

84-
class EndpointListener(object):
83+
class EndpointListener(six.with_metaclass(abc.ABCMeta, object)):
8584
"""
8685
Handler for messages coming in through an Endpoint.
8786
"""
8887

89-
__metaclass__ = abc.ABCMeta
90-
9188
def __init__(self, endpoint, main_thread=True):
9289
"""
9390
Create a new listener.

ipv8/messaging/serialization.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import abc
22
from struct import pack, unpack, unpack_from, Struct
3+
import six
34
import sys
45

56

@@ -304,13 +305,11 @@ def unpack_to_serializables(self, serializables, data):
304305
return out
305306

306307

307-
class Serializable(object):
308+
class Serializable(six.with_metaclass(abc.ABCMeta, object)):
308309
"""
309310
Interface for serializable objects.
310311
"""
311312

312-
__metaclass__ = abc.ABCMeta
313-
314313
format_list = []
315314
optional_format_list = []
316315
is_list_descriptor = False

ipv8/overlay.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
import abc
22
import logging
3-
from time import time
3+
import six
44

55
from .keyvault.crypto import ECCrypto
66
from .messaging.interfaces.endpoint import EndpointListener
77
from .messaging.serialization import Serializer
8-
from .peer import Peer
98
from .taskmanager import TaskManager
109

1110

12-
class Overlay(EndpointListener, TaskManager):
11+
class Overlay(six.with_metaclass(abc.ABCMeta, EndpointListener, TaskManager)):
1312
"""
1413
Interface for an Internet overlay.
1514
"""
1615

17-
__metaclass__ = abc.ABCMeta
18-
1916
def __init__(self, master_peer, my_peer, endpoint, network):
2017
"""
2118
Create a new overlay for the Internet.

ipv8/peerdiscovery/discovery.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
import abc
2-
32
from random import choice
3+
import six
44
from time import time
55
from threading import Lock
66

77

8-
class DiscoveryStrategy(object):
8+
class DiscoveryStrategy(six.with_metaclass(abc.ABCMeta, object)):
99
"""
1010
Strategy for discovering peers in a network.
1111
"""
1212

13-
__metaclass__ = abc.ABCMeta
14-
1513
def __init__(self, overlay):
1614
self.overlay = overlay
1715
self.walk_lock = Lock()

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ libnacl>=1.6.1
33
netifaces
44
Twisted>=17.9.0
55
pyOpenSSL
6+
six

0 commit comments

Comments
 (0)