From 9679d119f5da15e6f73720616dc8590e34bcd06b Mon Sep 17 00:00:00 2001 From: Andrew Davidson Date: Mon, 12 Mar 2012 20:23:22 -0700 Subject: [PATCH] adding link to del code and cleaning up some comments --- mysecrets.py | 43 +++++++++++++++++++++++++++++++++++-------- templates/page.html | 7 +++++-- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/mysecrets.py b/mysecrets.py index f2b8238..add4314 100755 --- a/mysecrets.py +++ b/mysecrets.py @@ -27,6 +27,21 @@ create = form.Form( form.Password('password'), ) +def trash(id): + if db.select('passwords', where='id = "'+id+'"'): + + if not db.select('trash', where='id = "'+id+'"'): + db.query('INSERT INTO trash SELECT * FROM passwords WHERE id = "'+id+'"') + + orig = db.select('passwords', where='id = "'+id+'"')[0] + new = db.select('trash', where='id = "'+id+'"')[0] + + if orig == new: + db.delete('passwords', where='id = "'+id+'"') + return True; + + return False; + def get_domain(base_url): with closing(urlopen('https://mxr.mozilla.org/mozilla/source/netwerk/dns/src/effective_tld_names.dat?raw=1')) as tldFile: tlds = [line.strip() for line in tldFile if line[0] not in "/\n"] @@ -35,12 +50,9 @@ def get_domain(base_url): for i in range(-len(urlElements),0): lastIElements = urlElements[i:] - # i=-3: ["abcde","co","uk"] - # i=-2: ["co","uk"] - # i=-1: ["uk"] etc - - candidate = ".".join(lastIElements) # abcde.co.uk, co.uk, uk - wildcardCandidate = ".".join(["*"]+lastIElements[1:]) # *.co.uk, *.uk, * + + candidate = ".".join(lastIElements) + wildcardCandidate = ".".join(["*"]+lastIElements[1:]) exceptionCandidate = "!"+candidate if (exceptionCandidate in tlds): @@ -49,7 +61,6 @@ def get_domain(base_url): return ".".join(urlElements[i-1:]) return base_url - def mkpass(size=10): validChars = string.ascii_letters + string.digits @@ -73,6 +84,20 @@ def get_generated_from_url(domain): class index: def GET(self, method): + if method == 'del': + i = web.input() + + result = trash(i.id) + + if result: + body = "id: " + i.id + " deleted." + + if not result: + body = "id: " + i.id + " not deleted." + + return render.page('Deleted ' + i.id, body) + + if method == 'new': i = web.input() @@ -91,7 +116,9 @@ class index: if selected: body.append('

Existing:

\n') body.append('

Suggested:

\n

' + generated[0].password + '

\n') diff --git a/templates/page.html b/templates/page.html index c1053e4..27911ab 100644 --- a/templates/page.html +++ b/templates/page.html @@ -29,7 +29,6 @@ $def with (title, body) font: inherit; vertical-align: baseline; } - /* HTML5 display-role reset for older browsers */ article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section { display: block; @@ -60,7 +59,6 @@ $def with (title, body)