Skip to content

Commit

Permalink
Revert change to default bind address (#731)
Browse files Browse the repository at this point in the history
* Revert default bind address change
* Remove initialising `T_CONNECT` with an address tuple
  • Loading branch information
scaramallion authored Dec 29, 2021
1 parent 186e5b6 commit b2f065d
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pull-request-linter

on:
pull_request:
branches: [ master ]
branches: [ master, 2.0.X ]

jobs:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-pytest-apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pull-request-pytest-apps

on:
pull_request:
branches: [ master ]
branches: [ master, 2.0.X ]

jobs:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pull-request-pytest

on:
pull_request:
branches: [ master ]
branches: [ master, 2.0.X ]

jobs:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr-typing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pull-request-typing

on:
pull_request:
branches: [ master ]
branches: [ master, 2.0.X ]

jobs:

Expand Down
1 change: 1 addition & 0 deletions docs/changelog/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Release Notes
.. toctree::
:maxdepth: 1

v2.0.1
v2.0.0
v1.5.7
v1.5.6
Expand Down
10 changes: 10 additions & 0 deletions docs/changelog/v2.0.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.. _v2.0.1:

2.0.1
=====

Changes
.......

* Revert change to default bind address
* Don't allow passing an address tuple to T_CONNECT initialisation
2 changes: 1 addition & 1 deletion pynetdicom/_globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@


# The default address that client sockets are bound to
BIND_ADDRESS = ("127.0.0.1", 0)
BIND_ADDRESS = ("", 0)


OptionalUIDType = Optional[Union[str, bytes, UID]]
2 changes: 1 addition & 1 deletion pynetdicom/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


# pynetdicom version
__version__ = "2.0.0"
__version__ = "2.0.1"

# DICOM Standard version used for SOP classes and instances
__dicom_version__: str = "2021e"
Expand Down
35 changes: 24 additions & 11 deletions pynetdicom/tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,38 @@ class TestTConnect:
def test_bad_addr_raises(self):
"""Test a bad init parameter raises exception"""
msg = (
r"'address' must be 'Tuple\[str, int\]' or "
r"'pynetdicom.pdu_primitives.A_ASSOCIATE', not 'NoneType'"
r"'request' must be 'pynetdicom.pdu_primitives.A_ASSOCIATE', not 'NoneType'"
)
with pytest.raises(TypeError, match=msg):
T_CONNECT(None)

def test_address_tuple(self):
"""Test init with a tuple"""
conn = T_CONNECT(("123", 12))
assert conn.address == ("123", 12)
assert conn.request is None
assert conn.result == ""

def test_address_request(self):
"""Test init with an A-ASSOCIATE primitive"""
request = A_ASSOCIATE()
request.called_presentation_address = ("123", 12)
conn = T_CONNECT(request)
assert conn.address == ("123", 12)
assert conn.request is request
assert conn.result == ""

msg = r"A connection attempt has not yet been made"
with pytest.raises(ValueError, match=msg):
conn.result

def test_result_setter(self):
"""Test setting the result value."""
request = A_ASSOCIATE()
request.called_presentation_address = ("123", 12)
conn = T_CONNECT(request)

msg = r"Invalid connection result 'foo'"
with pytest.raises(ValueError, match=msg):
conn.result = "foo"

assert conn._result == ""

for result in ("Evt2", "Evt17"):
conn.result = result
assert conn.result == result


class TestAssociationSocket:
Expand Down Expand Up @@ -161,7 +172,9 @@ def test_close_connect(self):
sock.close()
assert sock.socket is None
# Tries to connect, sets to None if fails
sock.connect(T_CONNECT(("localhost", 11112)))
request = A_ASSOCIATE()
request.called_presentation_address = ("localhost", 11112)
sock.connect(T_CONNECT(request))
assert sock.event_queue.get() == "Evt17"
assert sock.socket is None

Expand Down
63 changes: 43 additions & 20 deletions pynetdicom/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,41 +52,64 @@ class T_CONNECT:
"""A TRANSPORT CONNECTION primitive
.. versionadded:: 2.0
Attributes
----------
request : pynetdicom.pdu_primitives.A_ASSOCIATE
The A-ASSOCIATE (request) primitive that generated the TRANSPORT CONNECTION
primitive.
"""

def __init__(self, address: Union[Tuple[str, int], "A_ASSOCIATE"]) -> None:
def __init__(self, request: "A_ASSOCIATE") -> None:
"""Create a new TRANSPORT CONNECTION primitive.
Parameters
----------
address : Union[Tuple[str, int], pynetdicom.pdu_primitives.A_ASSOCIATE]
The ``(str: IP address, int: port)`` or A-ASSOCIATE (request) primitive to
use when making a connection with a peer.
request : pynetdicom.pdu_primitives.A_ASSOCIATE
The A-ASSOCIATE (request) primitive to use when making a connection with
a peer.
"""
self._request = None
self.result = ""

if isinstance(address, tuple):
self._address = address
elif isinstance(address, A_ASSOCIATE):
self._address = cast(Tuple[str, int], address.called_presentation_address)
self._request = address
else:
self._result = ""
self.request = request

if not isinstance(request, A_ASSOCIATE):
raise TypeError(
f"'address' must be 'Tuple[str, int]' or "
"'pynetdicom.pdu_primitives.A_ASSOCIATE', not "
f"'{address.__class__.__name__}'"
f"'request' must be 'pynetdicom.pdu_primitives.A_ASSOCIATE', not "
f"'{request.__class__.__name__}'"
)

@property
def address(self) -> Tuple[str, int]:
"""Return the peer's ``(str: IP address, int: port)``."""
return self._address
return cast(Tuple[str, int], self.request.called_presentation_address)

@property
def request(self) -> Optional[A_ASSOCIATE]:
"""Return the A-ASSOCIATE (request) primitive, or ``None`` if not available."""
return self._request
def result(self) -> str:
"""Return the result of the connection attempt as :class:`str`.
Parameters
----------
str
The result of the connection attempt, ``"Evt2"`` if the connection
succeeded, ``"Evt17"`` if it failed.
Returns
-------
str
The result of the connection attempt, ``"Evt2"`` if the connection
succeeded, ``"Evt17"`` if it failed.
"""
if self._result == "":
raise ValueError("A connection attempt has not yet been made")

return self._result

@result.setter
def result(self, value: str) -> None:
if value not in ("Evt2", "Evt17"):
raise ValueError(f"Invalid connection result '{value}'")

self._result = value


class AssociationSocket:
Expand Down

0 comments on commit b2f065d

Please sign in to comment.