Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
event_str = 'Evt1'
elif primitive.result == 0x00:
# A-ASSOCIATE Response (accept)
event_str = 'Evt7'
else:
# A-ASSOCIATE Response (reject)
event_str = 'Evt8'
elif primitive.__class__ == A_RELEASE:
if primitive.result is None:
# A-Release Request
event_str = 'Evt11'
else:
# A-Release Response
# result is 'affirmative'
event_str = 'Evt14'
elif primitive.__class__ in (A_ABORT, A_P_ABORT):
event_str = 'Evt15'
elif primitive.__class__ == P_DATA:
event_str = 'Evt9'
else:
raise ValueError("_primitive_to_event(): invalid primitive")
return event_str
evt.trigger(self.assoc, evt.EVT_REJECTED, {})
self.dul.kill_dul()
else:
LOGGER.warning(
"Received an invalid A-ASSOCIATE response from the peer"
)
LOGGER.info("Aborting Association")
self.send_abort(0x02)
self.assoc.is_aborted = True
self.assoc.is_established = False
# Event handler - association aborted
evt.trigger(self.assoc, evt.EVT_ABORTED, {})
self.assoc.kill()
# Association aborted
elif isinstance(rsp, (A_ABORT, A_P_ABORT)):
LOGGER.info("Association Aborted")
self.assoc.is_established = False
self.assoc.is_aborted = True
evt.trigger(self.assoc, evt.EVT_ABORTED, {})
self.dul.kill_dul()
else:
self.assoc.is_established = False
self.dul.kill_dul()
# Send A-ABORT PDU (service-dul source), issue A-P-ABORT
# indication, and start ARTIM timer.
dul.pdu = A_ABORT_RQ()
dul.pdu.source = 0x02
dul.pdu.reason_diagnostic = 0x00
dul.primitive = dul.pdu.to_primitive()
dul.primitive.abort_source = 0x02
dul.primitive.result = 0x01
dul.primitive.diagnostic = 0x01
dul.socket.send(dul.pdu.encode())
evt.trigger(dul.assoc, evt.EVT_PDU_SENT, {'pdu' : dul.pdu})
# Issue A-P-ABORT to user
primitive = A_P_ABORT()
primitive.provider_reason = 0x05
dul.to_user_queue.put(primitive)
dul.artim_timer.start()
return 'Sta13'
Returns
-------
pdu_primitives.A_ABORT or pdu_primitives.A_P_ABORT
The primitive representation of the current 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:
primitive = A_P_ABORT()
primitive.provider_reason = self.reason_diagnostic
return primitive
dul : dul.DULServiceProvider
The DICOM Upper Layer Service instance for the local AE
Returns
-------
str
``'Sta1'``, the next state of the state machine
"""
assoc = dul.assoc
remote = assoc.acceptor if assoc.is_requestor else assoc.requestor
address = (remote.address, remote.port)
evt.trigger(dul.assoc, evt.EVT_CONN_CLOSE, {'address' : address})
# Issue A-P-ABORT indication primitive.
primitive = A_P_ABORT()
primitive.provider_reason = 0x00
dul.to_user_queue.put(primitive)
dul.kill_dul()
return 'Sta1'
Parameters
----------
primitive : pdu_primitives.A_ABORT or pdu_primitives.A_P_ABORT
The primitive to use to set the current PDU field values.
"""
from pynetdicom.pdu_primitives import A_ABORT, A_P_ABORT
# User initiated abort
if primitive.__class__ == A_ABORT:
# The reason field shall be 0x00 when the source is DUL
# service-user
self.reason_diagnostic = 0
self.source = primitive.abort_source
# User provider primitive abort
elif primitive.__class__ == A_P_ABORT:
self.reason_diagnostic = primitive.provider_reason
self.source = 2
- ``0x05`` - unexpected PDU parameter
- ``0x06`` - invalid PDU parameter value
Raises
------
ValueError
If the `reason` value is invalid.
"""
if reason not in [0x00, 0x01, 0x02, 0x04, 0x05, 0x06]:
raise ValueError("Invalid 'reason' parameter value")
# The following parameters must be set for an A-P-ABORT primitive
# (* sent in A-ABORT PDU):
# Abort Source* (always 0x02)
# Provider Reason*
primitive = A_P_ABORT()
primitive.provider_reason = reason
self.dul.send_pdu(primitive)
self.assoc.is_aborted = True
self.assoc.is_established = False
If receive a association request or invalid PDU while waiting for
connection to close, send A-ABORT PDU
State-event triggers: Sta13 + Evt6/Evt19
Parameters
----------
dul : dul.DULServiceProvider
The DICOM Upper Layer Service instance for the local AE
Returns
-------
str
``'Sta13'``, the next state of the state machine
"""
primitive = A_P_ABORT()
primitive.provider_reason = 0x02
# Send A-ABORT PDU.
pdu = A_ABORT_RQ()
pdu.from_primitive(primitive)
dul.socket.send(dul.pdu.encode())
evt.trigger(dul.assoc, evt.EVT_PDU_SENT, {'pdu' : dul.pdu})
return 'Sta13'