Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
APP_LOGGER.error('Could not write file to specified directory:')
APP_LOGGER.error(" {0!s}".format(os.path.dirname(filename)))
APP_LOGGER.error('Directory may not exist or you may not have write '
'permission')
# Failed - Out of Resources - IOError
status_ds.Status = 0xA700
except Exception as exc:
APP_LOGGER.error('Could not write file to specified directory:')
APP_LOGGER.error(" {0!s}".format(os.path.dirname(filename)))
APP_LOGGER.exception(exc)
# Failed - Out of Resources - Miscellaneous error
status_ds.Status = 0xA701
return status_ds
handlers = [(evt.EVT_C_STORE, handle_store)]
# Test output-directory
if args.output_directory is not None:
if not os.access(args.output_directory, os.W_OK|os.X_OK):
APP_LOGGER.error('No write permissions or the output '
'directory may not exist:')
APP_LOGGER.error(" {0!s}".format(args.output_directory))
sys.exit()
# Create application entity
ae = AE(ae_title=args.aetitle)
# Add presentation contexts with specified transfer syntaxes
for context in StoragePresentationContexts:
ae.add_supported_context(context.abstract_syntax, transfer_syntax)
for context in VerificationPresentationContexts:
----------
primitive : pdu_primitives.PDU sub-class
A service primitive, one of:
.. currentmodule:: pynetdicom.pdu_primitives
* :class:`A_ASSOCIATE`
* :class:`A_RELEASE`
* :class:`A_ABORT`
* :class:`A_P_ABORT`
* :class:`P_DATA`
"""
# Event handler - ACSE sent primitive to the DUL service
acse_primitives = (A_ASSOCIATE, A_RELEASE, A_ABORT, A_P_ABORT)
if isinstance(primitive, acse_primitives):
evt.trigger(
self.assoc, evt.EVT_ACSE_SENT, {'primitive' : primitive}
)
self.to_provider_queue.put(primitive)
raise InvalidEventError(msg)
action_name = TRANSITION_TABLE[(event, self.current_state)]
# action is the (description, function, state) tuple
# associated with the action_name
action = ACTIONS[action_name]
# Attempt to execute the action and move the state machine to its
# next state
try:
# Execute the required action
next_state = action[1](self.dul)
# Event handler - FSM transition
evt.trigger(
self.dul.assoc,
evt.EVT_FSM_TRANSITION,
{
'action' : action_name,
'current_state' : self.current_state,
'fsm_event' : event,
'next_state' : next_state
}
)
#print(
# "{} + {} -> {} -> {}"
# .format(self.current_state, event, action_name, next_state)
#)
# Move the state machine to the next state
self.transition(next_state)
except IOError:
APP_LOGGER.error('Could not write file to specified directory:')
APP_LOGGER.error(" {0!s}".format(os.path.dirname(filename)))
APP_LOGGER.error('Directory may not exist or you may not have write '
'permission')
# Failed - Out of Resources - IOError
status_ds.Status = 0xA700
except:
APP_LOGGER.error('Could not write file to specified directory:')
APP_LOGGER.error(" {0!s}".format(os.path.dirname(filename)))
# Failed - Out of Resources - Miscellaneous error
status_ds.Status = 0xA701
return status_ds
handlers = [(evt.EVT_C_STORE, handle_store)]
# Request association with remote
assoc = ae.associate(args.peer,
args.port,
ae_title=args.called_aet,
ext_neg=ext_neg,
evt_handlers=handlers)
# Send query
if assoc.is_established:
response = assoc.send_c_get(d, query_model)
for status, identifier in response:
pass
assoc.release()
for cx in negotiated_contexts if cx.result == 0x00
}
self.assoc._rejected_cx = [
cx for cx in negotiated_contexts if cx.result != 0x00
]
# pylint: enable=protected-access
evt.trigger(self.assoc, evt.EVT_ACCEPTED, {})
# No acceptable presentation contexts
if not self.assoc.accepted_contexts:
LOGGER.error("No accepted presentation contexts")
self.send_abort(0x02)
self.assoc.is_aborted = True
self.assoc.is_established = False
evt.trigger(self.assoc, evt.EVT_ABORTED, {})
self.assoc.kill()
else:
LOGGER.info('Association Accepted')
self.assoc.is_established = True
evt.trigger(self.assoc, evt.EVT_ESTABLISHED, {})
elif hasattr(rsp, 'result') and rsp.result in [0x01, 0x02]:
# 0x01 is rejected (permanent)
# 0x02 is rejected (transient)
LOGGER.info('Association Rejected:')
LOGGER.info(
'Result: {}, Source: {}'
.format(rsp.result_str, rsp.source_str)
)
LOGGER.info('Reason: {}'.format(rsp.reason_str))
self.assoc.is_rejected = True
def _bind_defaults(self):
"""Bind the default event handlers."""
# Intervention event handlers
for event in evt._INTERVENTION_EVENTS:
handler = evt.get_default_handler(event)
self.bind(event, handler)
# Notification event handlers
if _config.LOG_HANDLER_LEVEL == 'standard':
self.bind(evt.EVT_DIMSE_RECV, standard_dimse_recv_handler)
self.bind(evt.EVT_DIMSE_SENT, standard_dimse_sent_handler)
self.bind(evt.EVT_PDU_RECV, standard_pdu_recv_handler)
self.bind(evt.EVT_PDU_SENT, standard_pdu_sent_handler)
----------
req : dimse_primitives.C_ECHO
The C-ECHO request primitive sent by the peer.
context : presentation.PresentationContext
The presentation context that the SCP is operating under.
"""
# Build C-ECHO response primitive
rsp = C_ECHO()
rsp.MessageID = req.MessageID
rsp.MessageIDBeingRespondedTo = req.MessageID
rsp.AffectedSOPClassUID = req.AffectedSOPClassUID
try:
status = evt.trigger(
self.assoc,
evt.EVT_C_ECHO,
{'request' : req, 'context' : context.as_tuple}
)
if isinstance(status, Dataset):
if 'Status' not in status:
raise AttributeError(
"The 'status' dataset returned by the handler "
"bound to 'evt.EVT_C_ECHO' must contain"
"a (0000,0900) Status element"
)
for elem in status:
if hasattr(rsp, elem.keyword):
setattr(rsp, elem.keyword, elem.value)
else:
LOGGER.warning(
"The 'status' dataset returned by the handler "
"bound to 'evt.EVT_C_ECHO' contained an "
to the :attr:`~DIMSEServiceProvider.msg_queue`.
This makes it possible to process incoming P-DATA primitives into
DIMSE messages while a service class implementation is running.
Parameters
----------
primitive : pdu_primitives.P_DATA
A P-DATA primitive received from the peer to be processed.
"""
if self.message is None:
self.message = DIMSEMessage()
if self.message.decode_msg(primitive):
# Trigger event
evt.trigger(
self.assoc, evt.EVT_DIMSE_RECV, {'message' : self.message}
)
context_id = self.message.context_id
try:
primitive = self.message.message_to_primitive()
except Exception as exc:
LOGGER.error("Received an invalid DIMSE message")
LOGGER.exception(exc)
self.dul.event_queue.put('Evt19')
return
# Keep C-CANCEL requests separate from other messages
# Only allow up to 10 C-CANCEL requests
if isinstance(primitive, C_CANCEL) and len(self.cancel_req) < 10:
msg_id = primitive.MessageIDBeingRespondedTo
def _check_sop_class_common_extended(self):
"""Check the user's response to a SOP Class Common Extended request.
Returns
-------
dict
The {SOP Class UID : SOPClassCommonExtendedNegotiation} items for
the accepted SOP Class Common Extended negotiation items.
"""
# pylint: disable=broad-except
try:
rsp = evt.trigger(
self.assoc,
evt.EVT_SOP_COMMON,
{'items' : self.requestor.sop_class_common_extended}
)
except Exception as exc:
LOGGER.error(
"Exception raised in handler bound to 'evt.EVT_SOP_COMMON'"
)
LOGGER.exception(exc)
return {}
try:
rsp = {
uid:ii for uid, ii in rsp.items()
if isinstance(ii, SOPClassCommonExtendedNegotiation)
}
except Exception as exc:
LOGGER.error(
def _bind_defaults(self):
"""Bind the default event handlers."""
# Intervention event handlers
for event in evt._INTERVENTION_EVENTS:
handler = evt.get_default_handler(event)
self.bind(event, handler)
# Notification event handlers
if _config.LOG_HANDLER_LEVEL == 'standard':
self.bind(evt.EVT_DIMSE_RECV, standard_dimse_recv_handler)
self.bind(evt.EVT_DIMSE_SENT, standard_dimse_sent_handler)
self.bind(evt.EVT_PDU_RECV, standard_pdu_recv_handler)
self.bind(evt.EVT_PDU_SENT, standard_pdu_sent_handler)