This is an automated email from the ASF dual-hosted git repository.
dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git
The following commit(s) were added to refs/heads/master by this push:
new 1b786d9 Makes wskadmin python2 and python3 compatible (#3479)
1b786d9 is described below
commit 1b786d9c5145b8fbd076aa2449210bbdade81a41
Author: rodric rabbah <[email protected]>
AuthorDate: Thu Mar 22 12:40:02 2018 -0400
Makes wskadmin python2 and python3 compatible (#3479)
* Python2/3 compatibility.
* Replace encodestring for p2/3 compat.
* Replace filter for 2/3 compat.
* Compare to python version major directly.
---
tools/admin/wskadmin | 17 ++++++++++-------
tools/admin/wskutil.py | 20 +++++++++++++-------
2 files changed, 23 insertions(+), 14 deletions(-)
diff --git a/tools/admin/wskadmin b/tools/admin/wskadmin
index d5c5799..4b85796 100755
--- a/tools/admin/wskadmin
+++ b/tools/admin/wskadmin
@@ -32,7 +32,10 @@ import sys
import traceback
import uuid
import wskprop
-import urllib
+if sys.version_info.major >= 3:
+ from urllib.parse import quote_plus
+else:
+ from urllib import quote_plus
try:
import argcomplete
except ImportError:
@@ -246,7 +249,7 @@ def createUserCmd(args, props):
}
else:
if not doc.get('blocked'):
- namespaces = filter(lambda ns: ns['name'] == desiredNamespace,
doc['namespaces'])
+ namespaces = [ns for ns in doc['namespaces'] if ns['name'] ==
desiredNamespace]
if len(namespaces) == 0:
doc['namespaces'].append({
'name': desiredNamespace,
@@ -280,7 +283,7 @@ def getUserCmd(args, props):
# if requesting key for specific namespace, report only that key;
# use default namespace if no namespace provided
namespaceName = args.namespace if args.namespace is not None else
args.subject
- namespaces = filter(lambda ns: ns['name'] == namespaceName,
doc['namespaces'])
+ namespaces = [ns for ns in doc['namespaces'] if ns['name'] ==
namespaceName]
if len(namespaces) == 1:
ns = namespaces[0]
print('%s:%s' % (ns['uuid'], ns['key']))
@@ -414,7 +417,7 @@ def deleteUserCmd(args, props):
return 1
else:
namespaceToDelete = args.namespace.strip()
- namespaces = filter(lambda ns: ns['name'] != namespaceToDelete,
prev['namespaces'])
+ namespaces = [ns for ns in prev['namespaces'] if ns['name'] !=
namespaceToDelete]
if len(prev['namespaces']) == len(namespaces):
print('Namespace "%s" does not exist for "%s"' %
(namespaceToDelete, prev['_id']))
return 1
@@ -510,7 +513,7 @@ def unblockUserCmd(args, props):
def setLimitsCmd(args, props):
argsDict = vars(args)
docId = args.namespace + "/limits"
- (dbDoc, res) = getDocumentFromDb(props, urllib.quote_plus(docId),
args.verbose)
+ (dbDoc, res) = getDocumentFromDb(props, quote_plus(docId), args.verbose)
doc = dbDoc or {'_id': docId}
limits = ['invocationsPerMinute', 'firesPerMinute',
'concurrentInvocations']
@@ -530,7 +533,7 @@ def setLimitsCmd(args, props):
def getLimitsCmd(args, props):
argsDict = vars(args)
docId = args.namespace + "/limits"
- (dbDoc, res) = getDocumentFromDb(props, urllib.quote_plus(docId),
args.verbose)
+ (dbDoc, res) = getDocumentFromDb(props, quote_plus(docId), args.verbose)
if dbDoc is not None:
limits = ['invocationsPerMinute', 'firesPerMinute',
'concurrentInvocations']
@@ -548,7 +551,7 @@ def getLimitsCmd(args, props):
def deleteLimitsCmd(args, props):
argsDict = vars(args)
- docId = urllib.quote_plus(args.namespace + "/limits")
+ docId = quote_plus(args.namespace + "/limits")
(dbDoc, res) = getDocumentFromDb(props, docId, args.verbose)
if dbDoc is None:
diff --git a/tools/admin/wskutil.py b/tools/admin/wskutil.py
index 59320d1..13d379f 100644
--- a/tools/admin/wskutil.py
+++ b/tools/admin/wskutil.py
@@ -21,11 +21,17 @@
import os
import json
-import httplib
+import sys
+if sys.version_info.major >= 3:
+ from http.client import HTTPConnection, HTTPSConnection, IncompleteRead
+ from urllib.parse import urlparse
+else:
+ from httplib import HTTPConnection, HTTPSConnection, IncompleteRead
+ from urlparse import urlparse
import ssl
import base64
import socket
-from urlparse import urlparse
+
# global configurations, can control whether to allow untrusted certificates
# on HTTPS connections
@@ -34,17 +40,17 @@ httpRequestProps = {'secure': True}
def request(method, urlString, body = '', headers = {}, auth = None, verbose =
False, https_proxy = os.getenv('https_proxy', None), timeout = 10):
url = urlparse(urlString)
if url.scheme == 'http':
- conn = httplib.HTTPConnection(url.netloc, timeout = timeout)
+ conn = HTTPConnection(url.netloc, timeout = timeout)
else:
if httpRequestProps['secure'] or not hasattr(ssl,
'_create_unverified_context'):
- conn = httplib.HTTPSConnection(url.netloc if https_proxy is None
else https_proxy, timeout = timeout)
+ conn = HTTPSConnection(url.netloc if https_proxy is None else
https_proxy, timeout = timeout)
else:
- conn = httplib.HTTPSConnection(url.netloc if https_proxy is None
else https_proxy, context=ssl._create_unverified_context(), timeout = timeout)
+ conn = HTTPSConnection(url.netloc if https_proxy is None else
https_proxy, context=ssl._create_unverified_context(), timeout = timeout)
if https_proxy:
conn.set_tunnel(url.netloc)
if auth is not None:
- auth = base64.encodestring(auth).replace('\n', '')
+ auth = base64.b64encode(auth.encode()).decode()
headers['Authorization'] = 'Basic %s' % auth
if verbose:
@@ -63,7 +69,7 @@ def request(method, urlString, body = '', headers = {}, auth
= None, verbose = F
body = ''
try:
body = res.read()
- except httplib.IncompleteRead as e:
+ except IncompleteRead as e:
body = e.partial
# patch the read to return just the body since the normal read
--
To stop receiving notification emails like this one, please contact
[email protected].