Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(self.PDUType,
_,
self.PDULength,
_) = unpack('> B B I I', Stream.read(10))
def TotalLength(self):
return 10
def __repr__(self):
tmp = "A-RELEASE-RP PDU\n"
tmp = tmp + " PDU type: 0x%02x\n" % self.PDUType
tmp = tmp + " PDU length: %d\n" % self.PDULength
return tmp + "\n"
class A_ABORT_PDU(PDU):
"""
This class represents the A-ABORT PDU
"""
def __init__(self):
self.PDUType = 0x07
self.PDULength = 0x00000004
self.AbortSource = None
self.ReasonDiag = None
def FromParams(self, Params):
# Params can be an A_ABORT_ServiceParamters or A_P_ABORT_ServiceParamters
# object.
if Params.__class__ == A_ABORT_ServiceParameters:
# User initiated abort
self.ReasonDiag = 0
self.AbortSource = Params.AbortSource
(self.PDUType,
_,
self.PDULength,
_) = unpack('> B B I I', Stream.read(10))
def TotalLength(self):
return 10
def __repr__(self):
tmp = "A-RELEASE-RQ PDU\n"
tmp = tmp + " PDU type: 0x%02x\n" % self.PDUType
tmp = tmp + " PDU length: %d\n" % self.PDULength
return tmp + "\n"
class A_RELEASE_RP_PDU(PDU):
'''This class represents the A-RELEASE-RP PDU'''
def __init__(self):
self.PDUType = 0x06 # Unsigned byte
self.PDULength = 0x00000004 # Unsigned int
def FromParams(self, Params=None):
# Params is an A_RELEASE_ServiceParameters object. It is optional.
# nothing to do
pass
def ToParams(self):
tmp = A_RELEASE_ServiceParameters()
#tmp.Reason = 'normal'
tmp.Result = 'affirmative'
return tmp
@property
def CallingAETitle(self):
"""
While the standard says this value should match the A-ASSOCIATE-RQ
value there is no guarantee and this should not be used as a check
value
Returns
-------
str
The Requestor's AE Calling AE Title
"""
return self.Reserved4
class A_ASSOCIATE_RJ_PDU(PDU):
'''This class represents the A-ASSOCIATE-RJ PDU'''
def __init__(self):
self.PDUType = 0x03 # Unsigned byte
self.PDULength = 0x00000004 # Unsigned int
self.Result = None # Unsigned byte
self.Source = None # Unsigned byte
self.ReasonDiag = None # Unsigned byte
def FromParams(self, Params):
# Params is an A_ASSOCIATE_ServiceParameters object
self.Result = Params.Result
self.Source = Params.ResultSource
self.ReasonDiag = Params.Diagnostic
def ToParams(self):
tmp = A_ASSOCIATE_ServiceParameters()
Returns
-------
pydicom.uid.UID
The Acceptor AE's Presentation Context item's accepted Transfer
Syntax. The UID instance has been extended with two variables
for tracking if SCP/SCU role negotiation has been accepted:
pydicom.uid.UID.SCP: Defaults to None if not used, 0 or 1 if used
pydicom.uid.UID.SCU: Defaults to None if not used, 0 or 1 if used
"""
ts_uid = self.TransferSyntaxSubItem.TransferSyntaxName
if isinstance(ts_uid, UID):
return ts_uid
else:
return UID(ts_uid.decode('utf-8'))
class AbstractSyntaxSubItem(PDU):
def __init__(self):
self.ItemType = 0x30 # Unsigned byte
self.ItemLength = None # Unsigned short
self.AbstractSyntaxName = None # String
def FromParams(self, syntax_name):
"""
Parameters
----------
syntax_name : pydicom.uid.UID
The abstract syntax name as a UID
"""
self.AbstractSyntaxName = syntax_name
self.ItemLength = len(self.AbstractSyntaxName)
def ToParams(self):
# additional sub items requiring decoding
while True:
item = next_item(s)
if item is None:
# Then the stream is empty so we break out of the loop
break
item.decode(s)
self.additional_items.append(item)
# After decoding, check that we have only added allowed items
self.validate_additional_items()
class A_ASSOCIATE_RQ_PDU(PDU):
'''This class represents the A-ASSOCIATE-RQ PDU
The A-ASSOCIATE-RQ PDU is sent at the start of association negotiation when
either the local or the peer AE wants to to request an association.
An A_ASSOCIATE_RQ requires the following parameters (see PS3.8 Section
9.3.2):
Protocol version (fixed)
Called AE title (supplied during association request)
Calling AE title (part of local AE)
Application Context (UID, fixed by application)
Presentation Context(s) (one or more)
ID (one)
Abstract Syntax (one)
Transfer Syntax(es) (one or more)
User Information
Returns
-------
list of pydicom.uid.UID
The Requestor AE's Presentation Context item's Transfer Syntax(es)
"""
syntaxes = []
for ii in self.AbstractTransferSyntaxSubItems:
if isinstance(ii, TransferSyntaxSubItem):
if isinstance(ii.TransferSyntaxName, UID):
syntaxes.append(ii.TransferSyntaxName)
else:
syntaxes.append( UID(ii.TransferSyntaxName.decode('utf-8')) )
return syntaxes
class PresentationContextItemAC(PDU):
"""
Attributes
----------
SCP - None or int
Defaults to None if SCP/SCU role negotiation not used, 0 or 1 if used
SCU - None or int
Defaults to None if SCP/SCU role negotiation not used, 0 or 1 if used
"""
def __init__(self):
self.ItemType = 0x21 # Unsigned byte
self.ItemLength = None # Unsigned short
self.PresentationContextID = None # Unsigned byte
self.ResultReason = None # Unsigned byte
self.TransferSyntaxSubItem = None # TransferSyntaxSubItem object
# Used for tracking SCP/SCU Role Negotiation
Returns
-------
pynetdicom.PDU.UserIdentityItem
The Requestor AE's User Identity object if available, None otherwise
"""
for ii in self.UserData:
if isinstance(ii, UserIdentitySubItemRQ):
return ii
elif isinstance(ii, UserIdentitySubItemAC):
return ii
return None
class MaximumLengthParameters(PDU):
"""
The maximum length notification allows communicating AEs to limit the size
of the data for each P-DATA indication. This notification is required for
all DICOM v3.0 conforming implementations.
PS3.7 Annex D.3.3.1 and PS3.8 Annex D.1
"""
def __init__(self):
self.MaximumLengthReceived = None
def ToParams(self):
tmp = MaximumLengthSubItem()
tmp.FromParams(self)
return tmp
def __eq__(self, other):
@property
def user_information(self):
"""
See PS3.8 9.3.2, 7.1.1.6
Returns
-------
pynetdicom.PDU.UserInformationItem
The Requestor AE's User Information object
"""
for ii in self.VariableItems[1:]:
if isinstance(ii, UserInformationItem):
return ii
class A_ASSOCIATE_AC_PDU(PDU):
'''This class represents the A-ASSOCIATE-AC PDU'''
def __init__(self):
self.PDUType = 0x02 # Unsigned byte
self.Reserved1 = 0x00 # Unsigned byte
self.PDULength = None # Unsigned int
# Unsigned short
self.ProtocolVersion = 1
# Unsigned short
self.Reserved2 = 0x00
# string of length 16
self.Reserved3 = None
# string of length 16
self.Reserved4 = None
self.Reserved5 = (0x0000, 0x0000, 0x0000, 0x0000) # 32 bytes
# VariablesItems is a list containing the following:
# 1 ApplicationContextItem
(self.ItemType,
_,
self.ItemLength) = unpack('> B B H', Stream.read(4))
self.AbstractSyntaxName = Stream.read(self.ItemLength)
def TotalLength(self):
return 4 + self.ItemLength
def __repr__(self):
tmp = " Abstract syntax sub item\n"
tmp = tmp + " Item type: 0x%02x\n" % self.ItemType
tmp = tmp + " Item length: %d\n" % self.ItemLength
tmp = tmp + " Abstract syntax name: %s\n" % self.AbstractSyntaxName
return tmp
class TransferSyntaxSubItem(PDU):
def __init__(self):
self.ItemType = 0x40 # Unsigned byte
self.ItemLength = None # Unsigned short
self.TransferSyntaxName = None # String
def FromParams(self, Params):
# Params is a string.
self.TransferSyntaxName = Params
self.ItemLength = len(self.TransferSyntaxName)
def ToParams(self):
# Returns the transfer syntax name
return self.TransferSyntaxName
def Encode(self):
tmp = b''
_,
self.ItemLength) = unpack('> B B H', Stream.read(4))
self.TransferSyntaxName = Stream.read(self.ItemLength)
def TotalLength(self):
return 4 + self.ItemLength
def __repr__(self):
tmp = " Transfer syntax sub item\n"
tmp = tmp + " Item type: 0x%02x\n" % self.ItemType
tmp = tmp + " Item length: %d\n" % self.ItemLength
tmp = tmp + " Transfer syntax name: %s\n" % self.TransferSyntaxName
return tmp
class UserInformationItem(PDU):
def __init__(self):
# Unsigned byte
self.ItemType = 0x50
# Unsigned short
self.ItemLength = None
# UserData is a list containing the following:
# 1 MaximumLengthItem
# 0 or more raw strings encoding user data items
# List of subitems
self.UserData = []
def FromParams(self, Params):
# Params is a UserData
for ii in Params:
self.UserData.append(ii.ToParams())
self.ItemLength = 0