Status: New
Owner: ----
Labels: Type-Enhancement Priority-Medium
New issue 1581 by [email protected]: Bytes Library
http://code.google.com/p/robotframework/issues/detail?id=1581
This results from issue 1506.
I implemented some Keywords for directly creating byte strings
to be used when dealing with binary data.
Keyword arguments are processed as unicode by default.
Currently you can only create byte strings
using `Encode String To Bytes` or `Evaluate`.
Encoding/decoding is generally targeted at textual data.
And you must explicitly specify latin (iso8859) encoding
to get a direct mapping between unicode and byte string char values.
`Evaluate` is more a last fallback...
if you really can't find a suitable solution using normal Keywords.
In Python 2.x explicitly creating byte strings is often not needed.
`str` and `unicode` are implicitly convertible.
In Python 3 `bytes` and `str` can't be implicitly converted.
So explicit byte string creation and conversions are necessary
for making Robot Framework compatible and useable with Python 3.
Additionally, when dealing with binary data
it is often useful to define bytes numerically
with integer sequences or with simple hex or binary digit strings.
There are currently no Keywords which let you do this easily.
I created 4 `Create Bytes ...` Keywords with different input support.
They actually return `bytearray`s.
`bytearray` is the same in Python 2.6+ and Python 3.
It makes the code Python 2.5 incompatible.
But is the simplest way of Python 2/3 compatible bytes data creation.
And mutable bytes can generally be useful.
And could need some additional Keywords for manipulation...
Better return `str` in 2.x and `bytes` in 3.x?
I didn't want to pollute other standard libraries with too much bytes ;)
so I put them into a new Bytes Library:
* Bytes.Create Bytes Hyv\xe4t t
... ${0x61} ${0o166} ${0b1110101} ${116} !
* Bytes.Create Bytes From Numbers 72 ${121} 118 0xe4 0b1110100
... 0o40 ${116} ${0x61} ${0o166} ${0b1110101} 116 ${0o41}
* Bytes.Create Bytes From Hex 4879 76e474 20 7461 767574 21
* Bytes.Create Bytes From Binary
... 0100100001111001 011101101110010001110100
... 00100000 0111010001100001 011101100111010101110100 00100001
==> bytearray(b'Hyv\xe4t tavut!')
The first two Keywords also allow char/number sequences as single arguments.
Single values and values from sequences are just combined:
@{avu}= Create List ${0x61} ${0o166} u
Bytes.Create Bytes Hyv\xe4t t ${avu} t!
Was this a good design choice? :)
I also added `Bytes.Should Be Bytes`.
I know there is `String.Should Be Byte String`.
`Should Be Bytes` also allows `bytearray`.
You can find the code in my robotframework fork's bytes bookmark:
https://bitbucket.org/userzimmermann/robotframework/commits/branch/bytes
Direct link to Bytes.py:
https://bitbucket.org/userzimmermann/robotframework/src/bytes/src/robot/libraries/Bytes.py
There are no docs and tests so far...
And last but not least: Is Hyvät tavut! grammatically correct? :)
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.