Forráskód Böngészése

HUE-8737 [py3] Make jdbc and saml imports optional

Romain 5 éve
szülő
commit
482a3a5a71

+ 1 - 1
desktop/core/src/desktop/lib/wsgiserver.py

@@ -654,7 +654,7 @@ class HTTPRequest(object):
         # exc_info tuple."
         if self.sent_headers:
             try:
-                raise exc_info[0], exc_info[1], exc_info[2]
+                raise exc_info[1]
             finally:
                 exc_info = None
 

+ 10 - 9
desktop/libs/indexer/src/indexer/api3.py

@@ -15,11 +15,10 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from __future__ import print_function
 from future import standard_library
 standard_library.install_aliases()
-from builtins import oct
-from builtins import zip
+
+from builtins import oct, zip
 from past.builtins import basestring
 import json
 import logging
@@ -29,8 +28,14 @@ import sys
 from django.urls import reverse
 from django.utils.translation import ugettext as _
 from django.views.decorators.http import require_POST
-from simple_salesforce.api import Salesforce
-from simple_salesforce.exceptions import SalesforceRefusedRequest
+
+LOG = logging.getLogger(__name__)
+
+try:
+  from simple_salesforce.api import Salesforce
+  from simple_salesforce.exceptions import SalesforceRefusedRequest
+except ImportError:
+  LOG.warn('simple_salesforce module not found')
 
 from desktop.lib import django_mako
 from desktop.lib.django_util import JsonResponse
@@ -63,10 +68,6 @@ else:
   from urllib import unquote as urllib_unquote
   from urlparse import urlparse
 
-
-LOG = logging.getLogger(__name__)
-
-
 try:
   from beeswax.server import dbms
 except ImportError as e:

+ 12 - 10
desktop/libs/liboauth/src/liboauth/views.py

@@ -17,14 +17,16 @@
 
 from future import standard_library
 standard_library.install_aliases()
-try:
-  import oauth2 as oauth
-except:
-  oauth = None
 
 import logging
+
+LOG = logging.getLogger(__name__)
+
 import urllib.request, urllib.parse, urllib.error
-import httplib2
+try:
+  import httplib2
+except ImportError:
+  LOG.warn('httplib2 module not found')
 
 import django.contrib.auth.views
 from django.core import urlresolvers
@@ -69,21 +71,21 @@ def show_login_page(request, login_errors=False):
 
 @login_notrequired
 def oauth_login(request):
-
   if 'social' not in request.GET:
-      raise Exception(_("Invalid request: %s") % resp)
+    raise Exception(_("Invalid request: %s") % resp)
   else:
-      url = OAuthBackend.handleLoginRequest(request)
+    url = OAuthBackend.handleLoginRequest(request)
 
   return HttpResponseRedirect(url)
 
 
 @login_notrequired
 def oauth_authenticated(request):
-
   access_token, next = OAuthBackend.handleAuthenticationRequest(request)
   if access_token == "":
-      return show_login_page(request, True)
+    return show_login_page(request, True)
+
   user = authenticate(access_token = access_token)
   login(request, user)
+
   return HttpResponseRedirect(next)

+ 2 - 3
desktop/libs/librdbms/src/librdbms/jdbc.py

@@ -27,11 +27,10 @@ from notebook.connectors.base import AuthenticationRequired
 
 LOG = logging.getLogger(__name__)
 
-
 try:
   from py4j.java_gateway import JavaGateway, JavaObject
-except ImportError as e:
-  LOG.exception('Failed to import py4j')
+except:
+  LOG.warn('Failed to import py4j')
 
 
 def query_and_fetch(db, statement, n=None):

+ 24 - 13
desktop/libs/libsaml/src/libsaml/urls.py

@@ -15,10 +15,18 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+import logging
+
 from django.conf.urls import url
-from djangosaml2 import views as djangosaml2_views
-from libsaml import views as libsaml_views
 
+LOG = logging.getLogger(__name__)
+
+try:
+  from djangosaml2 import views as djangosaml2_views
+  from libsaml import views as libsaml_views
+except ImportError:
+  LOG.warn('djangosaml2 module not found')
+  djangosaml2_views = None
 
 try:
   from djangosaml2.views import logout_service_post
@@ -27,17 +35,20 @@ except ImportError:
   logout_service_post = None
 
 
-urlpatterns = [
+if djangosaml2_views is not None:
+  urlpatterns = [
     url(r'^logout/$', djangosaml2_views.logout, name='saml2_logout')
-]
-
-urlpatterns += [
-                        url(r'^ls/$', libsaml_views.logout_service, name='saml2_ls'),
-                        url(r'^acs/$', libsaml_views.assertion_consumer_service, name='saml2_acs'),
-                        url(r'^login/$', libsaml_views.login, name='saml2_login'),
-                        url(r'^metadata/$', libsaml_views.metadata, name='saml2_metadata'),
-                        url(r'^test/$', libsaml_views.echo_attributes)]
+  ]
 
-if logout_service_post is not None:
   urlpatterns += [
-                          url(r'^ls/post/$', libsaml_views.logout_service_post, name='saml2_ls_post')]
+    url(r'^ls/$', libsaml_views.logout_service, name='saml2_ls'),
+    url(r'^acs/$', libsaml_views.assertion_consumer_service, name='saml2_acs'),
+    url(r'^login/$', libsaml_views.login, name='saml2_login'),
+    url(r'^metadata/$', libsaml_views.metadata, name='saml2_metadata'),
+    url(r'^test/$', libsaml_views.echo_attributes)
+  ]
+
+  if logout_service_post is not None:
+    urlpatterns += [
+      url(r'^ls/post/$', libsaml_views.logout_service_post, name='saml2_ls_post')
+    ]