pyats.tcl package

Module:

tcl

Authors:

Siming Yuan (siyuan), CSG Test - Ottawa

Description:

This module provides a standard way for users to access Tcl code/libraries when using the python ATS infrastructure.

This module requires environment variable AUTOTEST to be set to user’s Tcl ATS tree for proper ATS Tcl functionalities to work.

It acts as a wrapper to Python’s Tkinter module, and in addition provides standard typecasting for easy conversion from Tcl string to python native objects.

By default, this module provides one managed interpreter.

Submodules

Implements:

tcl.Array

Authors:

Siming Yuan (siyuan), CSG Test - Ottawa

Description:

This file implements Tcl Array in Python

class pyats.tcl.array.Array(*args, **kwargs)

Bases: AttrDict

Array Class (AttrDict)

This class mimics the Tcl array variable behavior, allowing users to save a Tcl array in Python, and use it throughout the rest of their codes.

This class extends the AttrDict class.

Note

There is no specific implementation to this API. The basic behavior of AttrDict is sufficient in describing Tcl arrays.

Examples

>>> array = Array()
>>> array['name,first'] = 'Garrosh'
>>> array['name,last']  = 'Hellscream'
>>> array['boss,number'] = '14'
>>> array['boss,instance'] = 'Siege of Orgrimmar'
>>> array.keys()
['name,first', 'name,last', 'boss,number', 'boss,instance']

AttrDict object init

How this works:
  • All python objects internally store their attributes in a dictionary that is named __dict__.

  • There is no requirement that the internal dictionary __dict__ would need to be “just a plain dict”, so we can assign any subclass of dict() to the internal dictionary.

  • In our case we simply assign the AttrDict() instance we are instantiating (as we are in __init__).

  • By calling super()’s __init__() method we made sure that it (already) behaves exactly like a dictionary, since that function calls all the dictionary instantiation code.

Special Note:
  • Known to cause memory leak in Python < 2.7.3 and Python3 < 3.2.3

static from_tcl(string)
keys(pattern=None)

Returns the keys in this Array (eg, [array names] in tcl). Similar to dict.keys() API, except allows for checking for whether a key starts with a string, or matches a particular regular expression.

Parameters:

pattern (str/regex) – a string object matching the start pattern of each key, or a regex object matching the key patterns

Example

import re

>>> array = Array()
>>> array['name,first'] = 'Garrosh'
>>> array['name,last']  = 'Hellscream'
>>> array['boss,number'] = '14'
>>> array['boss,instance'] = 'Siege of Orgrimmar'
>>> array.keys('name')
['name,first', 'name,last']
>>> array.keys(re.compile('^boss,.+'))
['boss,number', 'boss,instance']
Implements:

tcl.History

Authors:

Siming Yuan (siyuan), CSG Test - Ottawa

Description:

This file implements Tcl history mechanism

class pyats.tcl.history.Entry(api)

Bases: object

Tcl Historical Entry

This is a container object to add a timestamp to each Entry

class pyats.tcl.history.History(max_history=9999)

Bases: object

Tcl History class

This is similar to collections.deque. It is used to keep Tcl History when any interpreter calls were made by the user, up to the max history. The main design goal of this class is to allow users to enable/disable recording Tcl history for debugging purposes, and as well mark important historical events when running scripts.

Consider the storage of history items as a fixed-length list: when the max size is reached, adding more items will bump out the first item in the list.

This class provides two unique abilities:
  1. store generic Tcl call history

  2. unique markers where if a marker is active/created, the also log history under that marker.

Built-in __init__

This API initializes the history class. It inits the internal general storage, and as well creates the marker storage objects

Parameters:

max_history (int) – maximum storage entries. Default to 9999

Returns:

None

append(item)

Appends a historical item

This API appends to the tcl call history. Note that if any markers are active, it will also add to that marker

Parameters:

item (str) – item to add

clear(marker=None, clear_all=False)

Clears history

This API clears tcl call history.

Parameters:
  • clear_all (bool) – flag on whether to clear all history (including) markers

  • markers (str) – the marker where history is to be cleared. defaults to clearing the generic history

disable()

Disable history logging

This API disables logging. All log tries will be ignored until enabled again using the enable() api

Parameters:

None

enable()

Enable history logging

This API enables logging. By default, logging is enabled.

Parameters:

None

end_marker(marker)

Deactivate a new marker

Stops a currently active marker.

Parameters:

marker (str) – name of marker to stop

filter(marker=None, count=20, regex=None)

Return History

Returns a list of Tcl commands called in chronological order.

Parameters:
  • marker (str) – marker name to lookup

  • count (int) – max number of history counts to return. Default to 20.

  • regex (str) – regular expression string to match on during filtering

Returns:

List of commands

start_marker(marker)

Activates a new marker

A marker is a sub-history list within this object. It allows users to mark important start/ends during execution and create sub-histories for better debugging

Parameters:

marker (str) – name of new marker to create. if marker already exists then start it again (add to list of active markers)

Implements:

ReturnCodes TclDLL Tcl_ObjType Tcl_Obj GetListFromAny DictionaryCompare

Authors:

Jean-Sebastien Trottier (strottie), CSG XR - Ottawa

Description:

This file implements access to some internals of Tcl’s C code. This includes internal structures and APIs.

pyats.tcl.internal.DictionaryCompare(left, right)

This function compares two strings as if they were being used in an index or card catalog. The case of alphabetic characters is ignored, except to break ties. Thus “B” comes before “b” but after “a”. Also, integers embedded in the strings compare in numerical order. In other words, “x10y” comes after “x9y”, not before it as it would when using strcmp().

Results:

A negative result means that the first element comes before the second, and a positive result means that the second element should come first. A result of zero means the two elements are equal and it doesn’t matter which comes first.

Side effects:

None.

From:

DictionaryCompare @ tclCmdIL.c 8.4.19

pyats.tcl.internal.GetListFromAny(obj, interp=None)

Convert any Tcl object/string to a Python list (tuple)

If the object is already a valid Python list, it is returned unchanged (converted to list if necessary)

Examples

>>> import pyats.tcl
>>> obj = 'a b c {de} {f g h { i }}'
>>> pyats.tcl.internal.GetListFromAny(None, obj)
('a', 'b', 'c', 'de', 'f g h { i }')
class pyats.tcl.internal.ReturnCodes

Bases: object

TCL_BREAK = 3
TCL_CONTINUE = 4
TCL_ERROR = 1
TCL_OK = 0
TCL_RETURN = 2
pyats.tcl.internal.TclError_from_interp(interp, default_msg=None)
class pyats.tcl.internal.Tcl_Interp_p

Bases: c_void_p

classmethod from_param(interp)

Convert a Python object into a function call parameter.

class pyats.tcl.internal.Tcl_Obj

Bases: Structure

bytes

Structure/Union member

internalRep

Structure/Union member

length

Structure/Union member

refCount

Structure/Union member

typePtr

Structure/Union member

class u_internalRep

Bases: Union

doubleValue

Structure/Union member

longValue

Structure/Union member

otherValuePtr

Structure/Union member

class s_twoPtrValue

Bases: Structure

ptr1

Structure/Union member

ptr2

Structure/Union member

twoPtrValue

Structure/Union member

wideValue

Structure/Union member

class pyats.tcl.internal.Tcl_ObjType

Bases: Structure

dupIntRepProc

Structure/Union member

freeIntRepProc

Structure/Union member

name

Structure/Union member

setFromAnyProc

Structure/Union member

updateStringProc

Structure/Union member

Implements:

tcl.Interpreter

Authors:

Siming Yuan (siyuan), CSG Test - Ottawa

Description:

This file implements Tcl Interpreter (wrapper to Tkinter.Tk)

class pyats.tcl.interpreter.Interpreter

Bases: Tk

Interpreter class

This class provides extended Tcl-bridging functionalities, based on the native Python Tkinter module, enabling users to make native Tcl calls within their test scripts. This class provides native integration to ATS infrastructure/tree.

Common Functionalities:
  1. updating auto_path in all Interpreter

  2. loading the tclHelper package in new Interpreters

  3. typecasting support

  4. set/read Tcl variables into Python

Interpreter object init (built-in)

This API initiates a new instances of Interpreter objects. It will:
  1. update auto_path to include ATS tree defaults

  2. load tclHelper package

Parameters:

None

Returns:

initialized instance of interpreter object

cast_any(value)

Type casts a Tcl value (str) to a Python type

This API can be used to typecast Tcl return values (which are normally strings), to a Python object (such as int, str, etc)

If the value is already a recognized Python object, it is returned unchanged.

Parameters:

value – The object (typically a Tcl string) to cast.

Returns:

tcl list -> tuple(), only if already a tuple(), not a string tcl integer -> int() tcl double -> float() tcl boolean -> bool() tcl keyed list -> KeyedList() tcl string -> str()

static cast_array(value, item_cast=None)

Type cast a Tcl [array get] list (str) to a Python Array() object

Parameters:
  • value – The object (typically a Tcl string) to cast.

  • item_cast – a python callable (function/class) to cast array item values with. If None, no casting is applied to array item values.

Returns:

Array()

Raises:

ValueError

Example

>>> string = 'a 1 b 2'
>>> pyats.tcl.cast_array(string)
Array({'a': '1', 'b': '2'})
>>> pyats.tcl.cast_array(string, item_cast=int)
Array({'a': 1, 'b': 2})
>>> import functools
>>> cast_array_of_int =             ...     functools.partial(pyats.tcl.cast_array, item_cast=int)
>>> cast_array_of_int(string)
Array({'a': 1, 'b': 2})
cast_boolean(value)

Type cast a Tcl boolean (str) to a Python bool()

Parameters:

value – The object (typically a Tcl string) to cast.

Returns:

bool()

Raises:

ValueError

cast_double(value)

Type cast a Tcl double (str) to a Python float()

Parameters:

value – The object (typically a Tcl string) to cast.

Returns:

float()

Raises:

ValueError

cast_int(value)

Type cast a Tcl int (str) to a Python int()

Parameters:

value – The object (typically a Tcl string) to cast.

Returns:

int()

Raises:

ValueError

static cast_keyed_list(value, item_cast=None)

Type cast a Tclx keyed list (str) to a Python KeyedList() object

Parameters:
  • value – The object (typically a Tcl string) to cast.

  • item_cast – a python callable (function/class) to cast keyed list item values with. If None, no casting is applied to keyed list item values.

Returns:

KeyedList()

Raises:

ValueError

Example

>>> string = '{a 1} {b 2}'
>>> pyats.tcl.cast_keyed_list(string)
KeyedList({'a': '1', 'b': '2'})
>>> pyats.tcl.cast_keyed_list(string, item_cast=int)
KeyedList({'a': 1, 'b': 2})
>>> import functools
>>> cast_keyed_list_of_int =             ...     functools.partial(pyats.tcl.cast_keyed_list, item_cast=int)
>>> cast_keyed_list_of_int(string)
KeyedList({'a': 1, 'b': 2})
static cast_list(value, item_cast=None)

Type cast a Tcl list (str) to a Python tuple().

Parameters:
  • value – The object (typically a Tcl string) to cast.

  • item_cast – a python callable (function/class) to cast list elements with. If None, no casting is applied to list elements.

Example

>>> string = '1 2 3'
>>> pyats.tcl.cast_list(string)
('1', '2', '3')
>>> pyats.tcl.cast_list(string, item_cast=int)
(1, 2, 3)
>>> import functools
>>> cast_list_of_int =             ...     functools.partial(pyats.tcl.cast_list, item_cast=int)
>>> cast_list_of_int(string)
(1, 2, 3)
Returns:

tuple()

Raises:

ValueError

create_callback(callback, cmd_name=None, force=False)

Creating Callback Function

Allows the creation of a new tcl API that calls back a Python function. Note that the returns of the callback function will appear in Tcl in its str() form.

Parameters:
  • callback (func) – function in Python to callback

  • cmd_name (str) – name of Tcl API to create. If not supplied, the cmd_name of the callback function will be used

  • force (bool) – if True, force replace the same named function

Notes

Callback function can only have with positional arguments. Typical tcl args maps to python *args but appear as a tuple.

Returns:

TclCommand

eval(code, typecast=False, record=True)

Evaluates Tcl code

This API evaluates one or more lines of tcl code. This is a wrapper for the same tkinter.tk.eval API, adding the typecast ability

Parameters:
  • code (str) – Tcl code to be evaluated

  • typecast (bool) – whether to typecast the return value

Returns:

str returned from Tcl. if typecast=True, see cast_any return values.

Raises:

TclError

static generate_callback_cmd_name(callback, mangle_cmd_name=False)
get_array(name)

Reads a Tcl array to Python

This API reads a Tcl array variable and returns a corresponding Python Array object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

Array()

get_boolean(name)

Reads a boolean to Python

This API reads a tcl boolean and returns a corresponding Python bool object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

True/False

Note

In tcl, all integer (including negatives) other than 0 are True. 0 (Zero) is the only False Also, see man Tcl_GetBoolean:

Tcl_GetBoolean expects string to specify a boolean value.  If
string is any of 0, false, no, or off, then Tcl_GetBoolean
stores a zero value at *boolPtr. If string is any of 1, true,
yes, or on, then 1 is stored at *boolPtr. Any of these values
may be abbreviated, and upper-case spellings are also
acceptable.
get_double(name)

Reads a double to Python

This API reads a tcl double string and returns a corresponding Python float object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

float()

get_errorInfo()

Returns the last TclError information

This API returns the content of ::errorInfo, a detailed error descr of the last Tcl Error.

Parameters:

None

Returns:

string form of tcl error

get_int(name)

Reads a Tcl integer to Python

This API reads a tcl integer and returns a corresponding Python int object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

int()

get_keyed_list(name)

Reads a Tcl KeyedList to Python

This API reads a TclX Keyed List variable and returns a corresponding Python KeyedList object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

KeyedList()

get_list(name)

Reads a Tcl list to Python

This API reads a Tcl list variable and returns a corresponding Python tuple object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

tuple()

get_var(name)

Reads a Tcl variable to Python

This API reads any tcl variable and returns a corresponding Python str object.

Parameters:

name (str) – name of tcl variable to read (full namespace qualified)

Returns:

str()

remove_callback(callback)

Remove Callback Function

Remove a callback python from Tcl interpreter.

Parameters:

callback – Either callback or cmd_name argument give to create_callback or the TclCommand object returned by create_callback.

Returns:

None

set_array(name, obj)

Sets an array in Tcl

This API takes in an Array/dict object in Python and converts it to an array variable in Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • obj (Array) – array object providing the values

Returns:

None

set_boolean(name, value)

Sets a boolean in Tcl

This API takes in an python boolean and converts it to 1/0 in Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • value (bool) – True/False

Returns:

None

set_double(name, value)

Sets a variable in Tcl

This API takes in an python and converts it to a variable in Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • value (obj) – object providing the values in str format

Returns:

None

set_int(name, value)

Sets a variable in Tcl

This API takes in an python and converts it to a variable in Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • value (obj) – object providing the values in str format

Returns:

None

set_keyed_list(name, obj)

Sets a Keyed List in Tcl

This API takes in an KeyedList object in Python and converts it to a keyed list variable in Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • obj (KeyedList) – keyed list object providing the values

Returns:

None

set_list(name, value)

Sets a list in Tcl

This API takes in an python iterable object and converts it to a list Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • value (iterable) – the iterable whose items will be part of list

Returns:

None

set_var(name, value)

Sets a variable in Tcl

This API takes in an python and converts it to a variable in Tcl

Parameters:
  • name (str) – name of tcl variable to set (full namespace qualified)

  • value (obj) – object providing the values in str format

Returns:

None

Implements:

pyats.tcl.KeyedList

Authors:

Siming Yuan (siyuan), CSG Test - Ottawa

Description:

This file implements Tcl KeyedList in Python

class pyats.tcl.keyedlist.KeyedList(*args, **kwargs)

Bases: AttrDict, MutableMapping

KeyedList Class (AttrDict)

This class mimics the Tcl Keyed List variable behavior, allowing users to save a Tcl Keyed List in Python, and use it throughout the rest of their codes.

This class extends the AttrDict class.

Many operations with KeyedList classes are recursive, made to correspond to how the Tcl KeyedList behaves.

Keyed List behaviors:
  • keyed lists are basically key-value pairs (similar to dict in Python)

  • keys could have sub-keys, and sub-keys could be values, or another keyed list

  • keys and subkeys are identifed/separated by a “.”

Special Notes:
  • KeyedList extends AttrDict, which extends (based on) dict()

  • Accessing keys and subkeys can be achieved by var[‘key.subkey’] etc

  • subkeys that are keyed lists are also a KeyedList object
    • thus access to their values from top level is done recursively

Examples

>>> klist = KeyedList()
>>> klist['name.first'] = 'Garrosh'
>>> klist['name.last']  = 'Hellscream'
>>> klist['boss.number'] = '14'
>>> klist['boss.instance'] = 'Siege of Orgrimmar'
>>> klist['boss.location'] = 'The Inner Sanctum'
>>> klist.keys()
['name', 'boss']
>>> klist.boss.location
'The Inner Sanctum'

KeyedList init (built-in)

This API initializes the KeyedList instance object. It first creates the top level key/value pairs, then iterate through each child key-value to instantiate them as keyed-lists

Parameters:
  • *args – supports creating keyed lists from keyed tuples (pairs of two, with first being key name and 2nd being value)

  • **kwargs – supports creating keyed lists from dict style keyword arguments.

Returns:

initialized new KeyedList object.

Examples

klist = KeyedList(((‘name’, ((‘last’, ‘schwarzenegger’), (‘first’, ‘arnold’))), )) klist = KeyedList({‘name’ : {‘last’: ‘schwarzenegger’, ‘first’: ‘arnold’}, }) klist = KeyedList(‘{name {{last schwarzenegger} {first arnold}}}’)

all_items()

KeyedList all_items

This API returns all key-value pairs (including subkeys) in this KeyedList. This operation is recursive: all fully qualified keys will be returned.

Parameters:

None

Examples

>>> klist.all_items()
[('name.last', 'Hellscream'), ('name.first', 'Garrosh')]
Returns:

list of fully qualified key names

all_keys()

KeyedList all_keys

This API returns all keys (including subkeys) in this KeyedList. This operation is recursive: all fully qualified keys will be returned.

Parameters:

None

Examples

>>> klist.all_keys()
['name.last', 'name.first']
Returns:

list of fully qualified key names

static from_tcl(string)
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
has_key(key)

KeyedList __contains__ (built_in)

This API enables the python in operator

Parameters:

key (str) – key to check for, separated by ‘.’ when needed

Examples

>>> 'name.last' in klist
True
Returns:

True/False

pop(k[, d]) v, remove specified key and return the corresponding value.

If key is not found, d is returned if given, otherwise KeyError is raised.

setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
update([E, ]**F) None.  Update D from dict/iterable E and F.

If E is present and has a .keys() method, then does: for k in E: D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

Implements:

TclVariable TempTclVariable TclArrayVariable TempTclArrayVariable TclCommand TempTclCommand TclNamespace TempTclNamespace

Authors:

Jean-Sebastien Trottier (strottie), CSG XR - Ottawa

Description:

This file implements abstraction of Tcl namespaces, variables and commands

class pyats.tcl.namespace.TclArrayVariable(var_name, tcl=None, cast=None)

Bases: MutableMapping, TclVariable

clear() None.  Remove all items from D.
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
update([E, ]**F) None.  Update D from mapping/iterable E and F.

If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v

class pyats.tcl.namespace.TclCommand(cmd, args=None, keywords=None, tcl=None, cast=None, logger=None)

Bases: object

absolute()
build_tclcmd(*args, **kwargs)
call(*args, **kwargs)
createcommand(func)
delete()
eval(*args, **kwargs)
exists()
is_command()
is_proc()
static kwargs_to_dashed_args(**kwargs)
make_absolute()
origin()
proc_arg_default(arg_name)
proc_args()
proc_body()
rename(new_name)
class pyats.tcl.namespace.TclNamespace(ns, tcl=None)

Bases: object

class CommandsView(ns)

Bases: MutableMapping

byref(cmd_name, *args, **kwargs)
createcommand(cmd_name, func)
delete(cmd_name)
exists(cmd_name)
origin(cmd_name)
proc_arg_default(cmd_name, arg_name)
proc_args(cmd_name)
proc_body(cmd_name)
rename(cmd_name, new_name)
class ObjectsView(ns)

Bases: VariablesView

array_get(var_name, pattern=None)
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
class ProcsView(ns)

Bases: CommandsView

exists(cmd_name)
class VariablesView(ns)

Bases: MutableMapping

array_byref(var_name, *args, **kwargs)
array_get(var_name, pattern=None)
array_names(var_name, pattern=None)
array_set(var_name, value)
array_unset(var_name, pattern=None)
byref(var_name, *args, **kwargs)
exists(var_name, array_index=None)
get(k[, d]) D[k] if k in D, else d.  d defaults to None.
is_array(var_name)
set(var_name, value, array_index=None)
unset(var_name, array_index=None, nocomplain=False)
absolute()
call(tclcmd, *args)
children(pattern=None)
code(script)
create()
current()
delete()
eval(tclcmd, *args)
exists()
export(clear=False, *patterns)
forget(*patterns)
import_(force=False, *patterns)
is_absolute()
is_relative()
static join(string, *args)
make_absolute()
static normalize(string)
origin(command)
parent(force_eval=False)
static qualifiers(string)
static split(string)
static tail(string)
which(name, command=False, variable=False)
class pyats.tcl.namespace.TclVariable(var_name, array_index=None, tcl=None, cast=None)

Bases: object

absolute()
array_get(pattern=None)
array_get_obj(pattern=None)
array_get_str(pattern=None)
array_item_byref(array_index, cast=None)
array_names(pattern=None)
array_set(value)
array_size()
array_unset(pattern=None)
exists(array_index=None)
get(array_index=None, cast=<object object>)
get_obj(array_index=None, cast=<object object>)
get_str(array_index=None)
is_array()
make_absolute()
set(value, array_index=None)
unset(array_index=None, nocomplain=False)
class pyats.tcl.namespace.TempTclArrayVariable(var_name='::__pyats__{cls}_{id}_tmp', **kwargs)

Bases: TempTclVariable, TclArrayVariable

class pyats.tcl.namespace.TempTclCommand(func=None, cmd_name='::__pyats__{cls}_{id}_tmp', **kwargs)

Bases: TclCommand

class pyats.tcl.namespace.TempTclNamespace(ns='::__pyats__{cls}_{id}_tmp', **kwargs)

Bases: TclNamespace

class pyats.tcl.namespace.TempTclVariable(var_name='::__pyats__{cls}_{id}_tmp', **kwargs)

Bases: TclVariable

class pyats.tcl.q.Q(tcl)

Bases: object

Q class

Provides magic quick call methods for tcl interpreters. Allows users to call Tcl APIs as if they were attributes to the tcl interpreter object.

Examples

tcl.q.caas.load_lib(file=’/path/to/my/file.py’,

os=’NXOS’, parser=1)

tcl.q.set(‘myVar’, ‘value’) tcl.q.ns_a.ns_b.procname(‘arguments’, arg_a = ‘value, argb = ‘value’)

Parameters:

cast (bool) – flag to turn on/off casting. Default: True

Notes

  • positional arguments are kept in their order of appearance

  • keyword arguments are converted to dashed arguments in tcl, and appear after positional arguments

  • only supports [A-Za-z0-9_] for tcl namespaces and procedure names.

class pyats.tcl.q.Q_Code(*cmd, tcl)

Bases: object

Q_Code class

Worker class that implements Q logic

Implements:

pyats.tcl.tclstr pyats.tcl.tclobj

Authors:

Jean-Sebastien Trottier (strottie), CSG XR - Ottawa

Description:

This file implements the tclstr() and tclobj() functions

pyats.tcl.tclstr.tclobj(obj)
pyats.tcl.tclstr.tclstr(obj)

tclstr() Function/Class

This function converts any object into a string that is appropriate for use in Tcl.

The result is a string.

Note

If an object defines the __tclstr__() method, it will be invoked to perform the conversion.

Example

>>> from pyats.tcl import tclstr
>>> l = [1, 2, [3, 4]]
>>> tclstr(l)
'1 2 {3 4}'
>>> from pyats.tcl import tclstr
>>> d = {'my key': 'my value', 'a': 'b'}
>>> tclstr(d)
'{my key} {my value} a b'