kpvdr commented on a change in pull request #192: Changed Python API to better
handle strings where symbo…
URL: https://github.com/apache/qpid-proton/pull/192#discussion_r334494101
##########
File path: python/proton/_data.py
##########
@@ -308,6 +308,222 @@ def __eq__(self, o):
return False
+def _check_type(s, allow_ulong=False, throw=True):
+ if isinstance(s, symbol):
+ return s
+ if allow_ulong and isinstance(s, ulong):
+ return s
+ if isinstance(s, str):
+ # Must be py2 or py3 str
+ return symbol(s)
+ if isinstance(s, unicode):
+ # This must be python2 unicode as we already detected py3 str above
+ return symbol(s.encode('utf-8'))
+ if throw:
+ raise TypeError('Non-symbol type %s: %s' % (type(s), s))
+ return s
+
+def check_is_symbol(s, throw=True):
+ """
+ Check if s is a symbol type. If s is a string, convert to a symbol
+ and return it. If s is already a symbol, just return it.
+ For other types of s, if throw == True, raise a ``TypeError``,
+ otherwise return s without any changes.
+
+ :param s: Any object that should be checked
+ :type s: any
+ :param throw: If true, raise exception if non-allowed type is found.
+ Otherwise, return non-allowed types without any changes.
+ :type throw: ``bool``
+ """
+ return _check_type(s, allow_ulong=False, throw=throw)
+
+def check_is_symbol_or_ulong(s, throw=True):
Review comment:
I am unsure what needs to be done here. I can:
1. Place an '_' in front of them and remove them from the public API. In
fact, they have not been included in the API docs. I could pull the doc block
also.
2. Rename them to 'ensure_xxx' or perhaps 'check_and_promote_xxx' which
seems excessively long and burdensome, or
3. A combination of both of the above?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]