Fixes for Python 3 support
This commit is contained in:
parent
0352dc9137
commit
8cae92017e
examples/python
python/pyngus
tests/python
@ -349,8 +349,8 @@ def main(argv=None):
|
||||
my_socket.setblocking(0) # 0=non-blocking
|
||||
try:
|
||||
my_socket.connect(addr[0][4])
|
||||
except socket.error, e:
|
||||
if e[0] != errno.EINPROGRESS:
|
||||
except socket.error as e:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
|
||||
# create AMQP container, connection, sender and receiver
|
||||
|
@ -347,8 +347,8 @@ def main(argv=None):
|
||||
try:
|
||||
my_socket.bind((host, port))
|
||||
my_socket.listen(10)
|
||||
except socket.error, e:
|
||||
if e[0] != errno.EINPROGRESS:
|
||||
except socket.error as e:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
|
||||
# create an AMQP container that will 'provide' the RPC service
|
||||
|
@ -50,8 +50,8 @@ def connect_socket(host, port, blocking=True):
|
||||
my_socket.setblocking(0)
|
||||
try:
|
||||
my_socket.connect(addr[0][4])
|
||||
except socket.error, e:
|
||||
if e[0] != errno.EINPROGRESS:
|
||||
except socket.error as e:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
return my_socket
|
||||
|
||||
@ -67,8 +67,8 @@ def server_socket(host, port, backlog=10):
|
||||
try:
|
||||
my_socket.bind(addr[0][4])
|
||||
my_socket.listen(backlog)
|
||||
except socket.error, e:
|
||||
if e[0] != errno.EINPROGRESS:
|
||||
except socket.error as e:
|
||||
if e.errno != errno.EINPROGRESS:
|
||||
raise
|
||||
return my_socket
|
||||
|
||||
|
@ -259,9 +259,9 @@ class Connection(Endpoint):
|
||||
self._pn_connection.open()
|
||||
|
||||
def close(self, pn_condition=None):
|
||||
for link in self._sender_links.itervalues():
|
||||
for link in list(self._sender_links.values()):
|
||||
link.close(pn_condition)
|
||||
for link in self._receiver_links.itervalues():
|
||||
for link in list(self._receiver_links.values()):
|
||||
link.close(pn_condition)
|
||||
if pn_condition:
|
||||
self._pn_connection.condition = pn_condition
|
||||
@ -689,3 +689,17 @@ class Connection(Endpoint):
|
||||
"""The endpoint state machine failed due to protocol error."""
|
||||
super(Connection, self)._ep_error(error)
|
||||
self._connection_failed("Protocol error occurred.")
|
||||
|
||||
# order by name
|
||||
|
||||
def __lt__(self, other):
|
||||
return self.name < other.name
|
||||
|
||||
def __le__(self, other):
|
||||
return self < other or self.name == other.name
|
||||
|
||||
def __gt__(self, other):
|
||||
return self.name > other.name
|
||||
|
||||
def __ge__(self, other):
|
||||
return self > other or self.name == other.name
|
||||
|
@ -36,7 +36,7 @@ class Container(object):
|
||||
self._properties = properties
|
||||
|
||||
def destroy(self):
|
||||
conns = self._connections.values()
|
||||
conns = list(self._connections.values())
|
||||
for conn in conns:
|
||||
conn.destroy()
|
||||
|
||||
@ -62,7 +62,7 @@ class Container(object):
|
||||
readers = []
|
||||
writers = []
|
||||
timer_heap = []
|
||||
for c in self._connections.itervalues():
|
||||
for c in iter(self._connections.values()):
|
||||
if c.needs_input > 0:
|
||||
readers.append(c)
|
||||
if c.has_output > 0:
|
||||
|
@ -49,7 +49,7 @@ def read_socket_input(connection, socket_obj):
|
||||
raise # caller must handle
|
||||
except socket.error as e:
|
||||
LOG.debug("Socket error exception %s", str(e))
|
||||
err = e.args[0]
|
||||
err = e.errno
|
||||
# ignore non-fatal errors
|
||||
if (err != errno.EAGAIN and
|
||||
err != errno.EWOULDBLOCK and
|
||||
@ -92,7 +92,7 @@ def write_socket_output(connection, socket_obj):
|
||||
raise # caller must handle
|
||||
except socket.error as e:
|
||||
LOG.debug("Socket error exception %s", str(e))
|
||||
err = e.args[0]
|
||||
err = e.errno
|
||||
# ignore non-fatal errors
|
||||
if (err != errno.EAGAIN and
|
||||
err != errno.EWOULDBLOCK and
|
||||
|
@ -29,13 +29,18 @@ from getopt import GetoptError
|
||||
from logging import getLogger, StreamHandler, Formatter, Filter, \
|
||||
WARN, DEBUG, ERROR
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
CLASS_TYPES = (type, types.ClassType)
|
||||
else:
|
||||
CLASS_TYPES = (type,)
|
||||
|
||||
levels = {
|
||||
"DEBUG": DEBUG,
|
||||
"WARN": WARN,
|
||||
"ERROR": ERROR
|
||||
}
|
||||
|
||||
sorted_levels = [(v, k) for k, v in levels.items()]
|
||||
sorted_levels = [(v, k) for k, v in list(levels.items())]
|
||||
sorted_levels.sort()
|
||||
sorted_levels = [v for k, v in sorted_levels]
|
||||
|
||||
@ -537,7 +542,7 @@ class FunctionScanner(PatternMatcher):
|
||||
class ClassScanner(PatternMatcher):
|
||||
|
||||
def inspect(self, obj):
|
||||
return type(obj) in (types.ClassType, types.TypeType) and self.matches(obj.__name__)
|
||||
return type(obj) in CLASS_TYPES and self.matches(obj.__name__)
|
||||
|
||||
def descend(self, cls):
|
||||
# the None is required for older versions of python
|
||||
@ -549,13 +554,20 @@ class ClassScanner(PatternMatcher):
|
||||
for name in names:
|
||||
obj = getattr(cls, name)
|
||||
t = type(obj)
|
||||
if t == types.MethodType and name.startswith("test"):
|
||||
if hasattr(obj, '__call__') and name.startswith("test"):
|
||||
yield MethodTest(cls, name)
|
||||
|
||||
class ModuleScanner:
|
||||
|
||||
def __init__(self, modules):
|
||||
self._modules = modules
|
||||
|
||||
def inspect(self, obj):
|
||||
return type(obj) == types.ModuleType
|
||||
if type(obj) == types.ModuleType:
|
||||
return any([obj.__name__.startswith(m) for m in self._modules])
|
||||
else:
|
||||
return False
|
||||
return type(obj) == types.ModuleType and obj.__name__.startswith("unit_test")
|
||||
|
||||
def descend(self, obj):
|
||||
names = dir(obj)
|
||||
@ -569,17 +581,20 @@ class ModuleScanner:
|
||||
|
||||
class Harness:
|
||||
|
||||
def __init__(self):
|
||||
def __init__(self, modules):
|
||||
self.scanners = [
|
||||
ModuleScanner(),
|
||||
ModuleScanner(modules),
|
||||
ClassScanner("*Test", "*Tests", "*TestCase"),
|
||||
FunctionScanner("test_*")
|
||||
]
|
||||
self.tests = []
|
||||
self.scanned = []
|
||||
self._modules = modules
|
||||
|
||||
def scan(self, *roots):
|
||||
objects = list(roots)
|
||||
def scan(self):
|
||||
objects = []
|
||||
for name in self._modules:
|
||||
objects.append(__import__(name, None, None, ["dummy"]))
|
||||
|
||||
while objects:
|
||||
obj = objects.pop(0)
|
||||
@ -594,10 +609,8 @@ class Harness:
|
||||
modules = opts.modules
|
||||
if not modules:
|
||||
modules.extend(["unit_tests"])
|
||||
h = Harness()
|
||||
for name in modules:
|
||||
m = __import__(name, None, None, ["dummy"])
|
||||
h.scan(m)
|
||||
h = Harness(modules)
|
||||
h.scan()
|
||||
|
||||
filtered = [t for t in h.tests if is_included(t.name())]
|
||||
ignored = [t for t in h.tests if is_ignored(t.name())]
|
||||
|
@ -17,6 +17,6 @@
|
||||
# under the License.
|
||||
#
|
||||
|
||||
import unit_tests.container
|
||||
import unit_tests.connection
|
||||
import unit_tests.link
|
||||
from . import container
|
||||
from . import connection
|
||||
from . import link
|
||||
|
@ -20,14 +20,13 @@
|
||||
import gc
|
||||
import time
|
||||
|
||||
import proton
|
||||
from proton import VERSION_MAJOR, VERSION_MINOR
|
||||
import pyngus
|
||||
|
||||
|
||||
class Test(object):
|
||||
|
||||
PROTON_VERSION = (int(getattr(proton, "VERSION_MAJOR", 0)),
|
||||
int(getattr(proton, "VERSION_MINOR", 0)))
|
||||
PROTON_VERSION = (int(VERSION_MAJOR), int(VERSION_MINOR))
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
@ -16,7 +16,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import common
|
||||
from . import common
|
||||
# import logging
|
||||
import os
|
||||
import time
|
||||
|
@ -16,7 +16,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import common
|
||||
from . import common
|
||||
import gc
|
||||
|
||||
import pyngus
|
||||
|
@ -16,7 +16,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
import common
|
||||
from . import common
|
||||
# import logging
|
||||
import time
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user