[Git][security-tracker-team/security-tracker][master] 2 commits: tracker_service: use with statement

Emilio Pozuelo Monfort pochu at debian.org
Tue Aug 11 17:51:26 BST 2020



Emilio Pozuelo Monfort pushed to branch master at Debian Security Tracker / security-tracker


Commits:
aeee948d by Emilio Pozuelo Monfort at 2020-08-11T18:44:01+02:00
tracker_service: use with statement

- - - - -
b7bd87bd by Emilio Pozuelo Monfort at 2020-08-11T18:48:33+02:00
tracker_service: don't crash on /source-package/

If no source package is given, return a 404 error.

- - - - -


1 changed file:

- bin/tracker_service.py


Changes:

=====================================
bin/tracker_service.py
=====================================
@@ -186,28 +186,24 @@ class TrackerService(webservice_base_class):
         self.register('script.js', self.page_script_js)
 
     def page_style_css(self, path, params, url):
-        f=open('../static/style.css', 'r')
-        content=f.read()
-        f.close()
-        return BinaryResult(content,'text/css')
+        with open('../static/style.css', 'r') as f:
+            content=f.read()
+            return BinaryResult(content,'text/css')
 
     def page_logo_png(self, path, params, url):
-        f=open('../static/logo.png', 'rb')
-        content=f.read()
-        f.close()
-        return BinaryResult(content,'image/png')
+        with open('../static/logo.png', 'rb') as f:
+            content=f.read()
+            return BinaryResult(content,'image/png')
 
     def page_distributions_json(self, path, params, url):
-        f=open('../static/distributions.json', 'r')
-        content=f.read()
-        f.close()
-        return BinaryResult(content,'application/json')
+        with open('../static/distributions.json', 'r') as f:
+            content=f.read()
+            return BinaryResult(content,'application/json')
 
     def page_script_js(self, path, params, url):
-        f=open('../static/script.js', 'r')
-        content=f.read()
-        f.close()
-        return BinaryResult(content,'text/javascript')
+        with open('../static/script.js', 'r') as f:
+            content=f.read()
+            return BinaryResult(content,'text/javascript')
 
 
     def page_home(self, path, params, url):
@@ -619,6 +615,12 @@ question about how things work, don't be afraid to ask, we would like
 to improve our documentation and procedures, so feedback is welcome.""")])])
 
     def page_source_package(self, path, params, url):
+        if path == ():
+            return self.create_page(
+                url, "Object not found",
+                [P("No source package was provided.")],
+                status=404)
+
         pkg = path[0]
         data = security_db.getBugsForSourcePackage(self.db.cursor(), pkg)
 



View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/-/compare/6ee5cd6be5a18a1753aabfaa10ead6d3f6c8a9c5...b7bd87bd614f7e0bed2de4fb68c6f58d27c80959

-- 
View it on GitLab: https://salsa.debian.org/security-tracker-team/security-tracker/-/compare/6ee5cd6be5a18a1753aabfaa10ead6d3f6c8a9c5...b7bd87bd614f7e0bed2de4fb68c6f58d27c80959
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-security-tracker-commits/attachments/20200811/71f8999f/attachment-0001.html>


More information about the debian-security-tracker-commits mailing list