Robot Framework
robot.libraries.BuiltIn._Converter Class Reference
Inheritance diagram for robot.libraries.BuiltIn._Converter:
robot.libraries.BuiltIn._BuiltInBase robot.libraries.BuiltIn.BuiltIn

Public Member Functions

def convert_to_binary (self, item, base=None, prefix=None, length=None)
 Converts the given item to a binary string. More...
 
def convert_to_boolean (self, item)
 Converts the given item to Boolean true or false. More...
 
def convert_to_bytes (self, input, input_type='text')
 Converts the given input to bytes according to the input_type. More...
 
def convert_to_hex (self, item, base=None, prefix=None, length=None, lowercase=False)
 Converts the given item to a hexadecimal string. More...
 
def convert_to_integer (self, item, base=None)
 Converts the given item to an integer number. More...
 
def convert_to_number (self, item, precision=None)
 Converts the given item to a floating point number. More...
 
def convert_to_octal (self, item, base=None, prefix=None, length=None)
 Converts the given item to an octal string. More...
 
def convert_to_string (self, item)
 Converts the given item to a Unicode string. More...
 
def create_dictionary (self, *items)
 Creates and returns a dictionary based on the given items. More...
 
def create_list (self, *items)
 Returns a list containing given items. More...
 

Private Member Functions

def _convert_to_bin_oct_hex (self, item, base, prefix, length, format_spec)
 
def _convert_to_integer (self, orig, base=None)
 
def _convert_to_number (self, item, precision=None)
 
def _convert_to_number_without_precision (self, item)
 
def _format_separate_dict_items (self, separate)
 
def _get_base (self, item, base)
 
def _get_ordinals_from_bin (self, input)
 
def _get_ordinals_from_hex (self, input)
 
def _get_ordinals_from_int (self, input)
 
def _get_ordinals_from_text (self, input)
 
def _input_to_tokens (self, input, length)
 
def _split_dict_items (self, items)
 
def _test_ordinal (self, ordinal, original, type)
 

Additional Inherited Members

- Properties inherited from robot.libraries.BuiltIn._BuiltInBase
 _context = property
 
 _namespace = property
 
 _variables = property
 

Detailed Description

Definition at line 102 of file BuiltIn.py.

Member Function Documentation

◆ _convert_to_bin_oct_hex()

def robot.libraries.BuiltIn._Converter._convert_to_bin_oct_hex (   self,
  item,
  base,
  prefix,
  length,
  format_spec 
)
private

Definition at line 229 of file BuiltIn.py.

◆ _convert_to_integer()

def robot.libraries.BuiltIn._Converter._convert_to_integer (   self,
  orig,
  base = None 
)
private

Definition at line 133 of file BuiltIn.py.

◆ _convert_to_number()

def robot.libraries.BuiltIn._Converter._convert_to_number (   self,
  item,
  precision = None 
)
private

Definition at line 273 of file BuiltIn.py.

◆ _convert_to_number_without_precision()

def robot.libraries.BuiltIn._Converter._convert_to_number_without_precision (   self,
  item 
)
private

Definition at line 279 of file BuiltIn.py.

◆ _format_separate_dict_items()

def robot.libraries.BuiltIn._Converter._format_separate_dict_items (   self,
  separate 
)
private

Definition at line 472 of file BuiltIn.py.

◆ _get_base()

def robot.libraries.BuiltIn._Converter._get_base (   self,
  item,
  base 
)
private

Definition at line 143 of file BuiltIn.py.

◆ _get_ordinals_from_bin()

def robot.libraries.BuiltIn._Converter._get_ordinals_from_bin (   self,
  input 
)
private

Definition at line 399 of file BuiltIn.py.

◆ _get_ordinals_from_hex()

def robot.libraries.BuiltIn._Converter._get_ordinals_from_hex (   self,
  input 
)
private

Definition at line 394 of file BuiltIn.py.

◆ _get_ordinals_from_int()

def robot.libraries.BuiltIn._Converter._get_ordinals_from_int (   self,
  input 
)
private

Definition at line 385 of file BuiltIn.py.

◆ _get_ordinals_from_text()

def robot.libraries.BuiltIn._Converter._get_ordinals_from_text (   self,
  input 
)
private

Definition at line 374 of file BuiltIn.py.

◆ _input_to_tokens()

def robot.libraries.BuiltIn._Converter._input_to_tokens (   self,
  input,
  length 
)
private

Definition at line 404 of file BuiltIn.py.

◆ _split_dict_items()

def robot.libraries.BuiltIn._Converter._split_dict_items (   self,
  items 
)
private

Definition at line 463 of file BuiltIn.py.

◆ _test_ordinal()

def robot.libraries.BuiltIn._Converter._test_ordinal (   self,
  ordinal,
  original,
  type 
)
private

Definition at line 379 of file BuiltIn.py.

◆ convert_to_binary()

def robot.libraries.BuiltIn._Converter.convert_to_binary (   self,
  item,
  base = None,
  prefix = None,
  length = None 
)

Converts the given item to a binary string.

    The ``item``, with an optional ``base``, is first converted to an
    integer using `Convert To Integer` internally. After that it
    is converted to a binary number (base 2) represented as a
    string such as ``1011``.

    The returned value can contain an optional ``prefix`` and can be
    required to be of minimum ``length`` (excluding the prefix and a
    possible minus sign). If the value is initially shorter than
    the required length, it is padded with zeros.

    Examples:
    | ${result} = | Convert To Binary | 10 |         |           | # Result is 1010   |
    | ${result} = | Convert To Binary | F  | base=16 | prefix=0b | # Result is 0b1111 |
    | ${result} = | Convert To Binary | -2 | prefix=B | length=4 | # Result is -B0010 |

    See also `Convert To Integer`, `Convert To Octal` and `Convert To Hex`.

Definition at line 176 of file BuiltIn.py.

◆ convert_to_boolean()

def robot.libraries.BuiltIn._Converter.convert_to_boolean (   self,
  item 
)

Converts the given item to Boolean true or false.

    Handles strings ``True`` and ``False`` (case-insensitive) as expected,
    otherwise returns item's
    [http://docs.python.org/library/stdtypes.html#truth|truth value]
    using Python's ``bool()`` method.

Definition at line 311 of file BuiltIn.py.

◆ convert_to_bytes()

def robot.libraries.BuiltIn._Converter.convert_to_bytes (   self,
  input,
  input_type = 'text' 
)

Converts the given input to bytes according to the input_type.

    Valid input types are listed below:

    - ``text:`` Converts text to bytes character by character. All
      characters with ordinal below 256 can be used and are converted to
      bytes with same values. Many characters are easiest to represent
      using escapes like ``\x00`` or ``\xff``. Supports both Unicode
      strings and bytes.

    - ``int:`` Converts integers separated by spaces to bytes. Similarly as
      with `Convert To Integer`, it is possible to use binary, octal, or
      hex values by prefixing the values with ``0b``, ``0o``, or ``0x``,
      respectively.

    - ``hex:`` Converts hexadecimal values to bytes. Single byte is always
      two characters long (e.g. ``01`` or ``FF``). Spaces are ignored and
      can be used freely as a visual separator.

    - ``bin:`` Converts binary values to bytes. Single byte is always eight
      characters long (e.g. ``00001010``). Spaces are ignored and can be
      used freely as a visual separator.

    In addition to giving the input as a string, it is possible to use
    lists or other iterables containing individual characters or numbers.
    In that case numbers do not need to be padded to certain length and
    they cannot contain extra spaces.

    Examples (last column shows returned bytes):
    | ${bytes} = | Convert To Bytes | hyvä      |     | # hyv\xe4      |
    | ${bytes} = | Convert To Bytes | hyv\xe4   |     | # hyv\xe4      |
    | ${bytes} = | Convert To Bytes | \xff\x07  |     | # \xff\x07     |
    | ${bytes} = | Convert To Bytes | 82 70     | int | # RF           |
    | ${bytes} = | Convert To Bytes | 0b10 0x10 | int | # \x02\x10     |
    | ${bytes} = | Convert To Bytes | ff 00 07  | hex | # \xff\x00\x07 |
    | ${bytes} = | Convert To Bytes | 52462121  | hex | # RF!!         |
    | ${bytes} = | Convert To Bytes | 0000 1000 | bin | # \x08         |
    | ${input} = | Create List      | 1         | 2   | 12             |
    | ${bytes} = | Convert To Bytes | ${input}  | int | # \x01\x02\x0c |
    | ${bytes} = | Convert To Bytes | ${input}  | hex | # \x01\x02\x12 |

    Use `Encode String To Bytes` in ``String`` library if you need to
    convert text to bytes using a certain encoding.

Definition at line 364 of file BuiltIn.py.

◆ convert_to_hex()

def robot.libraries.BuiltIn._Converter.convert_to_hex (   self,
  item,
  base = None,
  prefix = None,
  length = None,
  lowercase = False 
)

Converts the given item to a hexadecimal string.

    The ``item``, with an optional ``base``, is first converted to an
    integer using `Convert To Integer` internally. After that it
    is converted to a hexadecimal number (base 16) represented as
    a string such as ``FF0A``.

    The returned value can contain an optional ``prefix`` and can be
    required to be of minimum ``length`` (excluding the prefix and a
    possible minus sign). If the value is initially shorter than
    the required length, it is padded with zeros.

    By default the value is returned as an upper case string, but the
    ``lowercase`` argument a true value (see `Boolean arguments`) turns
    the value (but not the given prefix) to lower case.

    Examples:
    | ${result} = | Convert To Hex | 255 |           |              | # Result is FF    |
    | ${result} = | Convert To Hex | -10 | prefix=0x | length=2     | # Result is -0x0A |
    | ${result} = | Convert To Hex | 255 | prefix=X | lowercase=yes | # Result is Xff   |

    See also `Convert To Integer`, `Convert To Binary` and `Convert To Octal`.

Definition at line 224 of file BuiltIn.py.

◆ convert_to_integer()

def robot.libraries.BuiltIn._Converter.convert_to_integer (   self,
  item,
  base = None 
)

Converts the given item to an integer number.

    If the given item is a string, it is by default expected to be an
    integer in base 10. There are two ways to convert from other bases:

    - Give base explicitly to the keyword as ``base`` argument.

    - Prefix the given string with the base so that ``0b`` means binary
      (base 2), ``0o`` means octal (base 8), and ``0x`` means hex (base 16).
      The prefix is considered only when ``base`` argument is not given and
      may itself be prefixed with a plus or minus sign.

    The syntax is case-insensitive and possible spaces are ignored.

    Examples:
    | ${result} = | Convert To Integer | 100    |    | # Result is 100   |
    | ${result} = | Convert To Integer | FF AA  | 16 | # Result is 65450 |
    | ${result} = | Convert To Integer | 100    | 8  | # Result is 64    |
    | ${result} = | Convert To Integer | -100   | 2  | # Result is -4    |
    | ${result} = | Convert To Integer | 0b100  |    | # Result is 4     |
    | ${result} = | Convert To Integer | -0x100 |    | # Result is -256  |

    See also `Convert To Number`, `Convert To Binary`, `Convert To Octal`,
    `Convert To Hex`, and `Convert To Bytes`.

Definition at line 129 of file BuiltIn.py.

◆ convert_to_number()

def robot.libraries.BuiltIn._Converter.convert_to_number (   self,
  item,
  precision = None 
)

Converts the given item to a floating point number.

    If the optional ``precision`` is positive or zero, the returned number
    is rounded to that number of decimal digits. Negative precision means
    that the number is rounded to the closest multiple of 10 to the power
    of the absolute precision. If a number is equally close to a certain
    precision, it is always rounded away from zero.

    Examples:
    | ${result} = | Convert To Number | 42.512 |    | # Result is 42.512 |
    | ${result} = | Convert To Number | 42.512 | 1  | # Result is 42.5   |
    | ${result} = | Convert To Number | 42.512 | 0  | # Result is 43.0   |
    | ${result} = | Convert To Number | 42.512 | -1 | # Result is 40.0   |

    Notice that machines generally cannot store floating point numbers
    accurately. This may cause surprises with these numbers in general
    and also when they are rounded. For more information see, for example,
    these resources:

    - http://docs.python.org/tutorial/floatingpoint.html
    - http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition

    If you want to avoid possible problems with floating point numbers,
    you can implement custom keywords using Python's
    [http://docs.python.org/library/decimal.html|decimal] or
    [http://docs.python.org/library/fractions.html|fractions] modules.

    If you need an integer number, use `Convert To Integer` instead.

Definition at line 269 of file BuiltIn.py.

◆ convert_to_octal()

def robot.libraries.BuiltIn._Converter.convert_to_octal (   self,
  item,
  base = None,
  prefix = None,
  length = None 
)

Converts the given item to an octal string.

    The ``item``, with an optional ``base``, is first converted to an
    integer using `Convert To Integer` internally. After that it
    is converted to an octal number (base 8) represented as a
    string such as ``775``.

    The returned value can contain an optional ``prefix`` and can be
    required to be of minimum ``length`` (excluding the prefix and a
    possible minus sign). If the value is initially shorter than
    the required length, it is padded with zeros.

    Examples:
    | ${result} = | Convert To Octal | 10 |            |          | # Result is 12      |
    | ${result} = | Convert To Octal | -F | base=16    | prefix=0 | # Result is -017    |
    | ${result} = | Convert To Octal | 16 | prefix=oct | length=4 | # Result is oct0020 |

    See also `Convert To Integer`, `Convert To Binary` and `Convert To Hex`.

Definition at line 198 of file BuiltIn.py.

◆ convert_to_string()

def robot.libraries.BuiltIn._Converter.convert_to_string (   self,
  item 
)

Converts the given item to a Unicode string.

    Strings are also [http://www.macchiato.com/unicode/nfc-faq|
    NFC normalized].

    Use `Encode String To Bytes` and `Decode Bytes To String` keywords
    in ``String`` library if you need to convert between Unicode and byte
    strings using different encodings. Use `Convert To Bytes` if you just
    want to create byte strings.

Definition at line 300 of file BuiltIn.py.

◆ create_dictionary()

def robot.libraries.BuiltIn._Converter.create_dictionary (   self,
items 
)

Creates and returns a dictionary based on the given items.

    Items are typically given using the ``key=value`` syntax same way as
    ``&{dictionary}`` variables are created in the Variable table. Both
    keys and values can contain variables, and possible equal sign in key
    can be escaped with a backslash like ``escaped\\=key=value``. It is
    also possible to get items from existing dictionaries by simply using
    them like ``&{dict}``.

    Alternatively items can be specified so that keys and values are given
    separately. This and the ``key=value`` syntax can even be combined,
    but separately given items must be first. If same key is used multiple
    times, the last value has precedence.

    The returned dictionary is ordered, and values with strings as keys
    can also be accessed using a convenient dot-access syntax like
    ``${dict.key}``. Technically the returned dictionary is Robot
    Framework's own ``DotDict`` instance. If there is a need, it can be
    converted into a regular Python ``dict`` instance by using the
    `Convert To Dictionary` keyword from the Collections library.

    Examples:
    | &{dict} = | Create Dictionary | key=value | foo=bar | | | # key=value syntax |
    | Should Be True | ${dict} == {'key': 'value', 'foo': 'bar'} |
    | &{dict2} = | Create Dictionary | key | value | foo | bar | # separate key and value |
    | Should Be Equal | ${dict} | ${dict2} |
    | &{dict} = | Create Dictionary | ${1}=${2} | &{dict} | foo=new | | # using variables |
    | Should Be True | ${dict} == {1: 2, 'key': 'value', 'foo': 'new'} |
    | Should Be Equal | ${dict.key} | value | | | | # dot-access |

Definition at line 456 of file BuiltIn.py.

◆ create_list()

def robot.libraries.BuiltIn._Converter.create_list (   self,
items 
)

Returns a list containing given items.

    The returned list can be assigned both to ``${scalar}`` and ``@{list}``
    variables.

    Examples:
    | @{list} =   | Create List | a    | b    | c    |
    | ${scalar} = | Create List | a    | b    | c    |
    | ${ints} =   | Create List | ${1} | ${2} | ${3} |

Definition at line 422 of file BuiltIn.py.


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