github-code-scanning[bot] commented on code in PR #13787:
URL: https://github.com/apache/druid/pull/13787#discussion_r1118025338


##########
examples/quickstart/jupyter-notebooks/druidapi/display.py:
##########
@@ -0,0 +1,65 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TEXT_TABLE = 0
+HTML_TABLE = 1
+
+class Display:
+
+    def __init__(self):
+        self.format = TEXT_TABLE
+        self.html_initialized = False
+
+    def text(self):
+        self.format = TEXT_TABLE
+
+    def html(self):
+        self.format = HTML_TABLE
+        if not self.html_initialized:
+            from .html_table import styles
+            styles()
+            self.html_initialized = True
+    
+    def table(self):
+        if self.format == HTML_TABLE:
+            from .html_table import HtmlTable
+            return HtmlTable()
+        else:
+            from .text_table import TextTable
+            return TextTable()
+    
+    def show_object_list(self, objects, cols):
+        list_to_table(self.table(), objects, cols)
+
+    def show_object(self, obj, labels):
+        object_to_table(self.table(), obj, labels)
+
+    def show_error(self, msg):
+        from .html_table import html_error
+        html_error('<b>ERROR: ' + msg + '</b>')
+    
+    def show_message(self, msg):
+        from .html_table import html
+        html('<b>' + msg + '</b>')
+
+def list_to_table(table, objects, cols = None):
+    table.from_object_list(objects, cols)
+    return table.show()

Review Comment:
   ## Wrong number of arguments in a call
   
   Call to [method HtmlTable.show](1) with too few arguments; should be no 
fewer than 1.
   Call to [method TextTable.show](2) with too few arguments; should be no 
fewer than 1.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4359)



##########
examples/quickstart/jupyter-notebooks/druidapi/rest.py:
##########
@@ -0,0 +1,266 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import requests
+from .util import dict_get
+from urllib.parse import quote
+from .error import ClientError
+
+def check_error(response):
+    '''
+    Raises an HttpError from the requests library if the response code is 
neither
+    OK (200) nor Accepted (202).
+
+    Druid's REST API is inconsistent with how it resports errors. Some APIs 
return
+    an error as a JSON object. Others return a text message. Still others 
return
+    nothing at all. With the JSON format, sometimes the error returns an
+    'errorMessage' field, other times only a generic 'error' field.
+
+    This method attempts to parse these variations. If the error response JSON
+    matches one of the known error formats, then raises a `ClientError` with 
the error
+    message. Otherise, raises a Requests library `HTTPError` for a generic 
error.
+    If the response includes a JSON payload, then the it is returned in the 
json field 
+    of the `HTTPError` object so that the client can perhaps decode it.
+    '''
+    code = response.status_code
+    if code == requests.codes.ok or code == requests.codes.accepted:
+        return
+    error = None

Review Comment:
   ## Unused local variable
   
   Variable error is not used.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4358)



##########
examples/quickstart/jupyter-notebooks/druidapi/display.py:
##########
@@ -0,0 +1,65 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+TEXT_TABLE = 0
+HTML_TABLE = 1
+
+class Display:
+
+    def __init__(self):
+        self.format = TEXT_TABLE
+        self.html_initialized = False
+
+    def text(self):
+        self.format = TEXT_TABLE
+
+    def html(self):
+        self.format = HTML_TABLE
+        if not self.html_initialized:
+            from .html_table import styles
+            styles()
+            self.html_initialized = True
+    
+    def table(self):
+        if self.format == HTML_TABLE:
+            from .html_table import HtmlTable
+            return HtmlTable()
+        else:
+            from .text_table import TextTable
+            return TextTable()
+    
+    def show_object_list(self, objects, cols):
+        list_to_table(self.table(), objects, cols)
+
+    def show_object(self, obj, labels):
+        object_to_table(self.table(), obj, labels)
+
+    def show_error(self, msg):
+        from .html_table import html_error
+        html_error('<b>ERROR: ' + msg + '</b>')
+    
+    def show_message(self, msg):
+        from .html_table import html
+        html('<b>' + msg + '</b>')
+
+def list_to_table(table, objects, cols = None):
+    table.from_object_list(objects, cols)
+    return table.show()
+
+def object_to_table(table, obj, labels):
+    table.from_object(obj, labels)
+    table.show()

Review Comment:
   ## Wrong number of arguments in a call
   
   Call to [method HtmlTable.show](1) with too few arguments; should be no 
fewer than 1.
   Call to [method TextTable.show](2) with too few arguments; should be no 
fewer than 1.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/4360)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to