Robot Framework
robot.utils.connectioncache.ConnectionCache Class Reference

Cache for libraries to use with concurrent connections, processes, etc. More...

Public Member Functions

def __bool__ (self)
 
def __init__ (self, no_current_msg='No open connection.')
 
def __iter__ (self)
 
def __len__ (self)
 
def close_all (self, closer_method='close')
 Closes connections using given closer method and empties cache. More...
 
def empty_cache (self)
 Empties the connection cache. More...
 
def get_connection (self, alias_or_index=None)
 Get the connection specified by the given alias or index. More...
 
def register (self, connection, alias=None)
 Registers given connection with optional alias and returns its index. More...
 
def resolve_alias_or_index (self, alias_or_index)
 
def switch (self, alias_or_index)
 Switches to the connection specified by the given alias or index. More...
 

Public Attributes

 current
 

Properties

 current_index = property
 

Private Member Functions

def _is_connection (self, conn)
 
def _resolve_alias (self, alias)
 
def _resolve_index (self, index)
 
def current_index (self)
 
def current_index (self, index)
 

Private Attributes

 _aliases
 
 _connections
 
 _no_current
 

Static Private Attributes

def __getitem__ = get_connection
 

Detailed Description

Cache for libraries to use with concurrent connections, processes, etc.

The cache stores the registered connections (or other objects) and allows
switching between them using generated indices or user given aliases.
This is useful with any library where there's need for multiple concurrent
connections, processes, etc.

This class is used also outside the core framework by SeleniumLibrary,
SSHLibrary, etc. Backwards compatibility is thus important when doing changes.

Definition at line 30 of file connectioncache.py.

Constructor & Destructor Documentation

◆ __init__()

def robot.utils.connectioncache.ConnectionCache.__init__ (   self,
  no_current_msg = 'No open connection.' 
)

Definition at line 32 of file connectioncache.py.

Member Function Documentation

◆ __bool__()

def robot.utils.connectioncache.ConnectionCache.__bool__ (   self)

Definition at line 135 of file connectioncache.py.

◆ __iter__()

def robot.utils.connectioncache.ConnectionCache.__iter__ (   self)

Definition at line 129 of file connectioncache.py.

◆ __len__()

def robot.utils.connectioncache.ConnectionCache.__len__ (   self)

Definition at line 132 of file connectioncache.py.

◆ _is_connection()

def robot.utils.connectioncache.ConnectionCache._is_connection (   self,
  conn 
)
private

Definition at line 160 of file connectioncache.py.

◆ _resolve_alias()

def robot.utils.connectioncache.ConnectionCache._resolve_alias (   self,
  alias 
)
private

Definition at line 146 of file connectioncache.py.

◆ _resolve_index()

def robot.utils.connectioncache.ConnectionCache._resolve_index (   self,
  index 
)
private

Definition at line 151 of file connectioncache.py.

◆ close_all()

def robot.utils.connectioncache.ConnectionCache.close_all (   self,
  closer_method = 'close' 
)

Closes connections using given closer method and empties cache.

    If simply calling the closer method is not adequate for closing
    connections, clients should close connections themselves and use
    :meth:`empty_cache` afterwards.

Definition at line 114 of file connectioncache.py.

◆ current_index() [1/2]

def robot.utils.connectioncache.ConnectionCache.current_index (   self)
private

Definition at line 41 of file connectioncache.py.

◆ current_index() [2/2]

def robot.utils.connectioncache.ConnectionCache.current_index (   self,
  index 
)
private

Definition at line 50 of file connectioncache.py.

◆ empty_cache()

def robot.utils.connectioncache.ConnectionCache.empty_cache (   self)

Empties the connection cache.

    Indexes of the new connections starts from 1 after this.

Definition at line 124 of file connectioncache.py.

◆ get_connection()

def robot.utils.connectioncache.ConnectionCache.get_connection (   self,
  alias_or_index = None 
)

Get the connection specified by the given alias or index.

    If ``alias_or_index`` is ``None``, returns the current connection
    if it is active, or raises an error if it is not.

    Alias is whatever was given to :meth:`register` method and indices
    are returned by it. Index can be given either as an integer or
    as a string that can be converted to an integer. Raises an error
    if no connection with the given index or alias found.

Definition at line 95 of file connectioncache.py.

◆ register()

def robot.utils.connectioncache.ConnectionCache.register (   self,
  connection,
  alias = None 
)

Registers given connection with optional alias and returns its index.

    Given connection is set to be the :attr:`current` connection.

    If alias is given, it must be a string. Aliases are case and space
    insensitive.

    The index of the first connection after initialization, and after
    :meth:`close_all` or :meth:`empty_cache`, is 1, second is 2, etc.

Definition at line 64 of file connectioncache.py.

◆ resolve_alias_or_index()

def robot.utils.connectioncache.ConnectionCache.resolve_alias_or_index (   self,
  alias_or_index 
)

Definition at line 138 of file connectioncache.py.

◆ switch()

def robot.utils.connectioncache.ConnectionCache.switch (   self,
  alias_or_index 
)

Switches to the connection specified by the given alias or index.

    Updates :attr:`current` and also returns its new value.

    Alias is whatever was given to :meth:`register` method and indices
    are returned by it. Index can be given either as an integer or
    as a string that can be converted to an integer. Raises an error
    if no connection with the given index or alias found.

Definition at line 81 of file connectioncache.py.

Member Data Documentation

◆ __getitem__

def robot.utils.connectioncache.ConnectionCache.__getitem__ = get_connection
staticprivate

Definition at line 106 of file connectioncache.py.

◆ _aliases

robot.utils.connectioncache.ConnectionCache._aliases
private

Definition at line 36 of file connectioncache.py.

◆ _connections

robot.utils.connectioncache.ConnectionCache._connections
private

Definition at line 35 of file connectioncache.py.

◆ _no_current

robot.utils.connectioncache.ConnectionCache._no_current
private

Definition at line 33 of file connectioncache.py.

◆ current

robot.utils.connectioncache.ConnectionCache.current

Definition at line 34 of file connectioncache.py.

Property Documentation

◆ current_index

robot.utils.connectioncache.ConnectionCache.current_index = property
static

Definition at line 39 of file connectioncache.py.


The documentation for this class was generated from the following file: