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:
except:
transfer_syntax = [ImplicitVRLittleEndian]
#-------------------------- CREATE AE and ASSOCIATE ---------------------------
if args.version:
print('echoscu.py v%s' %(VERSION))
sys.exit()
APP_LOGGER.debug('echoscu.py v%s', VERSION)
APP_LOGGER.debug('')
# Create local AE
# Binding to port 0, OS will pick an available port
ae = AE(ae_title=args.calling_aet)
ae.add_requested_context(VerificationSOPClass, transfer_syntax)
# Set timeouts
ae.network_timeout = args.timeout
ae.acse_timeout = args.acse_timeout
ae.dimse_timeout = args.dimse_timeout
# Request association with remote AE
assoc = ae.associate(args.peer,
args.port,
ae_title=args.called_aet,
max_pdu=args.max_pdu)
# If we successfully Associated then send N DIMSE C-ECHOs
if assoc.is_established:
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:
ae.add_supported_context(context.abstract_syntax, transfer_syntax)
ae.maximum_pdu_size = args.max_pdu
# Set timeouts
ae.network_timeout = args.timeout
ae.acse_timeout = args.acse_timeout
ae.dimse_timeout = args.dimse_timeout
ae.start_server((args.bind_addr, args.port), evt_handlers=handlers)
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:
ae.add_supported_context(context.abstract_syntax, transfer_syntax)
ae.maximum_pdu_size = args.max_pdu
# Set timeouts
ae.network_timeout = args.timeout
ae.acse_timeout = args.acse_timeout
ae.dimse_timeout = args.dimse_timeout
ae.start_server((args.bind_addr, args.port), evt_handlers=handlers)
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)
}
LOGGER.debug('# DICOM Dataset')
for elem in identifier.iterall():
LOGGER.info(elem)
LOGGER.info('')
except Exception as ex:
LOGGER.error("Failed to decode the request's Identifier dataset.")
LOGGER.exception(ex)
# Failure - Unable to Process - Failed to decode Identifier
rsp.Status = 0xC310
rsp.ErrorComment = 'Unable to decode the dataset'
self.dimse.send_msg(rsp, context.context_id)
return
# Pass the C-FIND request to the user to handle
try:
handler = evt.trigger(
self.assoc,
evt.EVT_C_FIND,
{
'request' : req,
'context' : context.as_tuple,
'_is_cancelled' : self.is_cancelled
}
)
except Exception as exc:
LOGGER.error("Exception in handler bound to 'evt.EVT_C_FIND'")
LOGGER.exception(exc)
rsp.Status = 0xC311
self.dimse.send_msg(rsp, context.context_id)
return
# No matches and no yields
"""Decode a received PDU.
Parameters
----------
bytestream : bytearray
The received PDU.
Returns
-------
pdu.PDU subclass, str
The PDU subclass corresponding to the PDU and the event string
corresponding to receiving that PDU type.
"""
# Trigger before data is decoded in case of exception in decoding
bytestream = bytes(bytestream)
evt.trigger(self.assoc, evt.EVT_DATA_RECV, {'data' : bytestream})
pdu_types = {
b'\x01' : (A_ASSOCIATE_RQ, 'Evt6'),
b'\x02' : (A_ASSOCIATE_AC, 'Evt3'),
b'\x03' : (A_ASSOCIATE_RJ, 'Evt4'),
b'\x04' : (P_DATA_TF, 'Evt10'),
b'\x05' : (A_RELEASE_RQ, 'Evt12'),
b'\x06' : (A_RELEASE_RP, 'Evt13'),
b'\x07' : (A_ABORT_RQ, 'Evt16')
}
pdu, event = pdu_types[bytestream[0:1]]
pdu = pdu()
pdu.decode(bytestream)
evt.trigger(self.assoc, evt.EVT_PDU_RECV, {'pdu' : pdu})
self.assoc._accepted_cx = {
cx.context_id:cx for cx in result if cx.result == 0x00
}
self.assoc._rejected_cx = [cx for cx in result if cx.result != 0x00]
# pylint: enable=protected-access
# Add any SCP/SCU Role Selection Negotiation response items
for item in ac_roles:
self.acceptor.add_negotiation_item(item)
# Send the A-ASSOCIATE (accept) primitive
LOGGER.info("Accepting Association")
self.send_accept()
# Callbacks/Logging
evt.trigger(self.assoc, evt.EVT_ACCEPTED, {})
# Assocation established OK
self.assoc.is_established = True
evt.trigger(self.assoc, evt.EVT_ESTABLISHED, {})
LOGGER.debug('# DICOM Dataset')
for elem in identifier.iterall():
LOGGER.info(elem)
LOGGER.info('')
except Exception as ex:
LOGGER.error("Failed to decode the request's Identifier dataset.")
LOGGER.exception(ex)
# Failure - Unable to Process - Failed to decode Identifier
rsp.Status = 0xC310
rsp.ErrorComment = 'Unable to decode the dataset'
self.dimse.send_msg(rsp, context.context_id)
return
# Pass the C-FIND request to the user to handle
try:
handler = evt.trigger(
self.assoc,
evt.EVT_C_FIND,
{
'request' : req,
'context' : context.as_tuple,
'_is_cancelled' : self.is_cancelled
}
)
except Exception as exc:
LOGGER.error("Exception in handler bound to 'evt.EVT_C_FIND'")
LOGGER.exception(exc)
rsp.Status = 0xC311
self.dimse.send_msg(rsp, context.context_id)
return
# No matches and no yields
----------
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)