ISO Presentation#

class icspacket.proto.iso_pres.presentation.ISO_PresentationContext[source]#

Manages Presentation Context Items.

Each entry pairs an ASN.1 abstract syntax with the encoding(s) - the transfer syntaxes - that this library is willing to use for it, which together tell the presentation layer how to interpret a given block of user data.

This class is used to create, register, and remove contexts, and is passed to ISO_Presentation to negotiate which contexts are valid during association.

property items: dict[int, Member_TYPE]#

Dictionary of Presentation Context Items keyed by their ID.

property asn1_types: dict[int, type]#

Dictionary mapping context IDs to ASN.1 decoding classes.

add(item: Member_TYPE, asn1_cls: type) None[source]#

Register an existing Presentation Context Item and bind its ASN.1 class.

new(name: str, ctx_id: int, asn1_cls: type, transfer_syntax: str | None = None) Member_TYPE[source]#

Create and register a new Presentation Context Item.

Parameters:
  • name – Abstract syntax name (object identifier or string).

  • ctx_id – Unique Presentation Context Identifier.

  • asn1_cls – ASN.1 decoding class for user data.

  • transfer_syntax – Transfer syntax to bind. Defaults to Basic (2.1.1).

Returns:

The created context item.

Return type:

PresentaionContextItem

remove(item: Member_TYPE) None[source]#

Remove a Presentation Context Item and its ASN.1 binding.

exception icspacket.proto.iso_pres.presentation.PresentationRejectedError(message: str = 'Presentation connection rejected', *, provider_reason: Any | None = None, user_data: Any | None = None, context_results: list[Any] | None = None)[source]#

Raised when the presentation provider rejects connection establishment.

exception icspacket.proto.iso_pres.presentation.PresentationAbortError(value: Any | None = None, provider: bool = False, *, provider_reason: Any | None = None, event_identifier: Any | None = None)[source]#

Raised when the presentation connection is abnormally released.

class icspacket.proto.iso_pres.presentation.PresentationNegotiatedContext(context_id: int, abstract_syntax_name: str, transfer_syntax_name: str, asn1_cls: type)[source]#

Presentation context selected into the defined context set.

class icspacket.proto.iso_pres.presentation.PresentationReleaseResult(accepted: bool, value: Any | None = None, collision: bool = False)[source]#

Result of a presentation release attempt.

class icspacket.proto.iso_pres.presentation.PresentationEvent(kind: str, value: Any | None = None, accepted: bool | None = None)[source]#

Parsed presentation data or release event.

class icspacket.proto.iso_pres.presentation.ISO_PresentationSettings(calling_selector: bytes | None = b'\x00\x00\x00\x01', called_selector: bytes | None = b'\x00\x00\x00\x01', use_version1: bool = False, custom_requirements: Presentation_requirements | None = None)[source]#

Configuration settings for the Presentation layer.

These settings influence how the Presentation connection (COPP) is established, specifically how selectors and protocol versions are negotiated.

Parameters:
  • calling_selector (bytes | None) – Local presentation selector, used to identify the calling application entity. If None, no selector is included.

  • called_selector (bytes | None) – Remote presentation selector, used to identify the destination application entity. If None, no selector is included.

  • use_version1 (bool) – If True, forces usage of COPP Version 1 semantics. If False, negotiates a higher version (default).

  • custom_requirements (Presentation_requirements | None) – Optional presentation requirements to override defaults. If None, a default requirements set is used.

class icspacket.proto.iso_pres.presentation.ISO_Presentation(session: ISO_Session, settings: ISO_PresentationSettings | None = None, context: ISO_PresentationContext | None = None)[source]#

Client-side driver for the ISO Presentation protocol (X.226 / ISO 8823).

Sitting directly on top of an ISO_Session, this class takes care of negotiating presentation contexts and wrapping/unwrapping application data so callers can exchange decoded ASN.1 objects instead of raw bytes. Connection setup and teardown are driven by exchanging PPDUs (Presentation Protocol Data Units) with the peer.

>>> session = ISO_Session(...) # may require COTP_Connection
>>> presentation = ISO_Presentation(session)

To make sure your application layer user data is decoded and encoded correctly, register a new context id:

>>> presentation.presentation_context.new("1.2.3", 1, MyASN1Class)
<Context_list.Member_TYPE>
>>> presentation.init_session(("127.0.0.1", 1234))
<MyASN1Class> # depending on server result and ctx_id
Parameters:
  • session (ISO_Session) – Underlying ISO Session instance to use for transport.

  • settings (ISO_PresentationSettings | None) – Optional Presentation settings (selectors, version, requirements).

  • context (ISO_PresentationContext | None) – Presentation context registry, managing context IDs and ASN.1 decoding classes.

settings: ISO_PresentationSettings#

Configuration settings for the Presentation layer.

property presentation_context: ISO_PresentationContext#

Registered Presentation Contexts.

Provides both the raw context items and their ASN.1 decoding bindings.

Returns:

The managed Presentation Context registry.

Return type:

ISO_PresentationContext

property session: ISO_Session#

Underlying Session object providing transport services.

property transport: COTP_Connection#

Underlying COTP transport connection (OSI transport layer).

connect(address: tuple[str, int]) None[source]#

Establish a Presentation connection.

If already connected, the call is ignored. Otherwise, it delegates connection establishment to the Session layer.

Parameters:

address (tuple[str, int]) – Network address tuple (host, port).

close() None[source]#

Close the Presentation connection.

Delegates closure to the Session layer and marks the Presentation context as invalid.

init_session(app_octets: bytes, address: tuple[str, int] | None)[source]#

Initialize a Presentation session (A-ASSOCIATE equivalent).

Builds and transmits a CP PPDU (Connect Presentation PDU) carrying application data, registered presentation contexts, and optional selectors. Waits for a CPA PPDU (Connect Presentation Accept) in response.

  • Includes all registered Presentation Context Items in negotiation.

  • If calling_selector or called_selector are set, they are included in the PPDU for AE identification.

  • If use_version1 is True, forces negotiation of COPP v1.

  • If custom_requirements is provided, overrides default presentation requirements.

Parameters:
  • app_octets (bytes) – Encoded application-layer data to include in the CP PPDU.

  • address (tuple[str, int] | None) – Optional address for connection establishment if the session is not already connected.

Raises:

ConnectionError – If session initiation fails, invalid CPA received, or unsupported mode is negotiated.

Returns:

Decoded user data if present in the CPA response, otherwise None.

Return type:

Any | None

init_x410_session(user_octets: bytes, address: tuple[str, int] | None) bytes[source]#

Initialize a presentation session in X.410-1984 pass-through mode.

close_session(octets: bytes, pres_ctx_id: int, graceful: bool = False) Any | None[source]#

Close the Presentation session.

Sends a CN/CPA termination sequence (Finish) via the Session layer, optionally embedding user data.

  • If pres_ctx_id is provided, the user data is bound to the given Presentation Context Identifier.

  • If graceful is True, waits for a Disconnect confirmation and returns decoded response data.

  • If graceful is False, closes immediately.

Parameters:
  • octets (bytes) – Encoded application user data to include.

  • pres_ctx_id (int | None) – Optional presentation context ID for user data binding.

  • graceful (bool) – Whether to perform graceful closure with peer acknowledgment.

Raises:

ConnectionStateError – If session has not been initialized.

Returns:

Decoded data from peer if graceful is True.

Return type:

Any | None

close_session_result(octets: bytes, pres_ctx_id: int, graceful: bool = False) PresentationReleaseResult | None[source]#

Close the Presentation session and return the release result.

abort_session(octets: bytes | None = None, pres_ctx_id: int = 1) None[source]#

Abort the Presentation session with optional user data.

Parameters:
  • octets (bytes | None) – Encoded application user data to include.

  • pres_ctx_id (int) – Presentation context ID for user data.

send_data(octets: bytes, /) None[source]#

Send raw user data.

Delegates to send_encoded_data().

Parameters:

octets (bytes) – Encoded user data.

send_encoded_data(octets: bytes, pres_ctx_id: int) None[source]#

Send BER-encoded user data bound to a Presentation Context Identifier.

Parameters:
  • octets (bytes) – User data to encode.

  • pres_ctx_id (int | None) – Optional Presentation Context ID. If omitted, default context is used.

Raises:

ConnectionStateError – If not connected.

send_x410_data(octets: bytes) None[source]#

Send X.410-1984 mode user data without presentation contexts.

recv_data() bytes[source]#

Receive raw user data from the session.

Returns:

Raw user data octets.

Return type:

bytes

recv_encoded_data(context: dict[int, type] | None = None) Any | None[source]#

Receive and decode Presentation-encoded user data.

Attempts to decode User-data PPDU from the session. If decoding fails, raises a type error.

Parameters:

context (dict[int, type] | None) – Optional decoding context mapping PCI IDs to classes. If omitted, the instance’s default presentation_context.asn1_types is used.

Raises:
Returns:

Decoded ASN.1 object or None.

Return type:

Any | None

recv_x410_data() bytes[source]#

Receive X.410-1984 mode user data without presentation contexts.

recv_event(context: dict[int, type] | None = None) PresentationEvent[source]#

Receive and classify the next presentation data or release event.