You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@steve.apache.org by hu...@apache.org on 2025/01/26 11:38:59 UTC

(steve) branch trunk updated (a3a7468 -> ebea9ba)

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a change to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git


    from a3a7468  ES backend fixes
     new a1d7f73  Python 3 compatibility updates
     new a3304ba  update constants.hexdigest to accept other digest methods
     new e6866a7  Add sqlite db backend
     new e2b7b1a  always pickle strings with the JSON marker, since those are fakes
     new 9ea0150  fix .gitignore so it doesn't ignore pysteve/lib
     new ebea9ba  Add poetry dep list

The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .gitignore                        |   2 +-
 pysteve/lib/backends/__init__.py  |   2 +-
 pysteve/lib/backends/sqlite.py    | 296 ++++++++++++++++++++++++++++++++++++++
 pysteve/lib/constants.py          |   6 +-
 pysteve/lib/election.py           |  20 +--
 pysteve/lib/form.py               |   3 +-
 pysteve/lib/plugins/stv.py        |  15 +-
 pysteve/lib/voter.py              |   6 +-
 pysteve/pyproject.toml            |  14 ++
 pysteve/www/cgi-bin/rest_voter.py |   7 +-
 10 files changed, 344 insertions(+), 27 deletions(-)
 create mode 100644 pysteve/lib/backends/sqlite.py
 create mode 100644 pysteve/pyproject.toml


(steve) 01/06: Python 3 compatibility updates

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit a1d7f7357b499f32972a02347cc3bd4fb0af685c
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jan 26 12:24:47 2025 +0100

    Python 3 compatibility updates
    
    - hashlib now only accepts bytestrings, so we'll set up a wrapper in
    constants for auto-converting.
    - izip no longer exists, zip to be used instead
    - fix import paths
    - multipart boundary must be bytestring
    - cmp no longer exists, sorted() now needs a wrapper via functools
---
 pysteve/lib/constants.py          |  6 +++++-
 pysteve/lib/election.py           | 20 ++++++++++----------
 pysteve/lib/form.py               |  3 ++-
 pysteve/lib/plugins/stv.py        | 15 ++++++++-------
 pysteve/lib/voter.py              |  6 +++---
 pysteve/www/cgi-bin/rest_voter.py |  7 ++++---
 6 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/pysteve/lib/constants.py b/pysteve/lib/constants.py
index 4a101bb..402abc1 100644
--- a/pysteve/lib/constants.py
+++ b/pysteve/lib/constants.py
@@ -15,7 +15,7 @@
 # limitations under the License.
 #
 
-
+import hashlib
 VOTE_TYPES = (
     
 )
@@ -24,6 +24,10 @@ DB_TYPES = (
     
 )
 
+def hexdigest(data: str):
+    """Wrapper for hashlib.sha224().hexdigest that handles encoding"""
+    return hashlib.sha224(data.encode("utf-8")).hexdigest()
+
 def appendVote(*types):
     """ Append a new type of voting to the list"""
     global VOTE_TYPES
diff --git a/pysteve/lib/election.py b/pysteve/lib/election.py
index 84a2061..cc3fe36 100644
--- a/pysteve/lib/election.py
+++ b/pysteve/lib/election.py
@@ -19,7 +19,7 @@ import json
 import os
 import random
 import time
-from itertools import izip
+#from itertools import izip
 
 try:
     from __main__ import config
@@ -28,9 +28,9 @@ except:
     config = configparser.RawConfigParser()
     config.read("%s/../../../steve.cfg" % (os.path.dirname(__file__)))
     
-import constants, voter
-from plugins import *
-from backends import *
+from lib import constants, voter
+from lib.plugins import *
+from lib.backends import *
 
 
 
@@ -88,7 +88,7 @@ def createElection(eid, title, owner, monitors, starts, ends, isopen):
             'monitors': monitors,
             'starts': starts,
             'ends': ends,
-            'hash': hashlib.sha512("%f-stv-%s" % (time.time(), os.environ['REMOTE_ADDR'] if 'REMOTE_ADDR' in os.environ else random.randint(1,99999999999))).hexdigest(),
+            'hash': constants.hexdigest("%f-stv-%s" % (time.time(), os.environ['REMOTE_ADDR'] if 'REMOTE_ADDR' in os.environ else random.randint(1,99999999999)), method=hashlib.sha512),
             'open': isopen
         }
     backend.election_create(eid, basedata)
@@ -122,9 +122,9 @@ def vote(electionID, issueID, voterID, vote):
     basedata = getBasedata(electionID)
     issueData = getIssue(electionID, issueID)
     if basedata and issueData:
-        xhash = hashlib.sha224(electionID + ":" + voterID).hexdigest()
-        vhash = hashlib.sha224(xhash + issueID).hexdigest()
-        votehash = hashlib.sha224(basedata['hash'] + issueID + voterID + vote).hexdigest()
+        xhash = constants.hexdigest(electionID + ":" + voterID)
+        vhash = constants.hexdigest(xhash + issueID)
+        votehash = constants.hexdigest(basedata['hash'] + issueID + voterID + vote)
         
         # Vote verification
         voteType = getVoteType(issueData)
@@ -182,10 +182,10 @@ def getHash(electionID):
         votes = getVotes(electionID, issue)
         ihash += issuedata['hash']
         output.append("Issue #%s: %s\n- Checksum: %s\n- Votes cast: %u\n" % (issue, issuedata['title'], issuedata['hash'], len(votes)))
-    tothash = hashlib.sha224(ihash).hexdigest()
+    tothash = constants.hexdigest(ihash)
     output.insert(0, ("You are receiving this data because you are listed as a monitor for this election.\nThe following data shows the state of the election data on disk. If any of these checksums change, especially the main checksum, then the election has been edited (rigged?) after invites were sent out.\n\nMain Election Checksum : %s\n\n" % tothash))
     output.append("\nYou can monitor votes and recasts online at: %s/monitor.html?%s" % (config.get("general", "rooturl"), electionID))
     return tothash, "\n".join(output)
 
 def createIssue(electionID, issueID, data):
-    backend.issue_create(electionID, issueID, data)
\ No newline at end of file
+    backend.issue_create(electionID, issueID, data)
diff --git a/pysteve/lib/form.py b/pysteve/lib/form.py
index 9b0520f..31ce381 100644
--- a/pysteve/lib/form.py
+++ b/pysteve/lib/form.py
@@ -19,7 +19,8 @@ import cgi
 
 ctype, pdict = cgi.parse_header(os.environ['CONTENT_TYPE'] if 'CONTENT_TYPE' in os.environ else "")
 if ctype == 'multipart/form-data':
-    xform = cgi.parse_multipart(sys.stdin, pdict)
+    pdict['boundary'] = bytes(pdict['boundary'], "utf-8")
+    xform = cgi.parse_multipart(sys.stdin, pdict, encoding="utf-8")
 else:
     xform = cgi.FieldStorage();
 
diff --git a/pysteve/lib/plugins/stv.py b/pysteve/lib/plugins/stv.py
index af74e54..3807790 100644
--- a/pysteve/lib/plugins/stv.py
+++ b/pysteve/lib/plugins/stv.py
@@ -27,6 +27,7 @@ BILLIONTH = 0.000000001
 
 
 from lib import constants
+import functools
 
 debug = []
 
@@ -137,7 +138,7 @@ class CandidateList(object):
 
   def print_results(self):
     for c in self.l:
-      print '%-40s%selected' % (c.name, c.status == ELECTED and ' ' or ' not ')
+      print ('%-40s%selected' % (c.name, c.status == ELECTED and ' ' or ' not '))
 
   def dbg_display_tables(self, excess):
     total = excess
@@ -147,7 +148,6 @@ class CandidateList(object):
     debug.append('%-20s %15s %15.9f' %( 'Non-transferable', ' ', excess))
     debug.append('%-20s %15s %15.9f' % ( 'Total', ' ', total))
 
-
 class Candidate(object):
   def __init__(self, name, rand, ahead):
     self.name = name
@@ -170,11 +170,12 @@ class Candidate(object):
     assert quota is not None
     self.weight = (self.weight * quota) / self.vote
 
-  def __cmp__(self, other):
-    if self.ahead < other.ahead:
+  @staticmethod
+  def cmp(a,b):
+    if a.ahead < b.ahead:
       return -1
-    if self.ahead == other.ahead:
-      return cmp(self.vote, other.vote)
+    if a.ahead == b.ahead:
+        return (a.vote > b.vote) - (a.vote < b.vote)
     return 1
 
 
@@ -227,7 +228,7 @@ def calc_totals(votes, candidates):
 
 
 def calc_aheads(candidates):
-  c_sorted = sorted(candidates.l)
+  c_sorted = sorted(candidates.l, key=functools.cmp_to_key(Candidate.cmp))
   last = 0
   for i in range(1, len(c_sorted)+1):
     if i == len(c_sorted) or c_sorted[last] != c_sorted[i]:
diff --git a/pysteve/lib/voter.py b/pysteve/lib/voter.py
index dbc7242..e6007c6 100644
--- a/pysteve/lib/voter.py
+++ b/pysteve/lib/voter.py
@@ -33,13 +33,13 @@ from lib import constants, election
 backend = constants.initBackend(config)
 
 def get(election, basedata, uid):
-    xhash = hashlib.sha512(basedata['hash'] + uid).hexdigest()
+    xhash = constants.hexdigest(basedata['hash'] + uid, method=hashlib.sha512)
     return backend.voter_get_uid(election, xhash)
     
     
 def add(election, basedata, PID):
-    uid = hashlib.sha224("%s%s%s%s" % (PID, basedata['hash'], time.time(), random.randint(1,99999999))).hexdigest()
-    xhash = hashlib.sha512(basedata['hash'] + uid).hexdigest()
+    uid = constants.hexdigest("%s%s%s%s" % (PID, basedata['hash'], time.time(), random.randint(1,99999999)))
+    xhash = constants.hexdigest(basedata['hash'] + uid, method=hashlib.sha512)
     backend.voter_add(election, PID, xhash)
     return uid, xhash
     
diff --git a/pysteve/www/cgi-bin/rest_voter.py b/pysteve/www/cgi-bin/rest_voter.py
index 7b2fb12..ae951cb 100755
--- a/pysteve/www/cgi-bin/rest_voter.py
+++ b/pysteve/www/cgi-bin/rest_voter.py
@@ -36,11 +36,12 @@ if 'SCRIPT_FILENAME' in os.environ:
 config = configparser.RawConfigParser()
 config.read(path + '/../../steve.cfg')
 
+
 # Some quick paths
 homedir = config.get("general", "homedir")
 pathinfo = os.environ['PATH_INFO'] if 'PATH_INFO' in os.environ else None
 
-from lib import response, voter, election, form
+from lib import response, voter, election, form, constants
 
 
 whoami = os.environ['REMOTE_USER'] if 'REMOTE_USER' in os.environ else None
@@ -145,7 +146,7 @@ if pathinfo:
                             response.respond(500, {'message': invalid})
                         else:
                             votehash = election.vote(electionID, issueID, voterID, vote)
-                            voteuid = hashlib.sha224(voterID).hexdigest()
+                            voteuid = constants.hexdigest(voterID)
                             # Catch proxy-emails
                             m = re.match(r"^(.+@.*?[a-zA-Z])-[^.]+$", email)
                             if m:
@@ -198,4 +199,4 @@ if pathinfo:
     else:
         response.respond(400, {'message': 'Invalid action supplied'})
 else:
-    response.respond(500, {'message': 'No path info supplied, aborting'})
\ No newline at end of file
+    response.respond(500, {'message': 'No path info supplied, aborting'})


(steve) 05/06: fix .gitignore so it doesn't ignore pysteve/lib

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit 9ea0150d594e1ecddc05831730641613b12e6f3d
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jan 26 12:36:45 2025 +0100

    fix .gitignore so it doesn't ignore pysteve/lib
---
 .gitignore | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index 4e99796..00fdff7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -18,7 +18,7 @@ docs/_build
 dropin.cache
 eggs/
 include/
-lib/
+/lib/
 man/
 parts/
 share/


(steve) 03/06: Add sqlite db backend

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit e6866a71fbfb2a6935f77d387d3c2dfb51bc796f
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jan 26 12:33:03 2025 +0100

    Add sqlite db backend
---
 pysteve/lib/backends/__init__.py |   2 +-
 pysteve/lib/backends/sqlite.py   | 296 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 297 insertions(+), 1 deletion(-)

diff --git a/pysteve/lib/backends/__init__.py b/pysteve/lib/backends/__init__.py
index 6f9f024..247e11c 100644
--- a/pysteve/lib/backends/__init__.py
+++ b/pysteve/lib/backends/__init__.py
@@ -16,4 +16,4 @@
 #
 """Database backends"""
 
-__all__ = ['files','es']
\ No newline at end of file
+__all__ = ['files','es', 'sqlite']
\ No newline at end of file
diff --git a/pysteve/lib/backends/sqlite.py b/pysteve/lib/backends/sqlite.py
new file mode 100644
index 0000000..e62c798
--- /dev/null
+++ b/pysteve/lib/backends/sqlite.py
@@ -0,0 +1,296 @@
+#
+# 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 hashlib
+import json
+import time
+from lib import constants
+import asfpy.sqlite
+
+"""SQLite database wrapper for STeVe v2 (PySTeVe)"""
+
+DB_CREATE_STATEMENTS = (
+    """
+CREATE TABLE "elections" (
+    "id"	TEXT PRIMARY KEY UNIQUE,
+    "title"	TEXT NOT NULL,
+    "owner"	TEXT NOT NULL,
+    "monitors"	TEXT NOT NULL,
+    "starts"	INTEGER,
+    "ends"	INTEGER,
+    "hash"	TEXT NOT NULL,
+    "open"	TEXT NOT NULL,
+    "closed" INTEGER
+);""",
+    """
+CREATE TABLE "issues" (
+    "id"	TEXT PRIMARY KEY UNIQUE,
+    "election" TEXT NOT NULL,
+    "title"	TEXT NOT NULL,
+    "description"	TEXT NOT NULL,
+    "type"	TEXT NOT NULL,
+    "candidates"	TEXT,
+    "seconds"	TEXT,
+    "nominatedby"	TEXT
+);""",
+    """
+CREATE TABLE "votes" (
+    "eid"	TEXT PRIMARY KEY UNIQUE,
+    "issue" TEXT NOT NULL,
+    "election" TEXT NOT NULL,
+    "key"	TEXT NOT NULL,
+    "data"	TEXT NOT NULL
+);""",
+    """
+CREATE TABLE "voters" (
+    "id"	TEXT PRIMARY KEY UNIQUE,
+    "election" TEXT NOT NULL,
+    "hash"	TEXT NOT NULL,
+    "uid"	TEXT NOT NULL
+);""",
+    """
+CREATE TABLE "vote_history" (
+    "id"	INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,
+    "eid"   TEXT NOT NULL,
+    "issue" TEXT NOT NULL,
+    "election" TEXT NOT NULL,
+    "key"	TEXT NOT NULL,
+    "data"	TEXT NOT NULL
+);
+""",
+)
+
+
+class SteveSQLite(object):
+    def __init__(self, config):
+        self.config = config
+        self.dbname = config.get("sqlite", "database")
+        self.db = asfpy.sqlite.DB(self.dbname)
+        if not self.db.table_exists("elections"):
+            for stmt in DB_CREATE_STATEMENTS:
+                self.db.runc(stmt)
+
+
+def pickle(doc: dict):
+    ndoc = {}
+    for k, v in doc.items():
+        if isinstance(v, list) or isinstance(v, dict):
+            v = "%JSON%:" + json.dumps(v)
+        ndoc[k] = v
+    return ndoc
+
+
+def unpickle(doc: dict):
+    ndoc = {}
+    for k, v in doc.items():
+        if isinstance(v, str) and v.startswith("%JSON%:"):
+            try:
+                v = json.loads(v[7:])
+            except json.JSONDecodeError:
+                pass
+        ndoc[k] = v
+    return ndoc
+
+
+class SQLiteBackend:
+
+    def __init__(self, config):
+        "Init - get config and turn it into an ES instance"
+        self.DB = SteveSQLite(config)
+
+    def document_exists(self, election, *issue):
+        "Does this election or issue exist?"
+        eid = election
+        if issue and issue[0]:
+            return self.DB.db.fetchone("issues", election=election, id=issue[0])
+        return self.DB.db.fetchone("elections", id=eid)
+
+    def get_basedata(self, election):
+        "Get base data from an election"
+        res = self.DB.db.fetchone("elections", id=election)
+        if res:
+            return unpickle(res)
+
+    def close(self, election, reopen=False):
+        "Mark an election as closed"
+        basedata = self.get_basedata(election)
+        if reopen == True:
+            basedata["closed"] = 0
+        else:
+            basedata["closed"] = 1
+        self.DB.db.update("elections", pickle(basedata), id=election)
+
+    def issue_get(self, electionID, issueID):
+        "Get JSON data from an issue"
+        issuedata = None
+        ihash = ""
+        res = self.DB.db.fetchone("issues", id=issueID, election=electionID)
+        if res:
+            issuedata = unpickle(res)
+            ihash = constants.hexdigest(json.dumps(issuedata))
+        return issuedata, ihash
+
+    def votes_get(self, electionID, issueID):
+        "Read votes and return as a dict"
+        res = [unpickle(x) for x in self.DB.db.fetch("votes", limit=None, election=electionID, issue=issueID)]
+        if res:
+            votes = {}
+            for entry in res:
+                votes[entry["key"]] = entry["data"]["vote"]
+            return votes
+        return {}
+
+    def votes_get_raw(self, electionID, issueID):
+        "Read votes and return raw format"
+        res = [unpickle(x) for x in self.DB.db.fetch("votes", limit=None, election=electionID, issue=issueID)]
+        if res:
+            votes = []
+            for entry in res:
+                votes.append(entry)
+            return votes
+        return {}
+
+    def vote_history(self, electionID, issueID):
+        "Read vote history and return raw format"
+        res = [unpickle(x) for x in self.DB.db.fetch("vote_history", limit=None, election=electionID, issue=issueID)]
+        if res:
+            votes = []
+            for entry in res:
+                votes.append(entry)
+            return votes
+        return []
+
+    def election_create(self, _electionid, basedata):
+        """Create a new election"""
+
+        self.DB.db.insert("elections", pickle(basedata))
+
+    def election_update(self, electionID, basedata):
+        "Update an election with new data"
+        self.DB.db.update("elections", pickle(basedata), id=electionID)
+
+    def issue_update(self, electionID, issueID, issueData):
+        "Update an issue with new data"
+        self.DB.db.update("issues", issueData, id=issueID, election=electionID)
+
+    def issue_list(self, election):
+        "List all issues in an election"
+        issues = [x["id"] for x in self.DB.db.fetch("issues", limit=None, election=election)]
+        return issues
+
+    def election_list(self):
+        "List all elections"
+        elections = [x for x in self.DB.db.fetch("elections", limit=None)]
+        return elections
+
+    def vote(self, electionID, issueID, uid, vote, vhash=None):
+        "Casts a vote on an issue"
+        eid = constants.hexdigest(electionID + ":" + issueID + ":" + uid)
+        now = time.time()
+        if vhash:
+            eid = vhash
+        doc = pickle(
+            {"eid": eid, "issue": issueID, "election": electionID, "key": uid, "data": {"timestamp": now, "vote": vote}}
+        )
+        self.DB.db.upsert("votes", doc, eid=eid)
+        self.DB.db.insert("vote_history", doc)
+
+    def issue_delete(self, electionID, issueID):
+        "Deletes an issue if it exists"
+        self.DB.db.delete("issues", election=electionID, id=issueID)
+
+    def issue_create(self, electionID, issueID, data):
+        "Create an issue"
+        # iid = hashlib.sha224((electionID + "/" + issueID).encode("utf-8")).hexdigest()
+        self.DB.db.insert("issues", pickle(data))
+
+    def voter_get_uid(self, electionID, votekey):
+        "Get the UID/email for a voter given the vote key hash"
+        # First, try the raw hash as an ID
+        try:
+            res = self.DB.db.fetchone("voters", id=votekey)
+            if res:
+                return res
+        except:
+            pass
+
+        # Now, look for it as hash inside the doc
+        try:
+            res = [pickle(x) for x in self.DB.db.fetch("voters", limit=100, election=electionID)]
+            if res:
+                for entry in res:
+                    if entry["hash"] == votekey:
+                        return entry["uid"]
+        except:
+            return False  # ES Error, probably not seeded the voters doc yet
+
+    def voter_add(self, election, PID, xhash):
+        "Add a voter to the DB"
+        eid = constants.hexdigest(election + ":" + PID)
+        doc = pickle({"id": eid, "election": election, "hash": xhash, "uid": PID})
+        self.DB.db.upsert("voters", doc, id=eid)
+
+    def ballot_scrub(self, election, xhash, uid=None):
+        "Scrub a ballot"
+        if uid:
+            xhash = hashlib.sha224(election + ":" + uid).hexdigest()
+
+        # Find ballots and votes matching
+        bid = self.voter_get_uid(election, xhash)
+        if not bid:
+            return None
+        issues = self.issue_list(election)
+        for issue in issues:
+            vhash = hashlib.sha224(xhash + issue).hexdigest()
+            try:
+                self.DB.db.delete("votes", eid=vhash)
+            except:
+                pass
+        return True
+
+    def voter_remove(self, election, UID):
+        "Remove the voter with the given UID"
+        votehash = constants.hexdigest(election + ":" + UID)
+        self.DB.db.delete("voters", id=votehash)
+
+    def voter_has_voted(self, election, issue, uid):
+        "Return true if the voter has voted on this issue, otherwise false"
+        eid = constants.hexdigest(election + ":" + issue + ":" + uid)
+        try:
+            return self.DB.db.fetchone(doc_type="votes", id=eid)
+        except:
+            return False
+
+    def voter_ballots(self, UID):
+        """Find all elections (and ballots) this user has participated in"""
+
+        # First, get all elections
+        elections = {}
+
+        res = [unpickle(x) for x in self.DB.db.fetch("elections", limit=None)]
+        for election in res:
+            # Mark election open or closed
+            elections[election["id"]] = {"title": election["title"], "open": False if election["closed"] else True}
+
+        # Then, get all ballots and note whether they still apply or not
+        ballots = {}
+        res = [pickle(x) for x in self.DB.db.fetch("voters", limit=100, uid=UID)]
+        for ballot in res:
+            ballots[ballot["election"]] = {"ballot": ballot["id"], "metadata": elections[ballot["election"]]}
+        return ballots
+
+
+constants.appendBackend("sqlite", SQLiteBackend)


(steve) 02/06: update constants.hexdigest to accept other digest methods

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit a3304ba2d7edda9ee13f1c4f7c9ac7de260f3629
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jan 26 12:25:21 2025 +0100

    update constants.hexdigest to accept other digest methods
    
    oops, forgot
---
 pysteve/lib/constants.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/pysteve/lib/constants.py b/pysteve/lib/constants.py
index 402abc1..db0ec52 100644
--- a/pysteve/lib/constants.py
+++ b/pysteve/lib/constants.py
@@ -24,9 +24,9 @@ DB_TYPES = (
     
 )
 
-def hexdigest(data: str):
+def hexdigest(data: str, method=hashlib.sha224):
     """Wrapper for hashlib.sha224().hexdigest that handles encoding"""
-    return hashlib.sha224(data.encode("utf-8")).hexdigest()
+    return method(data.encode("utf-8")).hexdigest()
 
 def appendVote(*types):
     """ Append a new type of voting to the list"""


(steve) 04/06: always pickle strings with the JSON marker, since those are fakes

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit e2b7b1aa93b2fa1aa474019031d6763cc5abcaf9
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jan 26 12:34:29 2025 +0100

    always pickle strings with the JSON marker, since those are fakes
---
 pysteve/lib/backends/sqlite.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pysteve/lib/backends/sqlite.py b/pysteve/lib/backends/sqlite.py
index e62c798..f0ef382 100644
--- a/pysteve/lib/backends/sqlite.py
+++ b/pysteve/lib/backends/sqlite.py
@@ -87,7 +87,7 @@ class SteveSQLite(object):
 def pickle(doc: dict):
     ndoc = {}
     for k, v in doc.items():
-        if isinstance(v, list) or isinstance(v, dict):
+        if isinstance(v, list) or isinstance(v, dict) or (isinstance(v, str) and v.startswith("%JSON%:")):
             v = "%JSON%:" + json.dumps(v)
         ndoc[k] = v
     return ndoc


(steve) 06/06: Add poetry dep list

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/steve.git

commit ebea9bacb36fc042e1723afad1c82479e9932b2a
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Jan 26 12:38:26 2025 +0100

    Add poetry dep list
---
 pysteve/pyproject.toml | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/pysteve/pyproject.toml b/pysteve/pyproject.toml
new file mode 100644
index 0000000..41309bc
--- /dev/null
+++ b/pysteve/pyproject.toml
@@ -0,0 +1,14 @@
+[tool.poetry]
+name = "steve"
+version = "0.1.0"
+description = ""
+authors = ["Apache STeVe <de...@steve.apache.org>"]
+readme = "README.md"
+
+[tool.poetry.dependencies]
+python = "^3.12"
+asfpy = "0.52"
+
+[build-system]
+requires = ["poetry-core"]
+build-backend = "poetry.core.masonry.api"