[tor-commits] [stem/master] Enforce read-only usage of manual database

atagar at torproject.org atagar at torproject.org
Mon Feb 10 03:14:50 UTC 2020


commit a8296d6071a253b4f2265b651b6d5b5c455278e7
Author: Damian Johnson <atagar at torproject.org>
Date:   Sun Feb 9 18:58:59 2020 -0800

    Enforce read-only usage of manual database
    
    Now that we're using python 3.x our sqlite module's uri mode can allow us to
    open our cache in a read-only manner...
    
      https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
---
 stem/manual.py | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/stem/manual.py b/stem/manual.py
index c1b4bd8f..1a0816c8 100644
--- a/stem/manual.py
+++ b/stem/manual.py
@@ -142,16 +142,11 @@ def query(query, *param):
   # The only reason to explicitly close the sqlite connection is to ensure
   # transactions are committed. Since we're only using read-only access this
   # doesn't matter, and can allow interpreter shutdown to do the needful.
-  #
-  # TODO: When we only support python 3.4+ we can use sqlite's uri argument
-  # to enforce a read-only connection...
-  #
-  #   https://docs.python.org/3/library/sqlite3.html#sqlite3.connect
 
   global DATABASE
 
   if DATABASE is None:
-    DATABASE = sqlite3.connect(CACHE_PATH)
+    DATABASE = sqlite3.connect('file:%s?mode=ro' % CACHE_PATH, uri=True)
 
   return DATABASE.execute(query, param)
 





More information about the tor-commits mailing list