Repository: pydicom/pynetdicom

Issue:
UnboundLocalError: local variable 'primitive' referenced before assignment
**Describe the bug**

`UnboundLocalError: local variable 'primitive' referenced before assignment` exception is observed when A-ABORT PDU is received with `Abort Source: Reserved`.

**Expected behavior**

I am not well versed in DICOM standard however I would expect pynetdicom to gracefully handle this case.

**Steps To Reproduce**

I am unable to reproduce the issue myself but I can provide a snippet of logs from production:

```
INFO Received Store Request
DEBUG ========================== INCOMING DIMSE MESSAGE ==========================
DEBUG Message Type                  : C-STORE RQ
DEBUG Presentation Context ID       : 1
DEBUG Message ID                    : 2
DEBUG Affected SOP Class UID        : Digital X-Ray Image Storage - For Presentation
DEBUG Affected SOP Instance UID     : REDACTED
DEBUG Data Set                      : Present
DEBUG Priority                      : Medium
DEBUG ============================ END DIMSE MESSAGE =============================
...
DEBUG pydicom.read_dataset() TransferSyntax="Little Endian Implicit"
...
INFO Association Released
DEBUG Abort Parameters:
DEBUG =========================== INCOMING A-ABORT PDU ===========================
DEBUG Abort Source: Reserved
DEBUG Abort Reason: No reason given
DEBUG ============================= END A-ABORT PDU ==============================
ERROR Exception in DUL.run(), aborting association
ERROR local variable 'primitive' referenced before assignment
Traceback (most recent call last):
  File "/oxipit/app/pacs_integration/.venv/lib/python3.7/site-packages/pynetdicom/dul.py", line 389, in run
    elif self._is_transport_event():
  File "/oxipit/app/pacs_integration/.venv/lib/python3.7/site-packages/pynetdicom/dul.py", line 160, in _is_transport_event
    self._read_pdu_data()
  File "/oxipit/app/pacs_integration/.venv/lib/python3.7/site-packages/pynetdicom/dul.py", line 311, in _read_pdu_data
    self.primitive = self.pdu.to_primitive()
  File "/oxipit/app/pacs_integration/.venv/lib/python3.7/site-packages/pynetdicom/pdu.py", line 1919, in to_primitive
    return primitive
UnboundLocalError: local variable 'primitive' referenced before assignment
```

This happens at the end of every C-STORE request and does not seem to be consequential (except for generating noise in logs). It looks like the PACS server on the other side is using a reserved value for the "source" field of A-ABORT PDU which is a case not handled by pynetdicom: https://github.com/pydicom/pynetdicom/blob/v1.5.3/pynetdicom/pdu.py#L1899-L1919

**Your environment**

```
Linux-4.15.0-101-generic-x86_64-with-debian-10.6
Python 3.7.9
pydicom 2.1.1
pynetdicom 1.5.3
```

Discussion:
codecov[bot]: # [Codecov](https://codecov.io/gh/pydicom/pynetdicom/pull/562?src=pr&el=h1) Report
> Merging [#562](https://codecov.io/gh/pydicom/pynetdicom/pull/562?src=pr&el=desc) (447959f) into [master](https://codecov.io/gh/pydicom/pynetdicom/commit/dffa77eff47b69bc2cc80e2c57a960e71a017511?el=desc) (dffa77e) will **not change** coverage.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff            @@
##            master      #562   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           27        27           
  Lines         8412      8408    -4     
=========================================
- Hits          8412      8408    -4     
```

| [Impacted Files](https://codecov.io/gh/pydicom/pynetdicom/pull/562?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pynetdicom/pdu.py](https://codecov.io/gh/pydicom/pynetdicom/pull/562/diff?src=pr&el=tree#diff-cHluZXRkaWNvbS9wZHUucHk=) | `100.00% <100.00%> (ø)` | |
| [pynetdicom/pdu\_primitives.py](https://codecov.io/gh/pydicom/pynetdicom/pull/562/diff?src=pr&el=tree#diff-cHluZXRkaWNvbS9wZHVfcHJpbWl0aXZlcy5weQ==) | `100.00% <100.00%> (ø)` | |


Patch:
diff --git a/docs/changelog/index.rst b/docs/changelog/index.rst
index 2ae0a9e49..a16d95b6c 100644
--- a/docs/changelog/index.rst
+++ b/docs/changelog/index.rst
@@ -8,6 +8,7 @@ Release Notes
    :maxdepth: 1
 
    v2.0.0
+   v1.5.4
    v1.5.3
    v1.5.2
    v1.5.1
diff --git a/docs/changelog/v1.5.4.rst b/docs/changelog/v1.5.4.rst
new file mode 100644
index 000000000..7fdc479b0
--- /dev/null
+++ b/docs/changelog/v1.5.4.rst
@@ -0,0 +1,10 @@
+.. _v1.5.4:
+
+1.5.4
+=====
+
+Fixes
+.....
+
+* Fixed not handling an A-ABORT with a reserved (``0x01``) 'source' value
+  (:issue:`561`)
diff --git a/pynetdicom/pdu.py b/pynetdicom/pdu.py
index 5fc925be7..8e8073644 100644
--- a/pynetdicom/pdu.py
+++ b/pynetdicom/pdu.py
@@ -1891,15 +1891,14 @@ class A_ABORT_RQ(PDU):
         """
         from pynetdicom.pdu_primitives import A_ABORT, A_P_ABORT
 
-        # User initiated abort
-        if self.source == 0x00:
-            primitive = A_ABORT()
-            primitive.abort_source = self.source
-
-        # User provider primitive abort
-        elif self.source == 0x02:
+        if self.source == 0x02:
+            # User provider primitive abort
             primitive = A_P_ABORT()
             primitive.provider_reason = self.reason_diagnostic
+        else:
+            # User initiated abort and undefined abort source
+            primitive = A_ABORT()
+            primitive.abort_source = self.source
 
         return primitive
 
diff --git a/pynetdicom/pdu_primitives.py b/pynetdicom/pdu_primitives.py
index 2a24c74c1..d0c9aaeb6 100644
--- a/pynetdicom/pdu_primitives.py
+++ b/pynetdicom/pdu_primitives.py
@@ -835,13 +835,13 @@ class A_ABORT(object):
     """
 
     def __init__(self):
-        self.abort_source = None
+        self._abort_source = None
 
     @property
     def abort_source(self):
         """Return the *Abort Source*."""
         if self._abort_source is None:
-            LOGGER.error("A_ABORT.abort_source parameter not set")
+            LOGGER.error("A_ABORT.abort_source value not set")
             raise ValueError("A_ABORT.abort_source value not set")
 
         return self._abort_source
@@ -849,16 +849,12 @@ class A_ABORT(object):
     @abort_source.setter
     def abort_source(self, value):
         """Set the Abort Source."""
-        # pylint: disable=attribute-defined-outside-init
-        if value in [0, 2]:
+        if value in [0, 1, 2, None]:
             self._abort_source = value
-        elif value is None:
-            self._abort_source = None
         else:
-            LOGGER.error("Attempted to set A_ABORT.abort_source to an "
-                         "invalid value")
-            raise ValueError("Attempted to set A_ABORT.abort_source to an "
-                             "invalid value")
+            msg = f"Invalid A-ABORT 'Source' value '{value}'"
+            LOGGER.error(msg)
+            raise ValueError(msg)
 
 
 class A_P_ABORT(object):
@@ -898,7 +894,7 @@ class A_P_ABORT(object):
     * DICOM Standard, Part 8, :dcm:`Section 7.4<part08/sect_7.4.html>`
     """
     def __init__(self):
-        self.provider_reason = None
+        self._provider_reason = None
 
     @property
     def provider_reason(self):
@@ -912,11 +908,8 @@ class A_P_ABORT(object):
     @provider_reason.setter
     def provider_reason(self, value):
         """Set the Provider Reason."""
-        # pylint: disable=attribute-defined-outside-init
-        if value in [0, 1, 2, 4, 5, 6]:
+        if value in [0, 1, 2, 4, 5, 6, None]:
             self._provider_reason = value
-        elif value is None:
-            self._provider_reason = None
         else:
             msg = (
                 "Attempted to set A_P_ABORT.provider_reason to an invalid "


Test patch:
diff --git a/pynetdicom/tests/encoded_pdu_items.py b/pynetdicom/tests/encoded_pdu_items.py
index c310d2b62..6a98d5aca 100644
--- a/pynetdicom/tests/encoded_pdu_items.py
+++ b/pynetdicom/tests/encoded_pdu_items.py
@@ -1,5 +1,5 @@
 """Encoding PDUs for use in testing."""
-############################# A-ASSOCIATE-RQ PDU ###############################
+############################# A-ASSOCIATE-RQ PDU #############################
 # Called AET: ANY-SCP
 # Calling AET: ECHOSCU
 # Application Context Name: 1.2.840.10008.3.1.1.1
@@ -11,22 +11,24 @@
 #   Max Length Received: 16382
 #   Implementation Class UID: 1.2.826.0.1.3680043.9.3811.0.9.0
 #   Implementation Version Name: PYNETDICOM_090
-a_associate_rq = b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d" \
-                 b"\x53\x43\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43" \
-                 b"\x48\x4f\x53\x43\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20" \
-                 b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
-                 b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \
-                 b"\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e\x32\x2e\x38\x34" \
-                 b"\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e\x31\x2e" \
-                 b"\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31" \
-                 b"\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31" \
-                 b"\x2e\x31\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e" \
-                 b"\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\x3e\x51" \
-                 b"\x00\x00\x04\x00\x00\x3f\xfe\x52\x00\x00\x20\x31\x2e\x32" \
-                 b"\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30" \
-                 b"\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e" \
-                 b"\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f" \
-                 b"\x4d\x5f\x30\x39\x30"
+a_associate_rq = (
+    b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d"
+    b"\x53\x43\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43"
+    b"\x48\x4f\x53\x43\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20"
+    b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+    b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
+    b"\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e\x32\x2e\x38\x34"
+    b"\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e\x31\x2e"
+    b"\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31"
+    b"\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31"
+    b"\x2e\x31\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e"
+    b"\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\x3e\x51"
+    b"\x00\x00\x04\x00\x00\x3f\xfe\x52\x00\x00\x20\x31\x2e\x32"
+    b"\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30"
+    b"\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e"
+    b"\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f"
+    b"\x4d\x5f\x30\x39\x30"
+)
 
 # Called AET: ANY-SCP
 # Calling AET: ECHOSCU
@@ -47,22 +49,24 @@ a_associate_rq = b"\x01\x00\x00\x00\x00\xd1\x00\x01\x00\x00\x41\x4e\x59\x2d" \
 #   AsynchronousOperationsWindow
 #       Max operations invoked: 5
 #       Max operations performed: 5
-a_associate_rq_user_async = b'\x01\x00\x00\x00\x00\xed\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43' \
-                            b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43' \
-                            b'\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00' \
-                            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                            b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e' \
-                            b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e' \
-                            b'\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31' \
-                            b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31' \
-                            b'\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30' \
-                            b'\x38\x2e\x31\x2e\x32\x50\x00\x00\x5a\x51\x00\x00\x04\x00\x00\x3f' \
-                            b'\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31' \
-                            b'\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e' \
-                            b'\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49' \
-                            b'\x43\x4f\x4d\x5f\x30\x39\x30\x58\x00\x00\x10\x01\x01\x00\x0a\x70' \
-                            b'\x79\x6e\x65\x74\x64\x69\x63\x6f\x6d\x00\x00\x53\x00\x00\x04\x00' \
-                            b'\x05\x00\x05'
+a_associate_rq_user_async = (
+    b'\x01\x00\x00\x00\x00\xed\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43'
+    b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43'
+    b'\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e'
+    b'\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31'
+    b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31'
+    b'\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30'
+    b'\x38\x2e\x31\x2e\x32\x50\x00\x00\x5a\x51\x00\x00\x04\x00\x00\x3f'
+    b'\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31'
+    b'\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e'
+    b'\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49'
+    b'\x43\x4f\x4d\x5f\x30\x39\x30\x58\x00\x00\x10\x01\x01\x00\x0a\x70'
+    b'\x79\x6e\x65\x74\x64\x69\x63\x6f\x6d\x00\x00\x53\x00\x00\x04\x00'
+    b'\x05\x00\x05'
+)
 
 # Called AET: ANY-SCP
 # Calling AET: GETSCU
@@ -79,23 +83,25 @@ a_associate_rq_user_async = b'\x01\x00\x00\x00\x00\xed\x00\x01\x00\x00\x41\x4e\x
 #       SOP Class: 1.2.840.10008.5.1.4.1.1.2 CT Image Storage
 #       SCU Role: 0
 #       SCP Role: 1
-a_associate_rq_role = b'\x01\x00\x00\x00\x00\xfc\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43' \
-                      b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x47\x45\x54\x53\x43\x55' \
-                      b'\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00' \
-                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e' \
-                      b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e' \
-                      b'\x31\x2e\x31\x20\x00\x00\x38\x01\x00\x00\x00\x30\x00\x00\x19\x31' \
-                      b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31' \
-                      b'\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x40\x00\x00\x13\x31\x2e\x32\x2e' \
-                      b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x2e\x31\x50' \
-                      b'\x00\x00\x5f\x51\x00\x00\x04\x00\x00\x3f\xfe\x52\x00\x00\x20\x31' \
-                      b'\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30' \
-                      b'\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30\x55' \
-                      b'\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39' \
-                      b'\x30\x54\x00\x00\x1d\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31' \
-                      b'\x30\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32' \
-                      b'\x00\x01'
+a_associate_rq_role = (
+    b'\x01\x00\x00\x00\x00\xfc\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43'
+    b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x47\x45\x54\x53\x43\x55'
+    b'\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e'
+    b'\x31\x2e\x31\x20\x00\x00\x38\x01\x00\x00\x00\x30\x00\x00\x19\x31'
+    b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31'
+    b'\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x40\x00\x00\x13\x31\x2e\x32\x2e'
+    b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x2e\x31\x50'
+    b'\x00\x00\x5f\x51\x00\x00\x04\x00\x00\x3f\xfe\x52\x00\x00\x20\x31'
+    b'\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30'
+    b'\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30\x55'
+    b'\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39'
+    b'\x30\x54\x00\x00\x1d\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31'
+    b'\x30\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32'
+    b'\x00\x01'
+)
 
 # Called AET: ANY-SCP
 # Calling AET: STORESCU
@@ -115,25 +121,27 @@ a_associate_rq_role = b'\x01\x00\x00\x00\x00\xfc\x00\x01\x00\x00\x41\x4e\x59\x2d
 #       Response requested: 0
 #       Primary field: pynetdicom
 #       Secondary field: p4ssw0rd
-a_associate_rq_user_id_user_pass = b'\x01\x00\x00\x00\x01\x1f\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43' \
-                                   b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x53\x54\x4f\x52\x45\x53' \
-                                   b'\x43\x55\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00' \
-                                   b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                                   b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e' \
-                                   b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e' \
-                                   b'\x31\x2e\x31\x20\x00\x00\x64\x01\x00\xff\x00\x30\x00\x00\x19\x31' \
-                                   b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31' \
-                                   b'\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x40\x00\x00\x13\x31\x2e\x32\x2e' \
-                                   b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x2e\x31\x40' \
-                                   b'\x00\x00\x13\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38' \
-                                   b'\x2e\x31\x2e\x32\x2e\x32\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34' \
-                                   b'\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\x56\x51' \
-                                   b'\x00\x00\x04\x00\x00\x40\x00\x52\x00\x00\x1b\x31\x2e\x32\x2e\x32' \
-                                   b'\x37\x36\x2e\x30\x2e\x37\x32\x33\x30\x30\x31\x30\x2e\x33\x2e\x30' \
-                                   b'\x2e\x33\x2e\x36\x2e\x30\x55\x00\x00\x0f\x4f\x46\x46\x49\x53\x5f' \
-                                   b'\x44\x43\x4d\x54\x4b\x5f\x33\x36\x30\x58\x00\x00\x18\x02\x00\x00' \
-                                   b'\x0a\x70\x79\x6e\x65\x74\x64\x69\x63\x6f\x6d\x00\x08\x70\x34\x73' \
-                                   b'\x73\x77\x30\x72\x64'
+a_associate_rq_user_id_user_pass = (
+    b'\x01\x00\x00\x00\x01\x1f\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43'
+    b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x53\x54\x4f\x52\x45\x53'
+    b'\x43\x55\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e'
+    b'\x31\x2e\x31\x20\x00\x00\x64\x01\x00\xff\x00\x30\x00\x00\x19\x31'
+    b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31'
+    b'\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x40\x00\x00\x13\x31\x2e\x32\x2e'
+    b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x2e\x31\x40'
+    b'\x00\x00\x13\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38'
+    b'\x2e\x31\x2e\x32\x2e\x32\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34'
+    b'\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\x56\x51'
+    b'\x00\x00\x04\x00\x00\x40\x00\x52\x00\x00\x1b\x31\x2e\x32\x2e\x32'
+    b'\x37\x36\x2e\x30\x2e\x37\x32\x33\x30\x30\x31\x30\x2e\x33\x2e\x30'
+    b'\x2e\x33\x2e\x36\x2e\x30\x55\x00\x00\x0f\x4f\x46\x46\x49\x53\x5f'
+    b'\x44\x43\x4d\x54\x4b\x5f\x33\x36\x30\x58\x00\x00\x18\x02\x00\x00'
+    b'\x0a\x70\x79\x6e\x65\x74\x64\x69\x63\x6f\x6d\x00\x08\x70\x34\x73'
+    b'\x73\x77\x30\x72\x64'
+)
 
 # Called AET: ANY-SCP
 # Calling AET: ECHOSCU
@@ -168,59 +176,63 @@ a_associate_rq_user_id_user_pass = b'\x01\x00\x00\x00\x01\x1f\x00\x01\x00\x00\x4
 #   SOP Class Extended Negotiation Item
 #       SOP Class: 1.2.840.10008.5.1.4.1.1.4 MR Image Storage
 #       Service Class App Info: b'\x02\x00\x03\x00\x01\x00'
-a_associate_rq_user_id_ext_neg = b'\x01\x00\x00\x00\x01\xab\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43' \
-                                 b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43' \
-                                 b'\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00' \
-                                 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                                 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e' \
-                                 b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e' \
-                                 b'\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31' \
-                                 b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31' \
-                                 b'\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30' \
-                                 b'\x38\x2e\x31\x2e\x32\x20\x00\x00\x36\x03\x00\x00\x00\x30\x00\x00' \
-                                 b'\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35' \
-                                 b'\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x40\x00\x00\x11\x31\x2e' \
-                                 b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x20' \
-                                 b'\x00\x00\x36\x05\x00\x00\x00\x30\x00\x00\x19\x31\x2e\x32\x2e\x38' \
-                                 b'\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31' \
-                                 b'\x2e\x31\x2e\x34\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e' \
-                                 b'\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\xa4\x51\x00\x00' \
-                                 b'\x04\x00\x00\x3f\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36' \
-                                 b'\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33' \
-                                 b'\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e' \
-                                 b'\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39\x30\x58\x00\x00\x10\x01' \
-                                 b'\x01\x00\x0a\x70\x79\x6e\x65\x74\x64\x69\x63\x6f\x6d\x00\x00\x53' \
-                                 b'\x00\x00\x04\x00\x05\x00\x05\x56\x00\x00\x21\x00\x19\x31\x2e\x32' \
-                                 b'\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34' \
-                                 b'\x2e\x31\x2e\x31\x2e\x32\x02\x00\x03\x00\x01\x00\x56\x00\x00\x21' \
-                                 b'\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e' \
-                                 b'\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x34\x02\x00\x03\x00\x01' \
-                                 b'\x00'
+a_associate_rq_user_id_ext_neg = (
+    b'\x01\x00\x00\x00\x01\xab\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43'
+    b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43'
+    b'\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e'
+    b'\x31\x2e\x31\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31'
+    b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31'
+    b'\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30'
+    b'\x38\x2e\x31\x2e\x32\x20\x00\x00\x36\x03\x00\x00\x00\x30\x00\x00'
+    b'\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35'
+    b'\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x32\x40\x00\x00\x11\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x20'
+    b'\x00\x00\x36\x05\x00\x00\x00\x30\x00\x00\x19\x31\x2e\x32\x2e\x38'
+    b'\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34\x2e\x31'
+    b'\x2e\x31\x2e\x34\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e'
+    b'\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\xa4\x51\x00\x00'
+    b'\x04\x00\x00\x3f\xfe\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36'
+    b'\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33'
+    b'\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59\x4e'
+    b'\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39\x30\x58\x00\x00\x10\x01'
+    b'\x01\x00\x0a\x70\x79\x6e\x65\x74\x64\x69\x63\x6f\x6d\x00\x00\x53'
+    b'\x00\x00\x04\x00\x05\x00\x05\x56\x00\x00\x21\x00\x19\x31\x2e\x32'
+    b'\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x35\x2e\x31\x2e\x34'
+    b'\x2e\x31\x2e\x31\x2e\x32\x02\x00\x03\x00\x01\x00\x56\x00\x00\x21'
+    b'\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e'
+    b'\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x34\x02\x00\x03\x00\x01'
+    b'\x00'
+)
 
 # Needs to be updated - no presentation context items?
-a_associate_rq_com_ext_neg = b'\x02\x00\x00\x00\x01\x49\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43' \
-                             b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43' \
-                             b'\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00' \
-                             b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                             b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e' \
-                             b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e' \
-                             b'\x31\x2e\x31\x21\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00\x11\x31' \
-                             b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32' \
-                             b'\x21\x00\x00\x19\x03\x00\x00\x00\x40\x00\x00\x11\x31\x2e\x32\x2e' \
-                             b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x21\x00\x00' \
-                             b'\x19\x05\x00\x00\x00\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30' \
-                             b'\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\x91\x51\x00' \
-                             b'\x00\x04\x00\x00\x40\x00\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32' \
-                             b'\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e' \
-                             b'\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59' \
-                             b'\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39\x30\x57\x00\x00\x4f' \
-                             b'\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e' \
-                             b'\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x34\x00\x11\x31\x2e\x32' \
-                             b'\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x34\x2e\x32\x00\x1f' \
-                             b'\x00\x1d\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e' \
-                             b'\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x38\x38\x2e\x32\x32'
-
-############################# A-ASSOCIATE-AC PDU ###############################
+a_associate_rq_com_ext_neg = (
+    b'\x02\x00\x00\x00\x01\x49\x00\x01\x00\x00\x41\x4e\x59\x2d\x53\x43'
+    b'\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f\x53\x43'
+    b'\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e'
+    b'\x31\x2e\x31\x21\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00\x11\x31'
+    b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32'
+    b'\x21\x00\x00\x19\x03\x00\x00\x00\x40\x00\x00\x11\x31\x2e\x32\x2e'
+    b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x21\x00\x00'
+    b'\x19\x05\x00\x00\x00\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30'
+    b'\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00\x00\x91\x51\x00'
+    b'\x00\x04\x00\x00\x40\x00\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32'
+    b'\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e'
+    b'\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30\x55\x00\x00\x0e\x50\x59'
+    b'\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30\x39\x30\x57\x00\x00\x4f'
+    b'\x00\x19\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e'
+    b'\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x34\x00\x11\x31\x2e\x32'
+    b'\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x34\x2e\x32\x00\x1f'
+    b'\x00\x1d\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e'
+    b'\x35\x2e\x31\x2e\x34\x2e\x31\x2e\x31\x2e\x38\x38\x2e\x32\x32'
+)
+
+############################# A-ASSOCIATE-AC PDU #############################
 # Called AET: ANY-SCP
 # Calling AET: ECHOSCU
 # Application Context Name: 1.2.840.10008.3.1.1.1
@@ -232,20 +244,22 @@ a_associate_rq_com_ext_neg = b'\x02\x00\x00\x00\x01\x49\x00\x01\x00\x00\x41\x4e\
 #   Max Length Received: 16384
 #   Implementation Class UID: 1.2.276.0.7230010.3.0.3.6.0
 #   Implementation Version Name: OFFIS_DCMTK_360
-a_associate_ac = b'\x02\x00\x00\x00\x00\xb8\x00\x01\x00\x00\x41\x4e\x59\x2d' \
-                 b'\x53\x43\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43' \
-                 b'\x48\x4f\x53\x43\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20' \
-                 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                 b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                 b'\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e\x32\x2e\x38\x34' \
-                 b'\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e\x31\x2e' \
-                 b'\x31\x21\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00\x11\x31' \
-                 b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31' \
-                 b'\x2e\x32\x50\x00\x00\x3a\x51\x00\x00\x04\x00\x00\x40\x00' \
-                 b'\x52\x00\x00\x1b\x31\x2e\x32\x2e\x32\x37\x36\x2e\x30\x2e' \
-                 b'\x37\x32\x33\x30\x30\x31\x30\x2e\x33\x2e\x30\x2e\x33\x2e' \
-                 b'\x36\x2e\x30\x55\x00\x00\x0f\x4f\x46\x46\x49\x53\x5f\x44' \
-                 b'\x43\x4d\x54\x4b\x5f\x33\x36\x30'
+a_associate_ac = (
+    b'\x02\x00\x00\x00\x00\xb8\x00\x01\x00\x00\x41\x4e\x59\x2d'
+    b'\x53\x43\x50\x20\x20\x20\x20\x20\x20\x20\x20\x20\x45\x43'
+    b'\x48\x4f\x53\x43\x55\x20\x20\x20\x20\x20\x20\x20\x20\x20'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e\x32\x2e\x38\x34'
+    b'\x30\x2e\x31\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e\x31\x2e'
+    b'\x31\x21\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00\x11\x31'
+    b'\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31'
+    b'\x2e\x32\x50\x00\x00\x3a\x51\x00\x00\x04\x00\x00\x40\x00'
+    b'\x52\x00\x00\x1b\x31\x2e\x32\x2e\x32\x37\x36\x2e\x30\x2e'
+    b'\x37\x32\x33\x30\x30\x31\x30\x2e\x33\x2e\x30\x2e\x33\x2e'
+    b'\x36\x2e\x30\x55\x00\x00\x0f\x4f\x46\x46\x49\x53\x5f\x44'
+    b'\x43\x4d\x54\x4b\x5f\x33\x36\x30'
+)
 
 # Called AET: ANY-SCP
 # Calling AET: ECHOSCU
@@ -260,27 +274,29 @@ a_associate_ac = b'\x02\x00\x00\x00\x00\xb8\x00\x01\x00\x00\x41\x4e\x59\x2d' \
 #   Implementation Version Name: OFFIS_DCMTK_360
 #   User Identity AC
 #       Server response: b'Accepted'
-a_associate_ac_user = b'\x02\x00\x00\x00\x00\xb8\x00\x01\x00\x00' \
-                      b'\x41\x4e\x59\x2d\x53\x43\x50\x20\x20\x20' \
-                      b'\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f' \
-                      b'\x53\x43\x55\x20\x20\x20\x20\x20\x20\x20' \
-                      b'\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00' \
-                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                      b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' \
-                      b'\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e' \
-                      b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30' \
-                      b'\x38\x2e\x33\x2e\x31\x2e\x31\x2e\x31\x21' \
-                      b'\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00' \
-                      b'\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31' \
-                      b'\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00' \
-                      b'\x00\x48\x51\x00\x00\x04\x00\x00\x40\x00' \
-                      b'\x52\x00\x00\x1b\x31\x2e\x32\x2e\x32\x37' \
-                      b'\x36\x2e\x30\x2e\x37\x32\x33\x30\x30\x31' \
-                      b'\x30\x2e\x33\x2e\x30\x2e\x33\x2e\x36\x2e' \
-                      b'\x30\x55\x00\x00\x0f\x4f\x46\x46\x49\x53' \
-                      b'\x5f\x44\x43\x4d\x54\x4b\x5f\x33\x36\x30' \
-                      b'\x59\x00\x00\x0a\x00\x08\x41\x63\x63\x65' \
-                      b'\x70\x74\x65\x64'
+a_associate_ac_user = (
+    b'\x02\x00\x00\x00\x00\xb8\x00\x01\x00\x00'
+    b'\x41\x4e\x59\x2d\x53\x43\x50\x20\x20\x20'
+    b'\x20\x20\x20\x20\x20\x20\x45\x43\x48\x4f'
+    b'\x53\x43\x55\x20\x20\x20\x20\x20\x20\x20'
+    b'\x20\x20\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
+    b'\x00\x00\x00\x00\x10\x00\x00\x15\x31\x2e'
+    b'\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30'
+    b'\x38\x2e\x33\x2e\x31\x2e\x31\x2e\x31\x21'
+    b'\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00'
+    b'\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31'
+    b'\x30\x30\x30\x38\x2e\x31\x2e\x32\x50\x00'
+    b'\x00\x48\x51\x00\x00\x04\x00\x00\x40\x00'
+    b'\x52\x00\x00\x1b\x31\x2e\x32\x2e\x32\x37'
+    b'\x36\x2e\x30\x2e\x37\x32\x33\x30\x30\x31'
+    b'\x30\x2e\x33\x2e\x30\x2e\x33\x2e\x36\x2e'
+    b'\x30\x55\x00\x00\x0f\x4f\x46\x46\x49\x53'
+    b'\x5f\x44\x43\x4d\x54\x4b\x5f\x33\x36\x30'
+    b'\x59\x00\x00\x0a\x00\x08\x41\x63\x63\x65'
+    b'\x70\x74\x65\x64'
+)
 
 # Issue 342
 # Called AET: ANY-SCP
@@ -354,29 +370,29 @@ a_associate_ac_no_ts = (
 )
 
 
-############################# A-ASSOCIATE-RJ PDU ###############################
+############################# A-ASSOCIATE-RJ PDU #############################
 # Result: Rejected (Permanent)
 # Source: DUL service-user
 # Reason: No reason given
 a_associate_rj = b"\x03\x00\x00\x00\x00\x04\x00\x01\x01\x01"
 
-############################## A-RELEASE-RJ PDU ################################
+############################## A-RELEASE-RJ PDU ##############################
 a_release_rq = b"\x05\x00\x00\x00\x00\x04\x00\x00\x00\x00"
 
-############################## A-RELEASE-RP PDU ################################
+############################## A-RELEASE-RP PDU ##############################
 a_release_rp = b"\x06\x00\x00\x00\x00\x04\x00\x00\x00\x00"
 
-############################### A-ABORT-RQ PDU #################################
+############################### A-ABORT-RQ PDU ###############################
 # Source: DUL service-user
 # Reason: No reason given
 a_abort = b"\x07\x00\x00\x00\x00\x04\x00\x00\x00\x00"
 
-############################## A-P-ABORT-RQ PDU ################################
+############################## A-P-ABORT-RQ PDU ##############################
 # Source: DUL service-provider`
 # Reason: Unrecognised PDU parameter
 a_p_abort = b"\x07\x00\x00\x00\x00\x04\x00\x00\x02\x04"
 
-################################ P-DATA-TF PDU #################################
+################################ P-DATA-TF PDU ###############################
 # Contains a C-ECHO message
 # Context ID: 1
 # Data: \x03\x00\x00\x00\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x00\x02\x00
@@ -399,12 +415,14 @@ a_p_abort = b"\x07\x00\x00\x00\x00\x04\x00\x00\x02\x04"
 #       00 00 20 01 | 02 00 00 00 | - MessageIDBeingRespondedTo (1)
 #       00 00 00 08 |             | - Command Data Set Type (257)
 #       00 00 00 09 | - Status (0)
-p_data_tf = b"\x04\x00\x00\x00\x00\x54\x00\x00\x00\x50\x01\x03\x00\x00\x00" \
-            b"\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x00\x02\x00\x12\x00" \
-            b"\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38" \
-            b"\x2e\x31\x2e\x31\x00\x00\x00\x00\x01\x02\x00\x00\x00\x30\x80" \
-            b"\x00\x00\x20\x01\x02\x00\x00\x00\x01\x00\x00\x00\x00\x08\x02" \
-            b"\x00\x00\x00\x01\x01\x00\x00\x00\x09\x02\x00\x00\x00\x00\x00"
+p_data_tf = (
+    b"\x04\x00\x00\x00\x00\x54\x00\x00\x00\x50\x01\x03\x00\x00\x00"
+    b"\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x00\x02\x00\x12\x00"
+    b"\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38"
+    b"\x2e\x31\x2e\x31\x00\x00\x00\x00\x01\x02\x00\x00\x00\x30\x80"
+    b"\x00\x00\x20\x01\x02\x00\x00\x00\x01\x00\x00\x00\x00\x08\x02"
+    b"\x00\x00\x00\x01\x01\x00\x00\x00\x09\x02\x00\x00\x00\x00\x00"
+)
 
 # C-ECHO RQ
 p_data_tf_rq = (
@@ -424,66 +442,83 @@ p_data_tf_rq = (
 #   Max operations performed: 5
 asynchronous_window_ops = b'\x53\x00\x00\x04\x00\x05\x00\x05'
 
-############################## User Identity Sub Item ##########################
+############################## User Identity Sub Item ########################
 # -RQ
 # Type: 1
 # Response requested: 0
 # Primary field: pynetdicom
 # Secondary field: (none)
-user_identity_rq_user_nopw = b'\x58\x00\x00\x10\x01\x01\x00\x0a\x70\x79\x6e\x65\x74\x64\x69\x63' \
-                             b'\x6f\x6d\x00\x00'
+user_identity_rq_user_nopw = (
+    b'\x58\x00\x00\x10\x01\x01\x00\x0a\x70\x79\x6e\x65\x74\x64\x69\x63'
+    b'\x6f\x6d\x00\x00'
+)
 
 # -RQ
 # Type: 1
 # Response requested: 0
 # Primary field: pynetdicom
 # Secondary field: p4ssw0rd
-user_identity_rq_user_pass = b'\x58\x00\x00\x18\x02\x00\x00\x0a\x70\x79\x6e\x65\x74\x64\x69\x63' \
-                             b'\x6f\x6d\x00\x08\x70\x34\x73\x73\x77\x30\x72\x64'
+user_identity_rq_user_pass = (
+    b'\x58\x00\x00\x18\x02\x00\x00\x0a\x70\x79\x6e\x65\x74\x64\x69\x63'
+    b'\x6f\x6d\x00\x08\x70\x34\x73\x73\x77\x30\x72\x64'
+)
 
 # -AC
 # Server response: b'Accepted'
-user_identity_ac = b'\x59\x00\x00\x0a\x00\x08\x41\x63\x63\x65' \
-                   b'\x70\x74\x65\x64'
+user_identity_ac = (
+    b'\x59\x00\x00\x0a\x00\x08\x41\x63\x63\x65\x70\x74\x65\x64'
+)
 
-########################### Application Context Item ###########################
+########################### Application Context Item #########################
 # Application Context Name: 1.2.840.10008.3.1.1.1
-application_context = b"\x10\x00\x00\x15\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31" \
-                      b"\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e\x31\x2e\x31" \
+application_context = (
+    b"\x10\x00\x00\x15\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31"
+    b"\x30\x30\x30\x38\x2e\x33\x2e\x31\x2e\x31\x2e\x31"
+)
 
-########################## Presentation Context  Items #########################
+########################## Presentation Context  Items #######################
 # -RQ
 # Presentation Context ID: 1
 # Abstract Syntax: 1.2.840.10008.1.1 Verification SOP Class
 # Transfer Syntax: 1.2.840.10008.1.2 Implicit VR Little Endian
-presentation_context_rq = b'\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31\x2e\x32\x2e' \
-                          b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31\x40\x00\x00' \
-                          b'\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31' \
-                          b'\x2e\x32'
+presentation_context_rq = (
+    b'\x20\x00\x00\x2e\x01\x00\x00\x00\x30\x00\x00\x11\x31\x2e\x32\x2e'
+    b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x31\x40\x00\x00'
+    b'\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31'
+    b'\x2e\x32'
+)
 
 # -AC
 # Presentation Context ID: 1
 # Result: Accepted
 # Transfer Syntax: 1.2.840.10008.1.2 Implicit VR Little Endian
-presentation_context_ac = b'\x21\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00\x11\x31\x2e\x32\x2e' \
-                          b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32'
+presentation_context_ac = (
+    b'\x21\x00\x00\x19\x01\x00\x00\x00\x40\x00\x00\x11\x31\x2e\x32\x2e'
+    b'\x38\x34\x30\x2e\x31\x30\x30\x30\x38\x2e\x31\x2e\x32'
+)
 
-############################ Abstract Syntax Sub Item ##########################
+############################ Abstract Syntax Sub Item ########################
 # Abstract Syntax: 1.2.840.10008.1.1 Verification SOP Class
-abstract_syntax = b'\x30\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30' \
-                  b'\x38\x2e\x31\x2e\x31'
+abstract_syntax = (
+    b'\x30\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30'
+    b'\x38\x2e\x31\x2e\x31'
+)
 
-############################ Transfer Syntax Sub Item ##########################
+############################ Transfer Syntax Sub Item ########################
 # Transfer Syntax: 1.2.840.10008.1.2 Implicit VR Little Endian
-transfer_syntax = b'\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30' \
-                  b'\x38\x2e\x31\x2e\x32'
+transfer_syntax = (
+    b'\x40\x00\x00\x11\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30\x30'
+    b'\x38\x2e\x31\x2e\x32'
+)
 
-######################## Presentation Data Value Sub Item ######################
-presentation_data = b'\x03\x00\x00\x00\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x00\x02' \
-                    b'\x00\x12\x00\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30' \
-                    b'\x30\x38\x2e\x31\x2e\x31\x00\x00\x00\x00\x01\x02\x00\x00\x00\x30' \
-                    b'\x80\x00\x00\x20\x01\x02\x00\x00\x00\x01\x00\x00\x00\x00\x08\x02' \
-                    b'\x00\x00\x00\x01\x01\x00\x00\x00\x09\x02\x00\x00\x00\x00\x00'
+######################## Presentation Data Value Sub Item ####################
+presentation_data = (
+    b'\x03\x00\x00\x00\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x00\x02'
+    b'\x00\x12\x00\x00\x00\x31\x2e\x32\x2e\x38\x34\x30\x2e\x31\x30\x30'
+    b'\x30\x38\x2e\x31\x2e\x31\x00\x00\x00\x00\x01\x02\x00\x00\x00\x30'
+    b'\x80\x00\x00\x20\x01\x02\x00\x00\x00\x01\x00\x00\x00\x00\x08\x02'
+    b'\x00\x00\x00\x01\x01\x00\x00\x00\x09\x02\x00\x00\x00\x00\x00'
+)
 
 # Context ID: 1
 # Data: \x03\x00\x00\x00\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x00\x02\x00
@@ -493,22 +528,26 @@ presentation_data = b'\x03\x00\x00\x00\x00\x04\x00\x00\x00\x42\x00\x00\x00\x00\x
 #       \x01\x00\x00\x00\x09\x02\x00\x00\x00\x00\x00
 presentation_data_value = b'\x00\x00\x00\x50\x01' + presentation_data
 
-######################## Maximum Length Received Sub Item ######################
+######################## Maximum Length Received Sub Item ####################
 # Max Length Received: 16382
 maximum_length_received = b'\x51\x00\x00\x04\x00\x00\x3f\xfe'
 
-######################## Implementaion Class UID Sub Item ######################
+######################## Implementaion Class UID Sub Item ####################
 # Implementation Class UID: 1.2.826.0.1.3680043.9.3811.0.9.0
-implementation_class_uid = b'\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e' \
-                           b'\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30' \
-                           b'\x2e\x39\x2e\x30'
+implementation_class_uid = (
+    b'\x52\x00\x00\x20\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e'
+    b'\x33\x36\x38\x30\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30'
+    b'\x2e\x39\x2e\x30'
+)
 
-##################### Implementation Version Name Sub Item #####################
+##################### Implementation Version Name Sub Item ###################
 # Implementation Version Name: PYNETDICOM_090
-implementation_version_name = b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f' \
-                              b'\x30\x39\x30'
+implementation_version_name = (
+    b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f'
+    b'\x30\x39\x30'
+)
 
-########################### Role Selection Sub Item ############################
+########################### Role Selection Sub Item ##########################
 # SOP Class: 1.2.840.10008.5.1.4.1.1.2 CT Image Storage
 # SCU Role: 0
 # SCP Role: 1
@@ -528,16 +567,18 @@ role_selection_odd = (
     b'\x00\x01'
 )
 
-############################ User Information Item #############################
+############################ User Information Item ###########################
 # Implementation Class UID: 1.2.826.0.1.3680043.9.3811.0.9.0
 # Implementation Version Name: PYNETDICOM_090
-user_information = b'\x50\x00\x00\x3e\x51\x00\x00\x04\x00\x00\x3f\xfe\x52\x00\x00\x20' \
-            b'\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30' \
-            b'\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30' \
-            b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30' \
-            b'\x39\x30'
+user_information = (
+    b'\x50\x00\x00\x3e\x51\x00\x00\x04\x00\x00\x3f\xfe\x52\x00\x00\x20'
+    b'\x31\x2e\x32\x2e\x38\x32\x36\x2e\x30\x2e\x31\x2e\x33\x36\x38\x30'
+    b'\x30\x34\x33\x2e\x39\x2e\x33\x38\x31\x31\x2e\x30\x2e\x39\x2e\x30'
+    b'\x55\x00\x00\x0e\x50\x59\x4e\x45\x54\x44\x49\x43\x4f\x4d\x5f\x30'
+    b'\x39\x30'
+)
 
-######################## Extended Negotiation Sub Item #########################
+######################## Extended Negotiation Sub Item #######################
 # SOP Class: 1.2.840.10008.5.1.4.1.1.2 CT Image Storage
 # Service Class App Info: b'\x02\x00\x03\x00\x01\x00'
 extended_negotiation = (
@@ -546,7 +587,7 @@ extended_negotiation = (
     b'\x00\x03\x00\x01\x00'
 )
 
-#################### Common Extended Negotiation Sub Item ######################
+#################### Common Extended Negotiation Sub Item ####################
 # SOP Class: 1.2.840.10008.5.1.4.1.1.4 MR Image Storage
 # Service Class: 1.2.840.10008.4.2 Storage Service Class
 # Related general SOP Class ID(s):
diff --git a/pynetdicom/tests/test_assoc.py b/pynetdicom/tests/test_assoc.py
index 664a2f20a..6ab616d03 100644
--- a/pynetdicom/tests/test_assoc.py
+++ b/pynetdicom/tests/test_assoc.py
@@ -38,7 +38,7 @@ from pynetdicom._globals import MODE_REQUESTOR, MODE_ACCEPTOR
 from pynetdicom.pdu_primitives import (
     UserIdentityNegotiation, SOPClassExtendedNegotiation,
     SOPClassCommonExtendedNegotiation, SCP_SCU_RoleSelectionNegotiation,
-    AsynchronousOperationsWindowNegotiation, A_ASSOCIATE,
+    AsynchronousOperationsWindowNegotiation, A_ASSOCIATE
 )
 from pynetdicom.sop_class import (
     VerificationSOPClass,
@@ -53,7 +53,6 @@ from pynetdicom.sop_class import (
     UnifiedProcedureStepPushSOPClass,
     UnifiedProcedureStepWatchSOPClass
 )
-from .encoded_pdu_items import a_associate_ac
 
 
 #debug_logger()
@@ -561,6 +560,32 @@ class TestAssociation(object):
 
         scp.shutdown()
 
+    def test_unknown_abort_source(self):
+        """Test an unknown abort source handled correctly #561"""
+        def handle_req(event):
+            pdu = b"\x07\x00\x00\x00\x00\x04\x00\x00\x01\x00"
+            event.assoc.dul.socket.send(pdu)
+            # Give the requestor time to process the message before killing
+            #   the connection
+            time.sleep(0.1)
+
+        self.ae = ae = AE()
+        ae.acse_timeout = 5
+        ae.dimse_timeout = 5
+        ae.network_timeout = 5
+        ae.add_supported_context(VerificationSOPClass)
+
+        hh = [(evt.EVT_REQUESTED, handle_req)]
+
+        scp = ae.start_server(('', 11112), block=False, evt_handlers=hh)
+
+        ae.add_requested_context(VerificationSOPClass)
+        assoc = ae.associate('localhost', 11112)
+        assert not assoc.is_established
+        assert assoc.is_aborted
+
+        scp.shutdown()
+
 
 class TestCStoreSCP(object):
     """Tests for Association._c_store_scp()."""
diff --git a/pynetdicom/tests/test_primitives.py b/pynetdicom/tests/test_primitives.py
index b5f73b225..d45fc4178 100644
--- a/pynetdicom/tests/test_primitives.py
+++ b/pynetdicom/tests/test_primitives.py
@@ -1008,6 +1008,8 @@ class TestPrimitive_A_ABORT(object):
         primitive = A_ABORT()
         primitive.abort_source = 0
         assert primitive.abort_source == 0
+        primitive.abort_source = 1
+        assert primitive.abort_source == 1
         primitive.abort_source = 2
         assert primitive.abort_source == 2
 
@@ -1016,7 +1018,7 @@ class TestPrimitive_A_ABORT(object):
         primitive = A_ABORT()
 
         with pytest.raises(ValueError):
-            primitive.abort_source = 1
+            primitive.abort_source = 3
 
         with pytest.raises(ValueError):
             primitive.abort_source