You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/03/22 16:40:04 UTC
[GitHub] dubee closed pull request #3479: Makes wskadmin python2 and python3 compatible
dubee closed pull request #3479: Makes wskadmin python2 and python3 compatible
URL: https://github.com/apache/incubator-openwhisk/pull/3479
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/tools/admin/wskadmin b/tools/admin/wskadmin
index d5c579916a..4b85796bcf 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 59320d1121..13d379f79e 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 @@
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
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services