Network

This section contains source code documentation of Network library.

dbi

  • client

Generic DB client factory

hydratk.lib.network.dbi.client.DBClient(engine='SQLITE', *args, **kwargs)

DB client factory method

Parameters:
  • engine (str) – DB engine, SQLITE|ORACLE|MYSQL|POSTGRESQL|JDBC|MSSQL NoSQL REDIS|MONGODB|CASSANDRA
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

DBClient

Return type:

obj

Raises:

error – NotImplementedError

  • jdbc_client

Generic JDBC client

class hydratk.lib.network.dbi.jdbc_client.DBClient(verbose=False, jvm_path=None, classpath=None, options=[])

Class DBClient

__init__(verbose=False, jvm_path=None, classpath=None, options=[])

Class constructor

Called when the object is initialized Uses Java client program to access JMS provider

Parameters:
  • verbose (bool) – verbose mode
  • jvm_path (str) – JVM location, default from configuration
  • classpath (str) – Java classpath, default from configuration
  • options (list) – JVM options
close()

Method stops JVM

Parameters:none
Returns:bool
bridge

Java bridge property getter

client

JDBC client property getter

verbose

verbose mode property getter

driver

JDBC driver property getter

conn_str

connection string property getter

user

username property getter

passw

user password property getter

is_connected

is_connected property getter

connect(driver, conn_str, user=None, passw=None, timeout=10)

Method connectes to server

Parameters:
  • connection_factory – JMS connection factory
  • properties (dict) – JMS connection properties
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
__weakref__

list of weak references to the object (if defined)

disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
exec_query(query, bindings=[], fetch_one=False, autocommit=True)

Method executes query

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
  • autocommit (bool) – autocommit
Returns:

result (bool), rows (list) (accessible by row[column])

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
commit()

Method commits transaction

Parameters:none
Returns:result
Return type:bool
rollback()

Method rollbacks transaction

Parameters:none
Returns:result
Return type:bool
  • mssql_client

PostgreSQL DB client

class hydratk.lib.network.dbi.mssql_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

MSSQL client property getter

host

server host property getter

port

server port property getter

sid

server SID property getter

user

username property getter

passw

user password property getter

is_connected

is_connected property getter

connect(host=None, port=1433, sid=None, user=None, passw=None, timeout=10)

Method connects to database

Parameters:
  • host (str) – hostname
  • port (int) – port
  • sid (str) – db instance
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
exec_query(query, bindings=None, fetch_one=False, autocommit=True)

Method executes query

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
  • autocommit (bool) – autocommit
Returns:

result (bool), rows (list) (accessible by row[column])

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
call_proc(p_name, param_names=[], i_values={}, o_types={}, autocommit=True)

Method calls procedure from database

Parameters:
  • p_name (str) – procedure name
  • param_names (list) – parameter names (input, output)
  • i_values (dict) – input parameter values
  • o_types (dict) – output parameter types
  • autocommit (bool) – autocommit
Returns:

params (dict)

Return type:

tuple

Raises:
  • event – dbi_before_call_proc
  • event – dbi_after_call_proc
commit()

Method commits transaction

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

rollback()

Method rollbacks transaction

Parameters:none
Returns:result
Return type:bool
  • mysql_client

MySQL DB client

class hydratk.lib.network.dbi.mysql_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Args:

client

MySQL client property getter

host

server host property getter

port

server port property getter

sid

server SID property getter

user

username property getter

passw

user password property getter

is_connected

is_connected property getter

connect(host=None, port=3306, sid='', user='', passw='', timeout=10)

Method connects to database

Parameters:
  • host (str) – hostname
  • port (int) – port
  • sid (str) – db instance
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
exec_query(query, bindings=None, fetch_one=False, autocommit=True)

Method executes query

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
  • autocommit (bool) – autocommit
Returns:

result (bool), rows (list) (accessible by row[column])

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
call_proc(p_name, param_names=[], i_values={}, o_types={}, type='proc', ret_type=None, autocommit=True)

Method calls procedure/function from database

Parameters:
  • p_name (str) – procedure name
  • param_names (list) – parameter names (input, output)
  • i_values (dict) – input parameter values
  • o_types (dict) – output parameter types
  • type (str) – code type, func|function|proc|procedure
  • ret_type (str) – return type, string, optional, used for function only
  • autocommit (bool) – autocommit
Returns:

result (according to ret_type) (for function only), params (dict)

Return type:

tuple

Raises:
  • event – dbi_before_call_proc
  • event – dbi_after_call_proc
commit()

Method commits transaction

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

rollback()

Method rollbacks transaction

Parameters:none
Returns:result
Return type:bool
  • oracle_client

ORACLE DB client

class hydratk.lib.network.dbi.oracle_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

Oracle client property getter

host

server host property getter

port

server port property getter

sid

server SID property getter

user

username property getter

passw

user password property getter

is_connected

is_connected property getter

connect(host=None, port=1521, sid=None, user=None, passw=None)

Method connects to database

Parameters:
  • host (str) – hostname
  • port (int) – port
  • sid (str) – db instance
  • user (str) – username
  • passw (str) – password
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
exec_query(query, bindings=None, fetch_one=False, autocommit=True)

Method executes query

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
  • autocommit (bool) – autocommit
Returns:

result (bool), rows (list) (accessible by row[column])

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
call_proc(p_name, param_names=[], i_values={}, o_types={}, type='proc', ret_type=None, autocommit=True)

Method calls procedure/function from database

Parameters:
  • p_name (str) – procedure name
  • param_names (list) – parameter names (input, output)
  • i_values (dict) – input parameter values
  • o_types (dict) – output parameter types
  • type (str) – code type, func|function|proc|procedure
  • ret_type (str) – return type, string, optional, used for function only
  • autocommit (bool) – autocommit
Returns:

result (according to ret_type) (for function only), params (dict)

Return type:

tuple

Raises:
  • event – dbi_before_call_proc
  • event – dbi_after_call_proc
commit()

Method commits transaction

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

rollback()

Method rollbacks transaction

Parameters:none
Returns:result
Return type:bool
  • postgresql_client

PostgreSQL DB client

class hydratk.lib.network.dbi.postgresql_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

PostgreSQL client property getter

host

server host property getter

port

server port property getter

sid

server SID property getter

user

username property getter

passw

user password property getter

is_connected

is_connected property getter

connect(host=None, port=5432, sid=None, user=None, passw=None, timeout=10)

Method connects to database

Parameters:
  • host (str) – hostname
  • port (int) – port
  • sid (str) – db instance
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
exec_query(query, bindings=None, fetch_one=False, autocommit=True)

Method executes query

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
  • autocommit (bool) – autocommit
Returns:

result (bool), rows (list) (accessible by row[column])

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
call_proc(p_name, param_names=[], i_values={}, o_types={}, autocommit=True)

Method calls procedure from database

Parameters:
  • p_name (str) – procedure name
  • param_names (list) – parameter names (input, output)
  • i_values (dict) – input parameter values
  • o_types (dict) – output parameter types
  • autocommit (bool) – autocommit
Returns:

params (dict)

Return type:

tuple

Raises:
  • event – dbi_before_call_proc
  • event – dbi_after_call_proc
commit()

Method commits transaction

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

rollback()

Method rollbacks transaction

Parameters:none
Returns:result
Return type:bool
  • sqlite_client

SQLite DB client

class hydratk.lib.network.dbi.sqlite_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

SQLite client property getter

db_file

database file property getter

is_connected

is_connected property getter

connect(db_file, timeout=10)

Method connects to database

Parameters:
  • db_file (str) – path to database file
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
exec_query(query, bindings=None, fetch_one=False, autocommit=True)

Method executes query

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
  • autocommit (bool) – autocommit
Returns:

result (bool), rows (list) (accessible by row[column])

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
commit()

Method commits transaction

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

rollback()

Method rollbacks transaction

Parameters:none
Returns:result
Return type:bool

nosql

  • cassandra_client

Cassandra client

class hydratk.lib.network.dbi.nosql.cassandra_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

SQLite client property getter

host

host property getter

port

port property getter

key_space

key_space property getter

user

user property getter

passw

passw property getter

is_connected

is_connected property getter

connect(host, port=9042, key_space=None, user=None, passw=None, timeout=10)

Method connects to database

Parameters:
  • host (obj) – host (str) or hosts (list)
  • port (int) – port
  • key_space (str) – key space
  • (str) username (user) –
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

exec_query(query, bindings=None, fetch_one=False)

Method executes query

See Cassandra documentation for more info.

Parameters:
  • query (str) – query, binded variables are marked with ?
  • bindings (list) – query bindings
  • fetch_one (bool) – fetch one row only
Returns:

result (bool), rows (list) (accessible by row.column)

Return type:

tuple

Raises:
  • event – dbi_before_exec_query
  • event – dbi_after_exec_query
  • mongodb_client

MongoDB client

class hydratk.lib.network.dbi.nosql.mongodb_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

SQLite client property getter

host

host property getter

port

port property getter

db

db property getter

user

user property getter

passw

passw property getter

is_connected

is_connected property getter

connect(host, port=27017, db='', user=None, passw=None, timeout=10)

Method connects to database

Parameters:
  • host (str) – host
  • port (int) – port
  • db (str) – database
  • (str) username (user) –
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
disconnect()

Method disconnects from database

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

exec_command(command, collection, document=None, filter=None, single=True)

Method executes command

See MongoDB documentation for more info.

Parameters:
  • command (str) – command insert|find|aggregate|update|replace|delete|drop
  • collection (str) – collection name
  • document (obj) – json object or list of json objects (for many records), used for insert, update
  • filter (obj) – json object, used for find, aggregate, update, replace, delete
  • single (bool) – apply to single record
Returns:

result (bool), output (obj) record id (obj) or records ids (list) for insert records (list) for find, aggregate records count for update, replace, delete empty for drop

Return type:

tuple

Raises:
  • event – dbi_before_exec_command
  • event – dbi_after_exec_command
  • redis_client

Redis client

class hydratk.lib.network.dbi.nosql.redis_client.DBClient

Class DBClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
client

SQLite client property getter

host

host property getter

port

port property getter

db

db property getter

passw

passw property getter

is_connected

is_connected property getter

connect(host, port=6379, db=0, passw=None, timeout=10)

Method connects to database

Parameters:
  • host (str) – host
  • port (int) – port
  • db (int) – database
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – dbi_before_connect
  • event – dbi_after_connect
exec_command(command)

Method executes command

See Redis documentation for more info.

Parameters:

command (str) – command

Returns:

result (bool), output (obj)

Return type:

tuple

Raises:
  • event – dbi_before_exec_command
  • event – dbi_after_exec_command
get(key)

Method executes command GET

Parameters:key (str) – key
Returns:value
Return type:str
set(key, value)

Method executes command SET

Parameters:
  • key (str) – key
  • value (str) – value
Returns:

bool

exists(key)

Method executes command EXISTS

Parameters:key (str) – key
Returns:bool
__weakref__

list of weak references to the object (if defined)

delete(key)

Method executes command DEL

Parameters:key (str) – key
Returns:bool

email

  • client

Generic EMAIL client factory

hydratk.lib.network.email.client.EmailClient(protocol, *args, **kwargs)

Email client factory method

Parameters:
  • protocol (str) – Email protocol, SMTP|POP|IMAP
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

EmailClient

Return type:

obj

Raises:

error – NotImplementedError

  • imap_client

IMAP email client

class hydratk.lib.network.email.imap_client.EmailClient(secured=False, verbose=False)

Class EmailClient

__init__(secured=False, verbose=False)

Class constructor

Called when the object is initialized

Parameters:
  • secured (bool) – secured IMAP
  • verbose (bool) – verbose mode
client

IMAP client property getter

secured

secured property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=None, user=None, passw=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (str) – server port, default protocol port
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – email_before_connect
  • event – email_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

email_count()

Method gets email count

Parameters:none
Returns:count
Return type:int
list_emails()

Method gets email list

Parameters:none
Returns:email ids
Return type:list
receive_email(msg_id)

Method receives email

Parameters:

(str) - email id (msg_id) –

Returns:

sender (str), recipients (list), cc (list), subject (str), message (str)

Return type:

tuple

Raises:
  • event – email_before_receive_email
  • event – email_after_receive_email
  • pop_client

POP email client

class hydratk.lib.network.email.pop_client.EmailClient(secured=False, verbose=False)

Class EmailClient

__init__(secured=False, verbose=False)

Class constructor

Called when the object is initialized

Parameters:
  • secured (bool) – secured POP
  • verbose (bool) – verbose mode
client

POP client property getter

secured

secured property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=None, user=None, passw=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (str) – server port, default protocol port
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – email_before_connect
  • event – email_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

email_count()

Method gets email count

Parameters:none
Returns:count
Return type:int
list_emails()

Method gets email list

Parameters:none
Returns:email ids
Return type:list
receive_email(msg_id)

Method receives email

Parameters:

(str) - email id (msg_id) –

Returns:

sender (str), recipients (list), cc (list), subject (str), message (str)

Return type:

tuple

Raises:
  • event – email_before_receive_email
  • event – email_after_receive_email
  • smtp_client

SMTP email client

class hydratk.lib.network.email.smtp_client.EmailClient(secured=False, verbose=False)

Class EmailClient

__init__(secured=False, verbose=False)

Class constructor

Called when the object is initialized

Parameters:
  • secured (bool) – secured SMTP
  • verbose (bool) – verbose mode
client

SMTP client property getter

secured

secured property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

__weakref__

list of weak references to the object (if defined)

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=None, user=None, passw=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (str) – server port, default protocol port
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – email_before_connect
  • event – email_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
send_email(subject, message, sender='hydra@hydratk.org', recipients=['hydra@hydratk.org'], cc=[], bcc=[])

Method sends email

Parameters:
  • subject (str) – email subject
  • message (str) – email content, string, mandatory
  • sender (str) – from email address
  • recipients (list) – to email addresses
  • cc (list) – carbon copy email addresses
  • bcc (list) – blind carbon copy email addresses
Returns:

result

Return type:

bool

Raises:
  • event – email_before_send_email
  • event – email_after_send_email

ftp

  • client

Generic FTP client factory

hydratk.lib.network.ftp.client.FTPClient(protocol='FTP', *args, **kwargs)

FTP client factory method

Parameters:
  • protocol (str) – FTP protocol, FTP|SFTP|TFTP
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

FTPClient

Return type:

obj

Raises:

error – NotImplementedError

  • ftp_client

FTP client

class hydratk.lib.network.ftp.ftp_client.FTPClient(secured=False, verbose=False)

Class FTPClient

__init__(secured=False, verbose=False)

Class constructor

Called when the object is initialized

Parameters:
  • secured (bool) – secured FTP
  • verbose (bool) – verbose mode
client

FTP client property getter

secured

secured protocol mode property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

path

remote path property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=21, user=None, passw=None, path='/', timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (int) – server port, default protocol port
  • user (str) – username
  • passw (str) – password
  • path (str) – server path
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_connect
  • event – ftp_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
list_dir()

Method lists remote working directory

Parameters:none
Returns:names
Return type:list
change_dir(path)

Method changes remote working directory

Parameters:path (str) – new remote path
Returns:result
Return type:bool
Raises:event – ftp_before_change_dir
__weakref__

list of weak references to the object (if defined)

download_file(remote_path, local_path=None)

Method downloads file from server

Parameters:
  • remote_path (str) – remote path
  • local_path (str) – local path, default ./filename
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_download_file
  • event – ftp_after_download_file
upload_file(local_path, remote_path=None)

Method uploads file to server

Parameters:
  • local_path (str) – local path
  • remote_path (str) – remote path, default ./filename
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_upload_file
  • event – ftp_after_upload_file
delete_file(path)

Method deletes file from server

Parameters:path (str) – remote path
Returns:result
Return type:bool
Raises:event – ftp_before_delete_file
make_dir(path)

Method makes directory on server

Parameters:path (str) – remote path
Returns:result
Return type:bool
Raises:event – ftp_before_make_dir
remove_dir(path)

Method removes directory from server

Parameters:path (str) – remote path
Returns:result
Return type:bool
Raises:event – ftp_before_remove_dir
  • sftp_client

SFTP client

class hydratk.lib.network.ftp.sftp_client.FTPClient(verbose=False)

Class FTPClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

SFTP client property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

cert

cert property getter

path

remote path property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=22, user=None, passw=None, cert=None, path='/', timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (int) – server port, default protocol port
  • user (str) – username
  • passw (str) – password
  • cert (str) – path to certificate file
  • path (str) – server path
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_connect
  • event – ftp_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
list_dir()

Method lists remote working directory

Parameters:none
Returns:names
Return type:list
change_dir(path)

Method changes remote working directory

Parameters:path (str) –
  • new remote path
Returns:result
Return type:bool
Raises:event – ftp_before_change_dir
download_file(remote_path, local_path=None)

Method downloads file from server

Parameters:
  • remote_path (str) – remote path
  • local_path (str) – local path, default ./filename
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_download_file
  • event – ftp_after_download_file
upload_file(local_path, remote_path=None)

Method uploads file to server

Parameters:
  • local_path (str) – local path
  • remote_path (str) – remote path, default ./filename
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_upload_file
  • event – ftp_after_upload_file
delete_file(path)

Method deletes file from server

Parameters:path (str) – remote path
Returns:result
Return type:bool
Raises:event – ftp_before_delete_file
__weakref__

list of weak references to the object (if defined)

make_dir(path)

Method makes directory on server

Parameters:path (str) – remote path
Returns:result
Return type:bool
Raises:event – ftp_before_make_dir
remove_dir(path)

Method removes directory from server

Parameters:path (str) – remote path
Returns:result
Return type:bool
Raises:event – ftp_before_remove_dir
  • tftp_client

TFTP client

class hydratk.lib.network.ftp.tftp_client.FTPClient(verbose=False)

Class FTPClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

TFTP client property getter

host

server host property getter

port

server port property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=69, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (int) – server port, default protocol port
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_connect
  • event – ftp_after_connect
__weakref__

list of weak references to the object (if defined)

download_file(remote_path, local_path=None)

Method downloads file from server

Parameters:
  • remote_path (str) – remote path
  • local_path (str) – local path, default ./filename
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_download_file
  • event – ftp_after_download_file
upload_file(local_path, remote_path=None)

Method uploads file to server

Parameters:
  • local_path (str) – local path
  • remote_path (str) – remote path, default ./filename
Returns:

result

Return type:

bool

Raises:
  • event – ftp_before_upload_file
  • event – ftp_after_upload_file

inet

  • client

TCP/UDP client

class hydratk.lib.network.inet.client.Client(lay3_prot='IPv4', lay4_prot='TCP')

Class Client

__init__(lay3_prot='IPv4', lay4_prot='TCP')

Class constructor

Called when the object is initialized

Parameters:
  • lay3_prot (str) – layer 3 protocol, IPV4|IPV6
  • lay4_prot (str) – layer 4 protocol, TCP|UDP
Raises:

error – NotImplementedError

lay3_prot

3rd layer protocol property getter

lay4_prot

4th layer protocol property getter

client

INET client property getter

host

server host property getter

port

server port property getter

is_connected

is_connecte property getter

connect(host, port, timeout=10)

Method connects to server

Method is supported for TCP only

Parameters:
  • host (str) – host, name or IP address
  • port (int) – port
  • timeout (int) – connection timeout
Returns:

result

Return type:

bool

Raises:
  • event – inet_before_connect
  • event – inet_after_connect
disconnect()

Method disconnects from server

Method is supported for TCP only

Args:

Returns:result
Return type:bool
__weakref__

list of weak references to the object (if defined)

send(data, host=None, port=None)

Method sends data to server

Parameters:
  • data (str) – data
  • host (str) – host, name or IP address, for UDP only
  • port (int) – port, for UDP only
Returns:

result

Return type:

bool

Raises:
  • event – inet_before_send
  • event – inet_after_send
receive(size=4096, timeout=10)

Method receives data from server

Parameters:
  • size (int) – buffer size
  • timeout (float) – receive timeout
Returns:

data

Return type:

str

Raises:
  • event – inet_before_receive
  • event – inet_after_receive
ip2name(ip)

Method translates IP address to name

Parameters:ip (str) – IP address, IPv4|IPv6 format
Returns:name
Return type:str
name2ip(name)

Method translates name to IP address :param name: hostname

Returns:ip
Return type:str
  • packet

Raw packet networking

hydratk.lib.network.inet.packet.Packet(protocol, **kwargs)

Packet factory method

Whole scapy protocol stack is supported

Parameters:
  • protocol (str) – protocol
  • kwargs (kwargs) – key value arguments
Returns:

Packet

Return type:

obj

Raises:

error – NotImplementedError

hydratk.lib.network.inet.packet.compose_packet(packets, payload=None)

Method composes packet from partial packets

Parameters:
  • packets (list) – partial packets
  • payload (str) – packet payload
Returns:

Packet

Return type:

obj

hydratk.lib.network.inet.packet.dump(packet, raw=False)

Method print packet dump

Parameters:
  • packet (obj) – packet, partial of composed
  • raw (bool) – print raw hexdump
Returns:

void

hydratk.lib.network.inet.packet.send_packet(packet, iface=None, verbose=False)

Method sends packet

Parameters:
  • packet (obj) – packet
  • iface (str) – interface, used when Ether packet is included
  • verbose (bool) – verbose mode
Returns:

void

Raises:
  • event – inet_before_send_packet
  • event – inet_after_send_packet
hydratk.lib.network.inet.packet.send_recv_packet(packet, iface=None, retry=3, timeout=1, verbose=False)

Method sends packet and receives answer

Parameters:
  • packet (obj) – packet
  • iface (str) – interface, used when Ether packet is included
  • retry (int) – number of retries
  • timeout (int) – timeout to receive answer
  • verbose (bool) – verbose mode
Returns:

answered packets, unswered packets

Return type:

tuple

Raises:
  • event – inet_before_sendrecv_packet
  • event – inet_after_sendrecv_packet
hydratk.lib.network.inet.packet.ping(destination, protocol='ICMP', port=None, verbose=False)

Method executes ping

Parameters:
  • destination (str) – IP address or hostname
  • protocol (str) – protocol, ICMP|TCP
  • port (int) – port, used for TCP protocol
  • verbose (bool) – verbose mode
Returns:

result

Return type:

bool

Raises:
  • error – ValueError
  • event – inet_before_ping
  • event – inet_after_ping
hydratk.lib.network.inet.packet.traceroute(destination, protocol='ICMP', port=None, max_hops=30, verbose=False)

Method executes traceroute

Parameters:
  • destination (str) – IP address or hostname
  • protocol (str) – protocol, ICMP|TCP
  • port (int) – port, used for TCP protocol
  • max_hops (int) – maximum hops
  • verbose (bool) – verbose mode
Returns:

result

Return type:

bool

Raises:
  • error – ValueError
  • event – inet_before_traceroute
  • event – inet_after_traceroute
hydratk.lib.network.inet.packet.sniffer(output, iface='all', filter=None, timeout=10)

Method executes traffic sniffer

Parameters:
  • output (str) – filename to store packets in PCAP format
  • iface (str) – interface where traffic will be sniffed, default all interfaces
  • filter (str) – traffic filter, see scapy doc
  • timeout (int) – time to stop sniffer
Returns:

void

Raises:
  • event – inet_before_sniff
  • event – inet_after_sniff

jms

  • client

Generic JMS client factory

hydratk.lib.network.jms.client.JMSClient(protocol='JMS', *args, **kwargs)

JMS client factory method

Parameters:
  • protocol (str) – JMS protocol, JMS|STOMP|AMQP|MQTT
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

JMSClient

Return type:

obj

Raises:

error – NotImplementedError

  • amqp_client

AMQP client

class hydratk.lib.network.jms.amqp_client.JMSClient(verbose=False)

Class JMSClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

AMQP client property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=5672, user=None, passw=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – hostname
  • port (str) – port
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_connect
  • event – jms_after_connected
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
send(destination_name, message, destination_type='queue', headers={})

Method sends message

JMS headers - JMSDeliveryMode, JMSPriority, JMSExpiration, JMSType, JMSMessageID,
JMSDestination, JMSReplyTo, JMSCorrelationID, JMSTimestamp
Parameters:
  • destination_name (str) – queue|topic name
  • message (str) – message
  • destination_type (str) – queue|topic
  • headers (dict) – JMS headers, key - title, value - string
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_send
  • event – jms_after_send
__weakref__

list of weak references to the object (if defined)

receive(destination_name, cnt=1)

Method receives messages

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
Returns:

messages as dictionary {‘message’, JMS headers}

Return type:

list

Raises:
  • event – jms_before_receive
  • event – jms_after_receive
browse(destination_name, cnt=100, jms_correlation_id=None, jms_type=None)

Method browses queue

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
  • jms_correlation_id (str) – requested JMSCorrelationID
  • jms_type (str) – requested JMSType
Returns:

messages as dictionary {‘message’, JMS headers}

Return type:

list

Raises:
  • event – jms_before_browse
  • event – jms_after_browse
  • jms_client

JMS client

class hydratk.lib.network.jms.jms_client.JMSClient(verbose=False, jvm_path=None, classpath=None, options=[])

Class JMSClient

__init__(verbose=False, jvm_path=None, classpath=None, options=[])

Class constructor

Called when the object is initialized Uses Java client program to access JMS provider

Parameters:
  • verbose (bool) – verbose mode
  • jvm_path (str) – JVM location, default from configuration
  • classpath (str) – Java classpath, default from configuration
  • options (list) – JVM options
close()

Method stops JVM

Parameters:none
Returns:bool
bridge

Java bridge property getter

client

JMS client property getter

verbose

verbose mode property getter

connection_factory

connection factory property getter

properties

connection properties property getter

is_connected

is_connected property getter

connect(connection_factory, properties={})

Method connects to server

JMS properties - applet, authoritative, batchsize, dns_url,
initial_context_factory, language, object_factories, provider_url, referral, security_authentication, security_credentials, security_principal, security_protocol, state_factories, url_pkg_prefixes
Parameters:
  • connection_factory – JMS connection factory
  • properties (dict) – JMS connection properties
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_connect
  • event – jms_after_connect
__weakref__

list of weak references to the object (if defined)

disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
send(destination_name, message, destination_type='queue', headers={})

Method sends message

JMS headers - JMSCorrelationID, JMSDeliveryMode PERSISTENT|NON_PERSISTENT,
JMSDestination, JMSExpiration, JMSMessageID, JMSPriority, JMSRedelivered True|False, JMSReplyTo, JMSTimestamp, JMSType
Parameters:
  • destination_name (str) – queue|topic name
  • message (str) – message
  • destination_type (str) – queue|topic
  • {dict} (headers) – JMS headers, key - title, value - string
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_send
  • event – jms_after_send
receive(destination_name, cnt=1)

Method receives messages

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
Returns:

messages as dictionary {‘message’, JMS headers}

Return type:

list

Raises:
  • event – jms_before_receive
  • event – jms_after_receive
browse(destination_name, cnt=100, jms_correlation_id=None, jms_type=None)

Method browses queue

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
  • jms_correlation_id (str) – requested JMSCorrelationID
  • jms_type (str) – requested JMSType
Returns:

messages as dictionary {‘message’, JMS headers}

Return type:

list

Raises:
  • event – jms_before_browse
  • event – jms_after_browse
  • mqtt_client

MQTT client

class hydratk.lib.network.jms.mqtt_client.JMSClient(verbose=False)

Class JMSClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

MQTT client property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

verbose

verbose property getter

is_connected

is_connected property getter

_on_log(client, obj, level, string)

Callback for on_log event

_on_message(client, obj, msg)

Callback for on_message event

connect(host, port=1883, user=None, passw=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – hostname
  • port (str) – port
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_connect
  • event – jms_after_connected
__weakref__

list of weak references to the object (if defined)

disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
send(destination_name, message)

Method sends message

Parameters:
  • destination_name (str) – topic name
  • message (str) – message
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_send
  • event – jms_after_send
receive(destination_name, cnt=1, timeout=10)

Method receives messages

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
  • timeout (int) – timeout to receive message
Returns:

messages

Return type:

list

Raises:
  • event – jms_before_receive
  • event – jms_after_receive
  • stomp_client

STOMP client

class hydratk.lib.network.jms.stomp_client.JMSClient(verbose=False)

Class JMSClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

STOMP client property getter

host

server host property getter

port

server port property getter

user

username property getter

passw

user password property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, port=61613, user=None, passw=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – hostname
  • port (str) – port
  • user (str) – username
  • passw (str) – password
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_connect
  • event – jms_after_connected
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
send(destination_name, message, destination_type='queue', headers={})

Method sends message

JMS headers - JMSCorrelationID, JMSExpiration, JMSDeliveryMode, JMSPriority,
JMSReplyTo, JMSType
Parameters:
  • destination_name (str) – queue|topic name
  • message (str) – message
  • destination_type (str) – queue|topic
  • headers (dict) – JMS headers, key - title, value - string
Returns:

result

Return type:

bool

Raises:
  • event – jms_before_send
  • event – jms_after_send
__weakref__

list of weak references to the object (if defined)

receive(destination_name, cnt=1)

Method receives messages

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
Returns:

messages as dictionary {‘message’, JMS headers}

Return type:

list

Raises:
  • event – jms_before_receive
  • event – jms_after_receive
browse(destination_name, cnt=100, jms_correlation_id=None, jms_type=None)

Method browses queue

Parameters:
  • destination_name (str) – queue name
  • cnt (int) – count of messages
  • jms_correlation_id (str) – requested JMSCorrelationID
  • jms_type (str) – requested JMSType
Returns:

messages as dictionary {‘message’, JMS headers}

Return type:

list

Raises:
  • event – jms_before_browse
  • event – jms_after_browse
  • simple_jms

Simple JMS client for request based processing

class hydratk.lib.network.jms.simplejms.JMSClient(verbose=False, jvm_path=None, classpath=None, options=[])

Class JMSClient

request

request property getter, setter

response

response property getter

send(jms_correlation_id)

Methods sends message

Parameters:jms_correlation_id (str) – JMSCorrelationID
Returns:result
Return type:bool
class hydratk.lib.network.jms.simplejms.JMSRequest(destination_queue, jms_type)

Class JMSRequest

__init__(destination_queue, jms_type)

Class constructor

Called when object is initialized

Parameters:
  • destination_queue (str) – queue
  • jms_type (str) – JMSType
destination_queue

destination_queue property getter, setter

jms_type

jms_type property getter, setter

msg

msg property getter, setter

message

message property getter, setter

__weakref__

list of weak references to the object (if defined)

class hydratk.lib.network.jms.simplejms.JMSRequestMessage(content=None, source='file')

Class JMSRequestMessage

__weakref__

list of weak references to the object (if defined)

__init__(content=None, source='file')

Class constructor

Called when object is initialized

Parameters:
  • content (str) – filename including path if source=file message content if source=str
  • source (str) – content source, file|str
content

content property getter, setter

load_from_file(msg_file)

Methods loads message content from file

Parameters:msg_file (str) – filename including path
Returns:void
bind_var(*args, **kwargs)

Methods binds input data to message template

Parameters:
  • args (arg) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

void

ldap

  • client

Generic LDAP client

class hydratk.lib.network.ldap.client.LDAPClient(verbose=False)

Class LDAPClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

LDAP client property getter

host

host property getter

port

port property getter

secured

secured property getter

user

user property getter

passw

passw property getter

base_dn

base_dn property getter

verbose

verbose mode property getter

is_connected

is_connected property getter

connect(host, base_dn, port=None, user=None, passw=None, secured=False, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • base_dn (str) – base distinguished name
  • port (str) – server port, default protocol port
  • user (str) – username, default without base_dn
  • passw (str) – password
  • secured (bool) – secured protocol
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – ldap_before_connect
  • event – ldap_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
read(rdn=None, filter='objectClass=*', attrs=[], fetch_one=False, get_child=True, cn_only=False, attrs_only=False)

Method reads records

Parameters:
  • rdn (str) – relative distinguished name (inc. organization unit)
  • filter (str) – search filter, default all object classes
  • attrs (list) – returned attributes, default all
  • fetch_one (bool) – fetch one record
  • get_child (bool) – get also child records
  • cn_only (bool) – get common name only
  • attrs_only (bool) – get attributes only
Returns:

records, dictionary of attributes

Return type:

list

Raises:
  • event – ldap_before_read
  • event – ldap_after_read
create(rdn, attrs={})

Method creates record

Parameters:
  • rdn (str) – relative distinguished name (inc. organization unit)
  • attrs (dict) – attributes attr/value, internally transformed to LDIF
Returns:

result

Return type:

bool

Raises:
  • event – ldap_before_create
  • event – ldap_after_create
__weakref__

list of weak references to the object (if defined)

update(rdn, attrs)

Method updates record

Parameters:
  • rdn (str) – relative distinguished name (inc. organization unit)
  • attrs (dict) – attributes attr/value, cn/uid will is used to change RDN current attributes are read internally, transformed to LDIF
Returns:

result

Return type:

bool

Raises:
  • event – ldap_before_update
  • event – ldap_after_update
delete(rdn)

Method deletes record

Parameters:

rdn (str) – relative distinguished name (inc. organization unit)

Returns:

result

Return type:

bool

Raises:
  • event – ldap_before_delete
  • event – ldap_after_delete

rest

  • client

Generic REST client for protocols HTTP, HTTPS

class hydratk.lib.network.rest.client.RESTClient(verbose=False)

Class RESTClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
url

URL property getter

proxies

proxies property getter

cert

cert property getter

req_header

request header property getter

req_body

request body property getter

res_status

response status code property getter

res_header

response header property getter

res_body

response body property getter

cookies

cookies property getter

verbose

verbose mode property getter

config

config property getter

history

history property getter

__weakref__

list of weak references to the object (if defined)

send_request(url, proxies=None, user=None, passw=None, auth='Basic', cert=None, verify_cert=True, method='GET', headers=None, cookies=None, body=None, params=None, file=None, content_type=None, timeout=10)

Method sends request to server

Parameters:
  • url (str) – URL
  • proxies (dict) – HTTP proxies {http: url, https: url}
  • user (str) – username
  • passw (str) – password
  • auth (str) – authentication type Basic|Digest|NTLM
  • cert (obj) – str (path to cert.perm path), tuple (path to cert.pem path, path to key.pem path)
  • verify_cert (bool) – verify certificate
  • method (str) – HTTP method GET|POST|PUT|DELETE|HEAD|OPTIONS
  • headers (dict) – HTTP headers
  • cookies (dict) – cookies (name:value)
  • body (str) – request body, POST method used by default
  • params (dict) – parameters, sent in URL for GET method, in body for POST|PUT|DELETE method
  • file (str) – filename including path, download for GET, upload for POST|PUT
  • content_type (str) – type of content, file|form|html|json|text|xml
  • timeout (int) – timeout
Returns:

status (int), body (str) (json object, xml object, otherwise original string)

Return type:

tuple

Raises:
  • event – rest_before_request
  • event – rest_after_request
get_header(title)

Method gets response header

Parameters:title (str) – header title
Returns:header
Return type:str

rpc

  • client

Generic RPC client factory

hydratk.lib.network.rpc.client.RPCClient(provider, *args)

RPC client factory method

Parameters:
  • provider (str) – RPC provider, RMI
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

RPCClient

Return type:

obj

Raises:

error – NotImplementedError

  • jsonrpc_client

XML-RPC client

class hydratk.lib.network.rpc.jsonrpc_client.RPCClient

Class RPCClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
proxy

proxy object property getter

init_proxy(url, timeout=10)

Method initializes proxy to remote object

Parameters:
  • url (str) – remote object url
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – rpc_before_init_proxy
  • event – rpc_after_init_proxy
__weakref__

list of weak references to the object (if defined)

call_method(name, *args)

Method call remote method

Parameters:
  • name (str) – method name
  • args (args) – method parameters
Returns:

method output

Return type:

obj

Raises:
  • event – rpc_before_call_method
  • event – rpc_after_call_method
  • rmi_client

Java RMI client

class hydratk.lib.network.rpc.rmi_client.RPCClient(jvm_path=None, classpath=None, options=[])

Class RPCClient

__init__(jvm_path=None, classpath=None, options=[])

Class constructor

Called when the object is initialized Uses Java client program to access JMS provider

Parameters:
  • jvm_path (str) – JVM location, default from configuration
  • classpath (str) – Java classpath, default from configuration
  • options (list) – JVM options
close()

Method stops JVM

Parameters:none
Returns:void
bridge

Java bridge property getter

proxy

proxy object property getter

__weakref__

list of weak references to the object (if defined)

init_proxy(url)

Method initializes proxy to remote object

Parameters:

url (str) – remote object url

Returns:

result

Return type:

bool

Raises:
  • event – rpc_before_init_proxy
  • event – rpc_after_init_proxy
call_method(name, *args)

Method call remote method

Parameters:
  • name (str) – method name
  • args (args) – method parameters
Returns:

method output

Return type:

obj

Raises:
  • event – rpc_before_call_method
  • event – rpc_after_call_method
  • xmlrpc_client

XML-RPC client

class hydratk.lib.network.rpc.xmlrpc_client.RPCClient

Class RPCClient

__init__()

Class constructor

Called when the object is initialized

Parameters:none
proxy

proxy object property getter

init_proxy(url, timeout=10)

Method initializes proxy to remote object

Parameters:
  • url (str) – remote object url
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – rpc_before_init_proxy
  • event – rpc_after_init_proxy
__weakref__

list of weak references to the object (if defined)

call_method(name, *args)

Method call remote method

Parameters:
  • name (str) – method name
  • args (args) – method parameters
Returns:

method output

Return type:

obj

Raises:
  • event – rpc_before_call_method
  • event – rpc_after_call_method

soap

  • client

Generic SOAP client

class hydratk.lib.network.soap.client.SOAPClient(verbose=False)

Class SOAPClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

SOAP client property getter

wsdl

WSDL property getter

url

URL property getter

proxies

proxies property getter

location

WSDL location property getter

user

username property getter

passw

user password property getter

cert

cert property getter

endpoint

service endpoint property getter

headers

HTTP headers property getter

verbose

verbose mode property getter

load_wsdl(url, proxies=None, location='remote', user=None, passw=None, auth='Basic', cert=None, endpoint=None, headers=None, use_cache=True, timeout=10)

Method loads wsdl

Parameters:
  • url (str) – WSDL URL, URL for remote, file path for local
  • proxies (dict) – HTTP proxies {http: url, https: url}
  • location (str) – WSDL location, remote|local
  • user (str) – username
  • passw (str) – password
  • auth (str) – HTTP authentication, Basic|NTLM
  • cert (obj) – str (path to cert.perm path), tuple (path to cert.pem path, path to key.pem path)
  • endpoint (str) – service endpoint, default endpoint from WSDL
  • headers (dict) – HTTP headers
  • use_cache (bool) – load WSDL from cache
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – soap_before_load_wsdl
  • event – soap_after_load_wsdl
get_operations()

Method returns service operations

Parameters:none
Returns:operations
Return type:list
send_request(operation, body=None, request=None, headers=None)

Method sends request

Parameters:
  • operation (str) – operation name
  • body (str|xml) – request body
  • request (str|xml) – SOAP request, use body or request
  • headers (dict) – HTTP headers, SOAPAction, Content-Type are set automatically
Returns:

response body, objectified xml

Return type:

obj

Raises:
  • event – soap_before_request
  • event – soap_after_request
__weakref__

list of weak references to the object (if defined)

hydratk.lib.network.soap.client.gen_wss_token(user, passw, method='Digest', nonce=True, created=True)

Method generates WSS token

Parameters:
  • user (str) – username
  • passw (str) – password
  • method (str) – token method Text|Digest
  • nonce (bool) – include nonce
  • created (bool) – include created
Returns:

dict

class hydratk.lib.network.soap.client.RequestsTransport(**kwargs)

Class RequestsTransport

  • simplesoap

Pycurl wrapped object oriented soap client solution

class hydratk.lib.network.soap.simplesoap.SoapResponse(curl_obj)

Class SoapResponse

response_code

response_code property getter

info

info property getter

headers

headers property getter

msg

msg property getter

message

message property getter

_extract_info(curl_obj)

Method extracts parameters from CURL object

Parameters:curl_obj (obj) – CURL object
Returns:void
_apply_info()

Method stores response code

Parameters:none
Returns:void
__init__(curl_obj)

Class constructor

Called when object is initialized

Parameters:curl_obj (obj) – CURL object
__weakref__

list of weak references to the object (if defined)

class hydratk.lib.network.soap.simplesoap.SoapRequest(request_url=None)

Class SoapRequest

__init__(request_url=None)

Class constructor

Called when object is initialized

Parameters:request_url (str) – URL
url

url property getter, setter

headers

header property getter, setter

msg

msg property getter, setter

message

message propery getter, setter

__weakref__

list of weak references to the object (if defined)

class hydratk.lib.network.soap.simplesoap.SoapResponseMessage(content=None)

Class SoapResponseMessage

__init__(content=None)

Class constructor

Called when object is initialized

Parameters:content (str) – response content
content

content property getter, setter

__weakref__

list of weak references to the object (if defined)

class hydratk.lib.network.soap.simplesoap.SoapRequestMessage(content=None, source='file')

Class SoapRequestMessage

__init__(content=None, source='file')

Class constructor

Called when object is initialized

Parameters:
  • content (str) – filename including path if source=file request content if source=str
  • source (str) – content source, file|str
content

content property getter, setter

load_from_file(msg_file)

Method loads request content from file

Parameters:msg_file (str) – filename including path
Returns:void
bind_var(*args, **kwargs)

Method binds input data to request template

Parameters:
  • args (arg) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

void

xsd_validate()

Method validates request xml according to xsd

Parameters:none
Returns:result (bool), message (str)
Return type:tuple
class hydratk.lib.network.soap.simplesoap.SoapClient

Class SoapClient

request

request property getter, setter

response

response property getter

__init__()

Class constructor

Called when object is initialized

Parameters:none
set_auth(username, password, auth_type=<class 'sphinx.ext.autodoc.HTTPAUTH'>)

Method sets authentication headers

Parameters:
  • username (str) – username
  • password (str) – password
  • (str) HTTP authentication, Basic supported only (auth_type) –
Returns:

void

set_cert(cert, key=None)

Method sets certificate

Parameters:
  • cert (str) – path to cert file
  • key (str) – path to key file
Returns:

void

send(timeout=30)

Method sends request

Parameters:timeout (int) – connection timeout
Returns:void
hydratk.lib.network.soap.simplesoap.xml_timestamp(location='Europe/Prague')

Method creates timestamp including time zone

Parameters:location (str) – time zone location
Returns:timestamp
Return type:str

term

  • client

Generic TERM client factory

hydratk.lib.network.term.client.TermClient(protocol='SSH', *args, **kwargs)

TERM client factory method

Parameters:
  • provider (str) – TERM protocol, SSH|TELNET
  • args (args) – arguments
  • kwargs (kwargs) – key value arguments
Returns:

TermClient

Return type:

obj

Raises:

error – NotImplementedError

  • ssh_client

SSH client

class hydratk.lib.network.term.ssh_client.TermClient(verbose=False)

Class TermClient

__init__(verbose=False)

Class constructor

Called when the object is initialized

Parameters:verbose (bool) – verbose mode
client

SSH client property getter

host

server host property getter

port

Sserver port property getter

user

username property getter

passw

user password property getter

cert

cert property getter

verbose

verbose mode property getter

is_connected

is client connected property getter

__weakref__

list of weak references to the object (if defined)

connect(host, port=22, user=None, passw=None, cert=None, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (int) – server port, default protocol port
  • user (str) – username
  • passw (str) – password
  • cert (str) – path to certificate file
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – term_before_connect
  • event – term_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
exec_command(command, input=None)

Method executes command

Parameters:
  • command (str) – command
  • input (str) – input for interactive mode
Returns:

result (bool), output (list) (stdout for result True, stderr for result False)

Return type:

tuple

Raises:
  • event – term_before_exec_command
  • event – term_after_exec_command
  • telnet_client

Telnet client

class hydratk.lib.network.term.telnet_client.TermClient(verbose=False, br='n')

Class TermClient

__init__(verbose=False, br='\n')

Class constructor

Called when the object is initialized

Parameters:
  • verbose (bool) – verbose mode
  • br (str) – line break character
client

Telnet client property getter

host

server host property getter

port

server port property getter

verbose

verbose mode property getter

is_connected

is client connected property getter

__weakref__

list of weak references to the object (if defined)

connect(host, port=23, timeout=10)

Method connects to server

Parameters:
  • host (str) – server host
  • port (int) – server port, default protocol port
  • timeout (int) – timeout
Returns:

result (bool), output (list)

Return type:

tuple

Raises:
  • event – term_before_connect
  • event – term_after_connect
disconnect()

Method disconnects from server

Parameters:none
Returns:result
Return type:bool
exec_command(command)

Method executes command

Parameters:

command (str) – command

Returns:

result (bool), output (list)

Return type:

tuple

Raises:
  • event – term_before_exec_command
  • event – term_after_exec_command
_read()

Method reads server output

Parameters:none
Returns:list

bridge

  • java

Bridge to Java virtual machine

class hydratk.lib.bridge.java.JavaBridge(jvm_path=None, classpath=None)

Class JavaBridge

__init__(jvm_path=None, classpath=None)

Class constructor

Called when the object is initialized

Parameters:
  • jvm_path (str) – JVM location, default from configuration
  • classpath (str) – Java classpath, default from configuration
jvm_path

JVM path property getter

classpath

JVM classpath property getter

status

JVM status property getter

start(options=[])

Method starts JVM

Parameters:

options (list) – JVM options

Returns:

result

Return type:

bool

Raises:
  • event – java_before_start
  • event – java_after_start
stop()

Method stops JVM

Parameters:

none

Returns:

result

Return type:

bool

Raises:
  • event – java_before_stop
  • event – java_after_stop
get_var(datatype, value)

Method creates Java variable

Parameters:
  • datatype (str) – byte|short|int|long|float|double|char|string|bool
  • value (str) – initial value
Returns:

Java variable

Return type:

obj

get_class(name, *attrs)

Method creates Java class instance

Parameters:
  • name (str) – class name
  • attrs (args) – constructor attributes
Returns:

class instance

Return type:

obj

desc_class(name)

Method describes Java class

Parameters:name (str) – class name
Returns:attribute names, method names
Return type:tuple
__weakref__

list of weak references to the object (if defined)

get_package(name)

Method returns package

Parameters:name (str) – package name
Returns:method
Return type:obj
init_arraylist(array)

Method initializes Java ArrayList

Parameters:list (list) – Python list
Returns:Java ArrayList
Return type:obj
init_hashmap(dictionary)

Method initializes Java HashMap

Parameters:dictionary (dict) – Python dictionary
Returns:Java HashMap
Return type:obj
_set_classpath(classpath=None)

Method sets classpath

Parameters:classpath (str) – path to be appended to configured classpath
Returns:classpath
Return type:str
  • selen

Bridge to Selenium WebDriver

class hydratk.lib.bridge.selen.SeleniumBridge(browser='PhantomJS')

Class SeleniumBridge

__init__(browser='PhantomJS')

Class constructor

Called when the object is initialized

Parameters:browser (str) – browser name, default PhantomJS
Raises:error – NotImplementedError
client

client property getter

browser

browser property getter

url

url property getter

confirm_alert

confirm_alert property getter

open(url, timeout=20)

Method opens web page from URL

Parameters:
  • url (str) – page URL
  • timeout (int) – timeout
Returns:

result

Return type:

bool

Raises:
  • event – selen_before_open
  • event – selen_after_open
close()

Method closes client

Parameters:none
Returns:result
Return type:bool
wait_for_element(ident, method='id', timeout=5)

Method waits for element presence till timeout

Parameters:
  • ident (str) – element id
  • method (str) – search method id|xpath
  • timeout (float) – timeout
Returns:

bool

Raises:
  • event – selenium_before_wait
  • event – selenium_after_wait
get_element(ident, method='id', single=True)

Method gets element

Parameters:
  • ident (str) – element identification, method specific
  • method (str) – search method, id|class|css|text|name|tag|xpath
  • single (bool) – get single element, used for method class|css|text|name|tag|xpath
Returns:

WebElement or list of WebElement

Return type:

obj

Raises:

event – selenium_before_get_elem

read_element(ident, method='id', attr=None, attr_val=None)

Method reads element value

Parameters:
  • ident (str) – element identification, method specific
  • method (str) – search method, id|class|css|text|name|tag|xpath
  • attr (str) – element attribute or text, used as additional condition in element search
  • attr_val (str) – attribute or text value
Returns:

element value

Return type:

str

Raises:

event – selenium_before_read_elem

set_element(ident, val=None, method='id', attr=None, attr_val=None, el_type=None)

Method sets element value

Parameters:
  • ident (str) – element identification, method specific
  • val (str) – value to set
  • method (str) – search method, id|class|css|text|name|tag|xpath
  • attr (str) – element attribute or text, used as additional condition in element search
  • attr_val (str) – attribute or text value
  • el_type (str) – expected element type (read from attribute type by default)
Returns:

result

Return type:

bool

Raises:

event – selenium_before_set_elem

exec_script(script, *args)

Method execute JavaScript code

Parameters:
  • script (str) – JavaScript code
  • args (args) – script arguments
Returns:

script output

Return type:

obj

Raises:
  • event – selen_before_script
  • event – selen_after_script
save_screen(outfile='screen.png')

Method saves screenshot

Parameters:

outfile (str) – output filename

Returns:

result

Return type:

bool

Raises:
  • event – selen_before_save_screen
  • event – selen_after_save_screen
__weakref__

list of weak references to the object (if defined)

check_alert(confirm=None)

Method checks if alert is present

Parameters:confirm (bool) – confirm dialogue
Returns:result (bool), value (str)
Return type:tuple
get_current_url()

Method gets current URL

Parameters:none
Returns:str
get_title()

Method gets page title

Parameters:none
Returns:str
go_back()

Method goes to previous page

Parameters:none
Returns:bool
refresh()

Method refreshes page

Parameters:none
Returns:bool
get_screen(output='png')

Method gets screenshot content

Parameters:output (str) – output type png|base64
Returns:str

data

  • loader

Module for data loading from external resources

hydratk.lib.data.loader.load_from_file(filename, header=0, delimiter=None, sheet=None)

Method loads data from file

Parameters:
  • filename (str) – filename, supported extensions csv|tsv|xlsx|ods
  • header (int) – row id with header defining column names, default first row
  • delimiter (str) – delimiter, supported for csv|tsv formats, default ;|tab
  • sheet (str) – sheet name, supported for xlsx|ods formats, default first sheet
Returns:

list of records, record is dictionary if header is present, otherwise list

Return type:

list

Raises:

error – ValueError

hydratk.lib.data.loader.load_from_db(engine, query, bindings=None, host=None, port=None, sid=None, user=None, passw=None, db_file=None)

Method loads data from database

Parameters:
  • engine (str) – DB engine, SQLITE|ORACLE|MYSQL|POSTGRESQL|MSSQL
  • query (str) – SQL query
  • bindings (list) – query bindings
  • host (str) – hostname
  • port (int) – port
  • sid (str) – db instance
  • user (str) – username
  • passw (str) – password
  • db_file (str) – database file
Returns:

list of records, record is dictionary

Return type:

list

Raises:

error – NotImplementedError

  • xml

Utilities for advanced work and validation of xml data format

class hydratk.lib.data.xml.XMLValidate

Class XMLValidate

xsd_validate_file(xml_file)

Method validates XML file according to XSD

Parameters:xml_file (str) – filename including path
Returns:void
Raises:error – InputError
xsd_validate(xml_str)

Method validates XML string according to XSD

Parameters:xml_str (str) – XML content
Returns:void
load_xsd_file(xsd_file)

Method loads XSD from file

Parameters:xsd_file (str) – filename including path
Returns:void
load_xsd(xsd_str)

Method loads XSD from string

Parameters:xsd_str (str) – XSD content
Returns:void
__weakref__

list of weak references to the object (if defined)

database

  • mssql

DBO MSSQL driver

class hydratk.lib.database.dbo.drivers.mssql.driver.DBODriver(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class DBODriver

_parse_dsn(dsn)

Method parses dsn

Parameters:dsn (str) – dsn
Returns:True
Return type:bool
Raises:exception – Exception
_apply_driver_options(driver_options)

Method sets driver options

Parameters:driver_option (dict) – driver options
Returns:void
connect()

Method connects to database

Parameters:none
Returns:void
close()

Method disconnects from database

Parameters:none
Returns:void
Raises:exception – DBODriverException
commit()

Method commits transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
execute(sql, *parameters)

Method executes query

Parameters:
  • sql (str) – SQL query
  • parameters (args) – query parameters
Returns:

cursor

Return type:

obj

rollback()

Method rollbacks transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
table_exists(table_name)

Method checks if table exists

Parameters:table_name (str) – table
Returns:result
Return type:bool
result_as_dict(state)

Method enables query result in dictionary form

Parameters:state (bool) – enable dictionary
Returns:void
Raises:error – TypeError
  • mysql

DBO MySQL driver

class hydratk.lib.database.dbo.drivers.mysql.driver.DBODriver(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class DBODriver

_parse_dsn(dsn)

Method parses dsn

Parameters:dsn (str) – dsn
Returns:True
Return type:bool
Raises:exception – Exception
_apply_driver_options(driver_options)

Method sets driver options

Parameters:driver_option (dict) – driver options
Returns:void
connect()

Method connects to database

Parameters:none
Returns:void
close()

Method disconnects from database

Parameters:none
Returns:void
Raises:exception – DBODriverException
commit()

Method commits transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
execute(sql, *parameters)

Method executes query

Parameters:
  • sql (str) – SQL query
  • parameters (args) – query parameters
Returns:

cursor

Return type:

obj

rollback()

Method rollbacks transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
table_exists(table_name)

Method checks if table exists

Parameters:table_name (str) – table
Returns:result
Return type:bool
erase_database()

Method drops database

Parameters:none
Returns:void
result_as_dict(state)

Method enables query result in dictionary form

Parameters:state (bool) – enable dictionary
Returns:void
Raises:error – TypeError
  • oracle

DBO Oracle driver

class hydratk.lib.database.dbo.drivers.oracle.driver.DBODriver(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class DBODriver

_parse_dsn(dsn)

Method parses dsn

Parameters:dsn (str) – dsn
Returns:True
Return type:bool
Raises:exception – Exception
_apply_driver_options(driver_options)

Method sets driver options

Parameters:driver_option (dict) – driver options
Returns:void
connect()

Method connects to database

Parameters:none
Returns:void
close()

Method disconnects from database

Parameters:none
Returns:void
Raises:exception – DBODriverException
commit()

Method commits transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
execute(sql, *parameters)

Method executes query

Parameters:
  • sql (str) – SQL query
  • parameters (args) – query parameters
Returns:

cursor

Return type:

obj

rollback()

Method rollbacks transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
table_exists(table_name)

Method checks if table exists

Parameters:table_name (str) – table
Returns:result
Return type:bool
erase_database()

Method drops database

Parameters:none
Returns:void
result_as_dict(state)

Method enables query result in dictionary form

Parameters:state (bool) – enable dictionary
Returns:void
Raises:error – TypeError
_make_dict(cursor)

Method for overriding row factory to return dictionary

Parameters:cursor (obj) – database cursor
Returns:method
  • pgsql

DBO PostgreSQL driver

class hydratk.lib.database.dbo.drivers.pgsql.driver.DBODriver(dsn, username=None, password=None, driver_options={}, autoconnect=True)

Class DBODriver

_parse_dsn(dsn)

Method parses dsn

Parameters:dsn (str) – dsn
Returns:True
Return type:bool
Raises:exception – Exception
_apply_driver_options(driver_options)

Method sets driver options

Parameters:driver_option (dict) – driver options
Returns:void
connect()

Method connects to database

Parameters:none
Returns:void
close()

Method disconnects from database

Parameters:none
Returns:void
Raises:exception – DBODriverException
commit()

Method commits transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
execute(sql, *parameters)

Method executes query

Parameters:
  • sql (str) – SQL query
  • parameters (args) – query parameters
Returns:

cursor

Return type:

obj

rollback()

Method rollbacks transaction

Parameters:none
Returns:void
Raises:exception – DBODriverException
__getitem__(name)

Method gets item

Parameters:name (str) – item name
Returns:item value
Return type:obj
__getattr__(name)

Method gets attribute

Parameters:name (str) – attribute name
Returns:attribute value
Return type:obj
table_exists(table_name)

Method checks if table exists

Parameters:table_name (str) – table
Returns:result
Return type:bool
erase_database()

Method drops database

Parameters:none
Returns:void
result_as_dict(state)

Method enables query result in dictionary form

Parameters:state (bool) – enable dictionary
Returns:void
Raises:error – TypeError