Exscript.util.cast module

Handy shortcuts for converting types.

Exscript.util.cast.to_host(host, default_protocol='telnet', default_domain='')[source]

Given a string or a Host object, this function returns a Host object.

Parameters:
  • host (string|Host) – A hostname (may be URL formatted) or a Host object.
  • default_protocol (str) – Passed to the Host constructor.
  • default_domain (str) – Appended to each hostname that has no domain.
Return type:

Host

Returns:

The Host object.

Exscript.util.cast.to_hosts(hosts, default_protocol='telnet', default_domain='')[source]

Given a string or a Host object, or a list of strings or Host objects, this function returns a list of Host objects.

Parameters:
  • hosts (string|Host|list(string)|list(Host)) – One or more hosts or hostnames.
  • default_protocol (str) – Passed to the Host constructor.
  • default_domain (str) – Appended to each hostname that has no domain.
Return type:

list[Host]

Returns:

A list of Host objects.

Exscript.util.cast.to_list(item)[source]

If the given item is iterable, this function returns the given item. If the item is not iterable, this function returns a list with only the item in it.

Parameters:item (object) – Any object.
Return type:list
Returns:A list with the item in it.
Exscript.util.cast.to_regex(regex, flags=0)[source]

Given a string, this function returns a new re.RegexObject. Given a re.RegexObject, this function just returns the same object.

Parameters:
  • regex (string|re.RegexObject) – A regex or a re.RegexObject
  • flags (int) – See Python’s re.compile().
Return type:

re.RegexObject

Returns:

The Python regex object.

Exscript.util.cast.to_regexs(regexs)[source]

Given a string or a re.RegexObject, or a list of strings or re.RegexObjects, this function returns a list of re.RegexObjects.

Parameters:regexs (str|re.RegexObject|list(str|re.RegexObject)) – One or more regexs or re.RegexObjects.
Return type:list(re.RegexObject)
Returns:A list of re.RegexObjects.