2626
2727
2828# extract error from the <PRE> tag inside the HTML response
29- HTML_ERROR = re .compile (' <pre>\s*(.*?)\s*</pre>' , re .IGNORECASE )
29+ HTML_ERROR = re .compile (" <pre>\\ s*(.*?)\\ s*</pre>" , re .IGNORECASE )
3030
3131
3232class BaseDruidClient (object ):
@@ -49,16 +49,16 @@ def set_proxies(self, proxies):
4949 urllib .request .install_opener (opener )
5050
5151 def _prepare_url_headers_and_body (self , query ):
52- querystr = json .dumps (query .query_dict ).encode (' utf-8' )
53- if self .url .endswith ('/' ):
52+ querystr = json .dumps (query .query_dict ).encode (" utf-8" )
53+ if self .url .endswith ("/" ):
5454 url = self .url + self .endpoint
5555 else :
56- url = self .url + '/' + self .endpoint
57- headers = {' Content-Type' : ' application/json' }
56+ url = self .url + "/" + self .endpoint
57+ headers = {" Content-Type" : " application/json" }
5858 if (self .username is not None ) and (self .password is not None ):
59- authstring = ' {}:{}' .format (self .username , self .password )
59+ authstring = " {}:{}" .format (self .username , self .password )
6060 b64string = b64encode (authstring .encode ()).decode ()
61- headers [' Authorization' ] = ' Basic {}' .format (b64string )
61+ headers [" Authorization" ] = " Basic {}" .format (b64string )
6262
6363 return headers , querystr , url
6464
@@ -449,7 +449,8 @@ def export_tsv(self, dest_path):
449449 """
450450 if self .query_builder .last_query is None :
451451 raise AttributeError (
452- "There was no query executed by this client yet. Can't export!" )
452+ "There was no query executed by this client yet. Can't export!"
453+ )
453454 else :
454455 return self .query_builder .last_query .export_tsv (dest_path )
455456
@@ -462,7 +463,8 @@ def export_pandas(self):
462463 """
463464 if self .query_builder .last_query is None :
464465 raise AttributeError (
465- "There was no query executed by this client yet. Can't export!" )
466+ "There was no query executed by this client yet. Can't export!"
467+ )
466468 else :
467469 return self .query_builder .last_query .export_pandas ()
468470
@@ -539,6 +541,7 @@ class PyDruid(BaseDruidClient):
539541 0 7 2013-10-04T00:00:00.000Z user_1
540542 1 6 2013-10-04T00:00:00.000Z user_2
541543 """
544+
542545 def __init__ (self , url , endpoint ):
543546 super (PyDruid , self ).__init__ (url , endpoint )
544547
@@ -561,12 +564,18 @@ def _post(self, query):
561564 except (ValueError , AttributeError , KeyError ):
562565 pass
563566
564- raise IOError ('{0} \n Druid Error: {1} \n Query is: {2}' .format (
565- e , err , json .dumps (
567+ raise IOError (
568+ "{0} \n Druid Error: {1} \n Query is: {2}" .format (
569+ e ,
570+ err ,
571+ json .dumps (
566572 query .query_dict ,
567573 indent = 4 ,
568574 sort_keys = True ,
569- separators = (',' , ': ' ))))
575+ separators = ("," , ": " ),
576+ ),
577+ )
578+ )
570579 else :
571580 query .parse (data )
572581 return query
0 commit comments