ae.sys_core_sh

SiHOT PMS system core xml interface

This portion is very old and needs refactoring and much more unit tests.

The classes provided by this portion are allowing the implementation of client and server components to communicate with the Sihot PMS system.

TODO:
  • use other xml library because xml.etree the xml modules in the Python standard library are not secure against maliciously constructed data - the problem here is that the xml generated by the Sihot system is not 100% conform to the xml standards.

  • refactor SihotXmlParser and inherited classes: migrating the attributes oc, tn, id, rc, hn, … to a dict.

  • inject cae app instance into _SihotTcpClient, RequestXmlHandler and TcpServer (replacing ae.core.po()).

Module Attributes

SDI_SH

Sihot System Interface Id

SH_DEF_SEARCH_FIELD

default search field for external systems (used by sys_data_sh.cl_field_data())

SDF_SH_SERVER_ADDRESS

Sihot Server address or ip

SDF_SH_KERNEL_PORT

Sihot Kernel Interface port

SDF_SH_WEB_PORT

Sihot Web interfaces port

SDF_SH_CLIENT_PORT

Sihot Server client port

SXML_DEF_ENCODING

encoding used by the Sihot xml interface

ERR_MESSAGE_PREFIX_CONTINUE

error message prefix for ignorable errors

TCP_CONNECTION_BROKEN_MSG

error message fragment added if connection is broken

Functions

elem_to_attr(elem)

convert element string to attribute string by converting into lower-case and replacing hyphens with underscores.

Classes

AvailCatInfo(cae[, use_kernel])

build xml request and send it to get available room categories from the Sihot server.

AvailCatInfoResponse(cae)

processing response of CATINFO operation code of the WEB interface

CatRoomResponse(cae)

parser for Sihot room category responses.

CatRooms(cae[, use_kernel])

built room category request and send it to Sihot server.

ConfigDict(cae[, use_kernel])

build and send request for the Sihot configuration settings.

ConfigDictResponse(cae)

parser to process Sihot configuration setting responses.

PostMessage(cae[, use_kernel])

build and send request to add a message into the Sihot system message/notification queue.

Request(cae)

xml parser for generic requests from SIHOT.

RequestXmlHandler(request, client_address, ...)

server component base class to receive xml data from the Sihot system.

ResChange(cae)

xml parser to process Sihot server reservation change notifications.

ResKernelGet(cae)

build and send generic request to the Sihot kernel interface.

ResKernelResponse(cae)

response to the RESERVATION-GET oc/request of the KERNEL interface.

ResResponse(cae)

xml parser for kernel or web interface responses.

RoomChange(cae)

xml parser to process Sihot server room change notifications.

ShSysConnector(system)

connector class for the Sihot system.

SihotXmlBuilder(cae[, use_kernel])

generic class to build and send Sihot xml requests.

SihotXmlParser(cae)

XMLParser interface used by client to parse the responses from the Sihot server.

TcpServer(ip, port, cls_xml_handler[, ...])

tcp server class to process xml sent by the Sihot client.

SDI_SH = 'Sh'

Sihot System Interface Id

SH_DEF_SEARCH_FIELD = 'ShId'

default search field for external systems (used by sys_data_sh.cl_field_data())

SDF_SH_SERVER_ADDRESS = 'shServerIP'

Sihot Server address or ip

SDF_SH_KERNEL_PORT = 'shServerKernelPort'

Sihot Kernel Interface port

SDF_SH_WEB_PORT = 'shServerPort'

Sihot Web interfaces port

SDF_SH_CLIENT_PORT = 'shClientPort'

Sihot Server client port

SXML_DEF_ENCODING = 'cp1252'

encoding used by the Sihot xml interface

ERR_MESSAGE_PREFIX_CONTINUE = 'CONTINUE:'

error message prefix for ignorable errors

TCP_CONNECTION_BROKEN_MSG = 'socket connection broken!'

error message fragment added if connection is broken

_TCP_MAXBUFLEN = 8192

tcp buffer length

_TCP_END_OF_MSG_CHAR = b'\x04'

end-of-message character of the Sihot xml interface

_DEBUG_RUNNING_CHARS = '|/-\\'

progress animation characters for console output

elem_to_attr(elem)[source]

convert element string to attribute string by converting into lower-case and replacing hyphens with underscores.

Parameters:

elem (str) – element string.

Return type:

str

Returns:

attribute string of the passed element string.

class _SihotTcpClient(server_ip, server_port, timeout=3.6, encoding='utf-8', debug_level=0)[source]

Bases: object

local sihot tcp client used by SihotXmlBuilder.send_to_server().

error_message = ''
received_xml = ''
__init__(server_ip, server_port, timeout=3.6, encoding='utf-8', debug_level=0)[source]
send_to_server(xml)[source]

send passed xml string to the Sihot server.

Parameters:

xml (str) – xml string to send.

Return type:

str

Returns:

error message or empty string if no errors occurred.

_receive_response(sock)[source]

receive response from Sihot server.

Parameters:

sock – used socket for the connection to the Sihot server.

Return type:

str

Returns:

received string.

class RequestXmlHandler(request, client_address, server)[source]

Bases: BaseRequestHandler

server component base class to receive xml data from the Sihot system.

error_message = ''
notify()[source]

print error message to console output.

handle()[source]

receive xml string sent by the Sihot system to this server component.

abstract handle_xml(xml_from_client)[source]

abstract method to be implemented by the inheriting class.

Parameters:

xml_from_client (bytes) – xml request sent from Sihot xml client as a bytes string.

Return type:

bytes

Returns:

xml response to the Sihot xml client as bytes string.

class _ThreadedServer(server_address, RequestHandlerClass, bind_and_activate=True)[source]

Bases: ThreadingMixIn, TCPServer

local tcp server threading mixin class used by TcpServer class.

class TcpServer(ip, port, cls_xml_handler, debug_level=0)[source]

Bases: object

tcp server class to process xml sent by the Sihot client.

__init__(ip, port, cls_xml_handler, debug_level=0)[source]
run(display_animation=False)[source]

run/start the server.

Parameters:

display_animation (bool) – pass True to display progress animation at console output.

class SihotXmlParser(cae)[source]

Bases: object

XMLParser interface used by client to parse the responses from the Sihot server.

__init__(cae)[source]
parse_xml(xml)[source]

parse the xml response string sent by the Sihot server.

Parameters:

xml (str) – xml string to parse.

get_xml()[source]

get the xml string to be parsed.

Return type:

str

Returns:

xml string to be parsed.

start(tag, _attrib)[source]

parse next opening xml tag; called for each opening tag.

Parameters:
  • tag (str) – tag string.

  • _attrib (Dict[str, str]) – attribute string (not used in Sihot xml elements).

Return type:

Optional[str]

Returns:

None if the tag got parsed and recognized/processed else the unrecognized tag string.

data(data)[source]

process parsed data string; called on each chunk (separated by XMLParser on spaces, special chars, …).

Parameters:

data (str) – data string chunk.

Return type:

Optional[str]

Returns:

None if data chunk string got parsed and recognized else the unprocessed data string.

end(tag)[source]

parser detected end tag of element; called for each closing tag.

Parameters:

tag (str) – closing element tag string.

Return type:

Optional[str]

Returns:

closing element tag string.

close()[source]

end of xml string reached; called when all data has been parsed.

Return type:

SihotXmlParser

Returns:

this SihotXmlParser instance.

server_error()[source]

get the server error code string.

Return type:

str

Returns:

‘0’ if no error occurred, else the Sihot error return code as string.

server_err_msg()[source]

get the server error message.

Return type:

str

Returns:

empty string if no error occurred, else the Sihot error message string.

class Request(cae)[source]

Bases: SihotXmlParser

xml parser for generic requests from SIHOT.

get_operation_code()[source]

return the Sihot operation code of the xml request string sent to the Sihot server.

Return type:

str

Returns:

Sihot operation code string.

class RoomChange(cae)[source]

Bases: SihotXmlParser

xml parser to process Sihot server room change notifications.

__init__(cae)[source]
class ResChange(cae)[source]

Bases: SihotXmlParser

xml parser to process Sihot server reservation change notifications.

__init__(cae)[source]
start(tag, attrib)[source]

parser detected start tag of next/new xml element; called for each opening tag.

Return type:

None

data(data)[source]

process parsed element data chunk.

Return type:

None

class ResResponse(cae)[source]

Bases: SihotXmlParser

xml parser for kernel or web interface responses.

__init__(cae)[source]
class AvailCatInfoResponse(cae)[source]

Bases: SihotXmlParser

processing response of CATINFO operation code of the WEB interface

__init__(cae)[source]
data(data)[source]

process parsed element data chunk.

Return type:

Optional[str]

class CatRoomResponse(cae)[source]

Bases: SihotXmlParser

parser for Sihot room category responses.

__init__(cae)[source]
end(tag)[source]

parser detected end tag of element.

class ConfigDictResponse(cae)[source]

Bases: SihotXmlParser

parser to process Sihot configuration setting responses.

__init__(cae)[source]
end(tag)[source]

parser detected end tag of Sihot config element.

Return type:

Optional[str]

class ResKernelResponse(cae)[source]

Bases: SihotXmlParser

response to the RESERVATION-GET oc/request of the KERNEL interface.

__init__(cae)[source]
class SihotXmlBuilder(cae, use_kernel=False)[source]

Bases: object

generic class to build and send Sihot xml requests.

tn: str = '1'
__init__(cae, use_kernel=False)[source]

create an instance of this class.

Parameters:
  • cae (ConsoleApp) – instance of the running ConsoleApp app.

  • use_kernel (bool) – pass True to use the Sihot kernel interface (False==use Sihot sxml interface).

beg_xml(operation_code, add_inner_xml='', transaction_number='')[source]

create a new xml request string including xml header, operation code and transaction number.

Parameters:
  • operation_code (str) – Sihot operation code of the new xml element.

  • add_inner_xml (str) – inner xml block/elements.

  • transaction_number (str) – Sihot transaction number string.

end_xml()[source]

terminate a Sihot xml request string.

add_tag(tag, val='')[source]

add a new xml element tag with the passed value.

send_to_server(response_parser=None)[source]

send the built xml request to the Sihot server.

Parameters:

response_parser (Optional[SihotXmlParser]) – used parser to parse the response from the Sihot server (def=SihotXmlParser).

Return type:

str

Returns:

error string or empty string if no errors occurred.

static new_tag(tag, val='', opening=True, closing=True)[source]

create new xml element with the passed tag and value.

Parameters:
  • tag (str) – tag of the new xml element.

  • val (Any) – value of the new xml element.

  • opening (bool) – pass False to NOT add the element opening tag.

  • closing (bool) – pass False to NOT add the element closing tag.

Returns:

new xml element or element part/fragment.

static convert_value_to_xml_string(value)[source]

convert any element value type to the corresponding xml string, replacing & < > characters with escapes.

Parameters:

value (Any) – element value to be converted.

Return type:

str

Returns:

element value as string.

property xml: str

property to determine the currently built xml string.

Getter:

return built xml string.

Setter:

change xml string.

class AvailCatInfo(cae, use_kernel=False)[source]

Bases: SihotXmlBuilder

build xml request and send it to get available room categories from the Sihot server.

avail_rooms(hotel_id='', room_cat='', from_date=datetime.date(2024, 3, 19), to_date=datetime.date(2024, 3, 19))[source]

determine available rooms for the specified hotel, room category and date range.

Parameters:
  • hotel_id (str) – Sihot hotel id or empty string to get available rooms of all hotels.

  • room_cat (str) – Sihot room category or empty string to get available rooms of all categories.

  • from_date (date) – start date of the date range: defaulting to today.

  • to_date (date) – end date of the date range; defaulting to today.

Return type:

Union[dict, str]

Returns:

Sihot response as dict created by AvailCatInfoResponse with the results or an error message string if an error occurred.

response: Optional[SihotXmlParser]
class CatRooms(cae, use_kernel=False)[source]

Bases: SihotXmlBuilder

built room category request and send it to Sihot server.

get_cat_rooms(hotel_id='1', from_date=datetime.date(2024, 3, 19), to_date=datetime.date(2024, 3, 19), scope='')[source]

determine configured room categories of the Sihot system for the specified hotel and date range.

Parameters:
  • hotel_id (str) – Sihot hotel id to get the room categories.

  • from_date (date) – start date of the date range: defaulting to today.

  • to_date (date) – end date of the date range; defaulting to today.

  • scope (str) – scope string to request additional information - see Sihot documentation.

Return type:

Union[dict, str]

Returns:

Sihot response as dict created by CatRoomResponse with the results or an error message string if an error occurred.

response: Optional[SihotXmlParser]
class ConfigDict(cae, use_kernel=False)[source]

Bases: SihotXmlBuilder

build and send request for the Sihot configuration settings.

get_key_values(config_type, hotel_id='1', language='EN')[source]

determine a configuration setting of the Sihot system for the specified hotel and language.

Parameters:
  • config_type (str) – Sihot config setting type - see Sihot documentation.

  • hotel_id (str) – Sihot hotel id to get the configuration setting.

  • language (str) – language id for the configuration description texts - see Sihot documentation.

Return type:

Union[dict, str]

Returns:

Sihot response as dict created by ConfigDictResponse with the results or an error message string if an error occurred.

response: Optional[SihotXmlParser]
class PostMessage(cae, use_kernel=False)[source]

Bases: SihotXmlBuilder

build and send request to add a message into the Sihot system message/notification queue.

post_message(msg, level=3, system='sys_core_sh_module')[source]

build and send request to add a message into the Sihot system message/notification queue.

Parameters:
  • msg (str) – message text string to add to the Sihot system messages.

  • level (int) – importance level.

  • system (str) – message sender system id/string.

Return type:

str

Returns:

error message or empty string if no error occurred.

response: Optional[SihotXmlParser]
class ResKernelGet(cae)[source]

Bases: SihotXmlBuilder

build and send generic request to the Sihot kernel interface.

__init__(cae)[source]

create an instance of this class.

Parameters:
  • cae (ConsoleApp) – instance of the running ConsoleApp app.

  • use_kernel – pass True to use the Sihot kernel interface (False==use Sihot sxml interface).

fetch_res_no(obj_id, scope='GET')[source]

determine reservation and guest data for the passed reservation object id.

Parameters:
  • obj_id (str) – Sihot reservation object id.

  • scope – search scope string (see 7.3.1.2 in Sihot KERNEL interface doc V 9.0).

Return type:

Tuple[Any, ...]

Returns:

either the reservation ids as tuple of (hotel_id, res_id, sub_id, gds_no) or the tuple (None, “error”) if the reservation was not found.

response: Optional[SihotXmlParser]
class ShSysConnector(system)[source]

Bases: SystemConnectorBase

connector class for the Sihot system.

connect()[source]

not needed - lazy connection

Return type:

str

static clients_match_field_init(match_fields)[source]

check and return the match field for a client search.

Parameters:

match_fields (Sequence) – tuple/list of length 1 with the match field name.

Return type:

str

Returns:

match field name or an error message if an error occurred.

last_err_msg: str

last system connection error message(s)