浏览代码

HUE-8935 [hadoop] Small code formatting in exception libs

Romain 6 年之前
父节点
当前提交
8d0a6b4ba7

+ 10 - 4
desktop/core/src/desktop/lib/exceptions_renderable.py

@@ -33,8 +33,7 @@ LOG = logging.getLogger(__name__)
 
 class PopupException(Exception):
   """
-  Middleware will render this exception; and the template
-  renders it as a pop-up.
+  Middleware will render this exception; and the template renders it as a pop-up.
   """
   def __init__(self, message, title="Error", detail=None, error_code=500):
     Exception.__init__(self, message)
@@ -53,8 +52,14 @@ class PopupException(Exception):
       LOG.error('Potential trace: %s' % self.traceback)
 
   def response(self, request):
-    data = dict(title=force_unicode(self.title), message=force_unicode(self.message), detail=force_unicode(self.detail) if self.detail else None, traceback=self.traceback)
-    data['is_embeddable'] = request.GET.get('is_embeddable', False)
+    data = {
+      'title': force_unicode(self.title),
+      'message': force_unicode(self.message),
+      'detail': force_unicode(self.detail) if self.detail else None,
+      'traceback': self.traceback,
+      'is_embeddable': request.GET.get('is_embeddable', False)
+    }
+
     if not request.ajax:
       data['request'] = request
     response = desktop.lib.django_util.render("popup_error.mako", request, data)
@@ -62,4 +67,5 @@ class PopupException(Exception):
       response.status_code = 200
     else:
       response.status_code = self.error_code
+
     return response

+ 6 - 3
desktop/core/src/desktop/lib/rest/http_client.py

@@ -32,6 +32,7 @@ from requests.auth import AuthBase ,HTTPBasicAuth, HTTPDigestAuth
 from requests_kerberos import HTTPKerberosAuth, REQUIRED, OPTIONAL, DISABLED
 from urllib3.contrib import pyopenssl
 
+
 pyopenssl.DEFAULT_SSL_CIPHER_LIST = conf.SSL_CIPHER_LIST.get()
 
 __docformat__ = "epytext"
@@ -41,6 +42,7 @@ LOG = logging.getLogger(__name__)
 CACHE_SESSION = {}
 CACHE_SESSION_LOCK = threading.Lock()
 
+
 def get_request_session(url, logger):
   global CACHE_SESSION, CACHE_SESSION_LOCK
 
@@ -53,6 +55,7 @@ def get_request_session(url, logger):
 
   return CACHE_SESSION
 
+
 class RestException(Exception):
   """
   Any error result from the Rest API is converted into this exception type.
@@ -146,7 +149,6 @@ class HttpClient(object):
     self._session.headers.update(headers)
     return self
 
-
   @property
   def base_url(self):
     return self._base_url
@@ -158,7 +160,7 @@ class HttpClient(object):
   def set_verify(self, verify=True):
     self._session.verify = verify
     return self
-      
+
   def _get_headers(self, headers):
     if headers:
       self._session.headers.update(headers)
@@ -227,6 +229,7 @@ class HttpClient(object):
       res += '?' + param_str
     return iri_to_uri(res)
 
+
 class HTTPBearerAuth(AuthBase):
     """Attaches HTTP Basic Authentication to the given Request object."""
 
@@ -241,4 +244,4 @@ class HTTPBearerAuth(AuthBase):
 
     def __call__(self, r):
         r.headers['Authorization'] = 'Bearer %s' % self.token
-        return r
+        return r

+ 2 - 4
desktop/libs/hadoop/src/hadoop/fs/exceptions.py

@@ -21,15 +21,13 @@ import logging
 from desktop.lib.exceptions import StructuredException
 from desktop.lib.rest.http_client import RestException
 
+
 LOG = logging.getLogger(__name__)
 
 
 class PermissionDeniedException(StructuredException):
   def __init__(self, msg, orig_exc=None):
-    # TODO(todd) use orig_exc for something fun
-    StructuredException.__init__(self,
-      "PERMISSION_DENIED",
-      msg)
+    StructuredException.__init__(self,  "PERMISSION_DENIED", msg)
 
 
 class WebHdfsException(RestException):