This is an automated email from the ASF dual-hosted git repository.
kpvdr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/qpid-proton.git
The following commit(s) were added to refs/heads/master by this push:
new 4f18c35 PROTON-2010: Fix for Proton Python handling of comments and
mech lists in connection config file. Also, small fix for JSON syntax in
connect-config.md.
4f18c35 is described below
commit 4f18c353b5f73cc020d3ba3b66600e7ddc7d5441
Author: Kim van der Riet <[email protected]>
AuthorDate: Tue Feb 26 12:20:25 2019 -0500
PROTON-2010: Fix for Proton Python handling of comments and mech lists in
connection config file. Also, small fix for JSON syntax in connect-config.md.
---
docs/connect-config.md | 4 ++--
python/proton/_common.py | 1 -
python/proton/_reactor.py | 17 ++++++++++++++++-
python/proton/_transport.py | 2 ++
4 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/docs/connect-config.md b/docs/connect-config.md
index eeaea4e..ec3b5ff 100644
--- a/docs/connect-config.md
+++ b/docs/connect-config.md
@@ -35,8 +35,8 @@ values, all properties are optional.
// Note: it is an error to have a "tls" object unless scheme="amqps"
"tls": {
"cert": null, // [string] name of client certificate or database
- "key": null // [string] private key or identity for client
certificate
+ "key": null, // [string] private key or identity for client
certificate
"ca": null, // [string] name of CA certificate or database
- "verify": true, // [bool] if true, require a valid cert with matching
host name
+ "verify": true // [bool] if true, require a valid cert with matching
host name
}
}
diff --git a/python/proton/_common.py b/python/proton/_common.py
index 3715c6a..d64f408 100644
--- a/python/proton/_common.py
+++ b/python/proton/_common.py
@@ -77,7 +77,6 @@ def unicode2utf8(string):
# Anything else illegal - specifically python3 bytes
raise TypeError("Unrecognized string type: %r (%s)" % (string,
type(string)))
-
def utf82unicode(string):
"""Convert C strings returned from proton-c into python unicode"""
if string is None:
diff --git a/python/proton/_reactor.py b/python/proton/_reactor.py
index 993c177..e1ddae3 100644
--- a/python/proton/_reactor.py
+++ b/python/proton/_reactor.py
@@ -23,6 +23,7 @@ from __future__ import absolute_import
import heapq
import json
import logging
+import re
import os
import time
import traceback
@@ -863,10 +864,24 @@ def _get_default_config():
conf = os.environ.get('MESSAGING_CONNECT_FILE') or _find_config_file()
if conf and os.path.isfile(conf):
with open(conf, 'r') as f:
- return json.load(f)
+ json_text = f.read()
+ json_text = _strip_json_comments(json_text)
+ return json.loads(json_text)
else:
return {}
+def _strip_json_comments(json_text):
+ """This strips c-style comments from text, taking into account
'/*comments*/' and '//comments'
+ nested inside a string etc."""
+ def replacer(match):
+ s = match.group(0)
+ if s.startswith('/'):
+ return " " # note: a space and not an empty string
+ else:
+ return s
+ pattern =
re.compile(r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
re.DOTALL | re.MULTILINE)
+ return re.sub(pattern, replacer, json_text)
+
def _get_default_port_for_scheme(scheme):
if scheme == 'amqps':
return 5671
diff --git a/python/proton/_transport.py b/python/proton/_transport.py
index 2c7a9b4..ddd08c7 100644
--- a/python/proton/_transport.py
+++ b/python/proton/_transport.py
@@ -309,6 +309,8 @@ class SASL(Wrapper):
return outcome
def allowed_mechs(self, mechs):
+ if isinstance(mechs, list):
+ mechs = " ".join(mechs)
pn_sasl_allowed_mechs(self._sasl, unicode2utf8(mechs))
def _get_allow_insecure_mechs(self):
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]