Unified approach to string formatting.
See original GitHub issue- Version: 3.15.0
- Python: 2.7/3.4/3.5
What was wrong?
We need a well though through string handling solution for bytesXX
, bytes
and string
types being passed into functions as arguments.
Currently, users expect to be able to provide hex encoded strings to some of these methods which either fails due to these methods expecting bytestrings, or it appears to succeed when in fact it has sent the provided hex-string as-is.
How can it be fixed?
For web3.sha3
and web3.eth.sign
we have a workable solution. See https://github.com/pipermerriam/web3.py/issues/289
For bytesXX
we should be able to be smart and detect hex encoded values.
- If the value is a byte string, validate
len(v) == XX
whereXX
is thebytesXX
length. - If the value is a text string, assume hex encoding. validate
len(v_without_0x_prefix) == 2 * XX
whereXX
is thebytesXX
length.
For bytes
types.
- If the value is a byte string, pass it through unmodified.
- If the value is a text string, validate that it is a valid hexidecimal encoded value.
For string
types.
- If the value is a byte string, pass it through unmodified.
- If the value is a text string, decode it as
utf8
into it’s bytes representation.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
String Formatting – Programming Fundamentals - Rebus Press
String formatting uses a process of string interpolation (variable substitution) to evaluate a string literal containing one or more placeholders, ...
Read more >Unified method to parse string in any ISO-8601 compliant format
I need a unified method to parse any ISO-8601 compliant string. Unfortunately, neither Joda nor fastxml StdDateFormat is fully qualified to ...
Read more >Standard numeric format strings | Microsoft Learn
Format method, and the StringBuilder.AppendFormat method. The composite format feature allows you to include the string representation of ...
Read more >String Formatting in Python - Scaler Topics
Another way to format strings in Python is to use the format() method. In this method, first, we put placeholders in the string...
Read more >Python string formatting - Medium
The basic way. The simplest method for concatenating strings and variables is the following: >>> print("hello" + " " + "world ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve updated the initial issue description to reflect this change.
@veox I believe what we are trying to support is both of the following:
demo.transact().setString("0xtentacle");
# that must be a unicode string (so in python2u"0xtent..."
)demo.transact().setString(b"\x30\x78\x74\x65\x6e\x74\x61\x63\x6c\x65");