From c906a97ffa5b135cb52d30258992c08fbe133692 Mon Sep 17 00:00:00 2001 From: lowzj Date: Sat, 16 Jul 2016 02:13:05 +0800 Subject: [PATCH] update base.py,twisted.py to support python2.6 --- consul/base.py | 24 ++++++++++++------------ consul/twisted.py | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/consul/base.py b/consul/base.py index 4e049195..ccdfbbe8 100644 --- a/consul/base.py +++ b/consul/base.py @@ -1910,37 +1910,37 @@ def _query_data(self, service=None, tags=None, ttl=None, regexp=None): - service_body = { - k: v for k, v in { + service_body = dict([ + (k, v) for k, v in { 'service': service, 'onlypassing': onlypassing, 'tags': tags, - 'failover': { - k: v for k, v in { + 'failover': dict([ + (k, v) for k, v in { 'nearestn': nearestn, 'datacenters': datacenters }.items() if v is not None - } + ]) }.items() if v is not None - } + ]) - data = { - k: v for k, v in { + data = dict([ + (k, v) for k, v in { 'name': name, 'session': session, 'token': token or self.agent.token, 'dns': { 'ttl': ttl } if ttl is not None else None, - 'template': { - k: v for k, v in { + 'template': dict([ + (k, v) for k, v in { 'type': 'name_prefix_match', 'regexp': regexp }.items() if v is not None - }, + ]), 'service': service_body }.items() if v is not None - } + ]) return json.dumps(data) def create(self, service, diff --git a/consul/twisted.py b/consul/twisted.py index dcc81880..33834d7a 100644 --- a/consul/twisted.py +++ b/consul/twisted.py @@ -82,10 +82,10 @@ def compat_string(value): def _get_resp(self, response): # Merge multiple header values as per RFC2616 # http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2 - headers = { - self.compat_string(k): ','.join(map(self.compat_string, v)) + headers = dict([ + (self.compat_string(k), ','.join(map(self.compat_string, v))) for k, v in dict(response.headers.getAllRawHeaders()).items() - } + ]) body = yield response.text(encoding='utf-8') returnValue((response.code, headers, body))