Change to Python3 coding style
This commit is contained in:
parent
fc0fe0557b
commit
b0b9a4d33c
137 changed files with 910 additions and 913 deletions
|
@ -88,8 +88,8 @@ class ContentDbPlugin(object):
|
|||
site_sizes[row["site_id"]]["optional_downloaded"] += row["size"]
|
||||
|
||||
# Site site size stats to sites.json settings
|
||||
site_ids_reverse = {val: key for key, val in self.site_ids.iteritems()}
|
||||
for site_id, stats in site_sizes.iteritems():
|
||||
site_ids_reverse = {val: key for key, val in self.site_ids.items()}
|
||||
for site_id, stats in site_sizes.items():
|
||||
site_address = site_ids_reverse.get(site_id)
|
||||
if not site_address:
|
||||
self.log.error("Not found site_id: %s" % site_id)
|
||||
|
@ -166,7 +166,7 @@ class ContentDbPlugin(object):
|
|||
num = 0
|
||||
site_id = self.site_ids[site.address]
|
||||
content_inner_dir = helper.getDirname(content_inner_path)
|
||||
for relative_inner_path, file in content.get("files_optional", {}).iteritems():
|
||||
for relative_inner_path, file in content.get("files_optional", {}).items():
|
||||
file_inner_path = content_inner_dir + relative_inner_path
|
||||
hash_id = int(file["sha512"][0:4], 16)
|
||||
if hash_id in site.content_manager.hashfield:
|
||||
|
@ -232,14 +232,14 @@ class ContentDbPlugin(object):
|
|||
num_file = 0
|
||||
num_updated = 0
|
||||
num_site = 0
|
||||
for site in self.sites.values():
|
||||
for site in list(self.sites.values()):
|
||||
if not site.content_manager.has_optional_files:
|
||||
continue
|
||||
if not site.settings["serving"]:
|
||||
continue
|
||||
has_updated_hashfield = next((
|
||||
peer
|
||||
for peer in site.peers.itervalues()
|
||||
for peer in site.peers.values()
|
||||
if peer.has_hashfield and peer.hashfield.time_changed > self.time_peer_numbers_updated
|
||||
), None)
|
||||
|
||||
|
@ -248,7 +248,7 @@ class ContentDbPlugin(object):
|
|||
|
||||
hashfield_peers = itertools.chain.from_iterable(
|
||||
peer.hashfield.storage
|
||||
for peer in site.peers.itervalues()
|
||||
for peer in site.peers.values()
|
||||
if peer.has_hashfield
|
||||
)
|
||||
peer_nums = collections.Counter(
|
||||
|
@ -270,7 +270,7 @@ class ContentDbPlugin(object):
|
|||
updates[row["file_id"]] = peer_num
|
||||
|
||||
self.execute("BEGIN")
|
||||
for file_id, peer_num in updates.iteritems():
|
||||
for file_id, peer_num in updates.items():
|
||||
self.execute("UPDATE file_optional SET peer = ? WHERE file_id = ?", (peer_num, file_id))
|
||||
self.execute("END")
|
||||
|
||||
|
@ -394,7 +394,7 @@ class ContentDbPlugin(object):
|
|||
|
||||
self.updatePeerNumbers()
|
||||
|
||||
site_ids_reverse = {val: key for key, val in self.site_ids.iteritems()}
|
||||
site_ids_reverse = {val: key for key, val in self.site_ids.items()}
|
||||
deleted_file_ids = []
|
||||
for row in self.queryDeletableFiles():
|
||||
site_address = site_ids_reverse.get(row["site_id"])
|
||||
|
|
|
@ -6,7 +6,7 @@ import gevent
|
|||
|
||||
from util import helper
|
||||
from Plugin import PluginManager
|
||||
import ContentDbPlugin
|
||||
from . import ContentDbPlugin
|
||||
|
||||
|
||||
# We can only import plugin host clases after the plugins are loaded
|
||||
|
@ -24,7 +24,7 @@ def processAccessLog():
|
|||
for site_id in access_log:
|
||||
content_db.execute(
|
||||
"UPDATE file_optional SET time_accessed = %s WHERE ?" % now,
|
||||
{"site_id": site_id, "inner_path": access_log[site_id].keys()}
|
||||
{"site_id": site_id, "inner_path": list(access_log[site_id].keys())}
|
||||
)
|
||||
num += len(access_log[site_id])
|
||||
access_log.clear()
|
||||
|
@ -37,7 +37,7 @@ def processRequestLog():
|
|||
num = 0
|
||||
cur.execute("BEGIN")
|
||||
for site_id in request_log:
|
||||
for inner_path, uploaded in request_log[site_id].iteritems():
|
||||
for inner_path, uploaded in request_log[site_id].items():
|
||||
content_db.execute(
|
||||
"UPDATE file_optional SET uploaded = uploaded + %s WHERE ?" % uploaded,
|
||||
{"site_id": site_id, "inner_path": inner_path}
|
||||
|
@ -101,7 +101,7 @@ class ContentManagerPlugin(object):
|
|||
{"site_id": self.contents.db.site_ids[self.site.address], "hash_id": hash_id}
|
||||
)
|
||||
row = res.fetchone()
|
||||
if row and row[0]:
|
||||
if row and row["is_downloaded"]:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -191,7 +191,7 @@ class SitePlugin(object):
|
|||
if is_downloadable:
|
||||
return is_downloadable
|
||||
|
||||
for path in self.settings.get("optional_help", {}).iterkeys():
|
||||
for path in self.settings.get("optional_help", {}).keys():
|
||||
if inner_path.startswith(path):
|
||||
return True
|
||||
|
||||
|
|
|
@ -1,15 +1,7 @@
|
|||
import hashlib
|
||||
import os
|
||||
import copy
|
||||
import json
|
||||
from cStringIO import StringIO
|
||||
|
||||
import pytest
|
||||
|
||||
from OptionalManager import OptionalManagerPlugin
|
||||
from util import helper
|
||||
from Crypt import CryptBitcoin
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("resetSettings")
|
||||
class TestOptionalManager:
|
||||
|
@ -58,7 +50,7 @@ class TestOptionalManager:
|
|||
assert not file_row["is_downloaded"]
|
||||
|
||||
# Write file from outside of ZeroNet
|
||||
site.storage.open("testfile", "wb").write("A" * 1234) # For quick check hash does not matter only file size
|
||||
site.storage.open("testfile", "wb").write(b"A" * 1234) # For quick check hash does not matter only file size
|
||||
|
||||
hashfield_len_before = len(site.content_manager.hashfield)
|
||||
site.storage.verifyFiles(quick_check=True)
|
||||
|
@ -92,8 +84,8 @@ class TestOptionalManager:
|
|||
assert site.content_manager.hashfield.getHashId("aaaabbbbcccc") == site.content_manager.hashfield.getHashId("aaaabbbbdddd")
|
||||
|
||||
# Write files from outside of ZeroNet (For quick check hash does not matter only file size)
|
||||
site.storage.open("testfile1", "wb").write("A" * 1234)
|
||||
site.storage.open("testfile2", "wb").write("B" * 2345)
|
||||
site.storage.open("testfile1", "wb").write(b"A" * 1234)
|
||||
site.storage.open("testfile2", "wb").write(b"B" * 2345)
|
||||
|
||||
site.storage.verifyFiles(quick_check=True)
|
||||
|
||||
|
@ -129,7 +121,6 @@ class TestOptionalManager:
|
|||
assert site.bad_files["data/fake_bigfile.mp4|2048-3064"] == 1
|
||||
|
||||
def testOptionalDelete(self, site):
|
||||
privatekey = "5KUh3PvNm5HUWoCfSUfcYvfQ2g3PrRNJWr6Q9eqdBGu23mtMntv"
|
||||
contents = site.content_manager.contents
|
||||
|
||||
site.content_manager.setPin("data/img/zerotalk-upvote.png", True)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import re
|
||||
import time
|
||||
import cgi
|
||||
import html
|
||||
|
||||
import gevent
|
||||
|
||||
|
@ -28,7 +28,7 @@ class UiWebsocketPlugin(object):
|
|||
content_db.my_optional_files[self.site.address + "/" + content_inner_dir] = time.time()
|
||||
if len(content_db.my_optional_files) > 50: # Keep only last 50
|
||||
oldest_key = min(
|
||||
content_db.my_optional_files.iterkeys(),
|
||||
iter(content_db.my_optional_files.keys()),
|
||||
key=(lambda key: content_db.my_optional_files[key])
|
||||
)
|
||||
del content_db.my_optional_files[oldest_key]
|
||||
|
@ -80,7 +80,7 @@ class UiWebsocketPlugin(object):
|
|||
# Add leech / seed stats
|
||||
row["peer_seed"] = 0
|
||||
row["peer_leech"] = 0
|
||||
for peer in site.peers.itervalues():
|
||||
for peer in site.peers.values():
|
||||
if not peer.time_piecefields_updated or sha512 not in peer.piecefields:
|
||||
continue
|
||||
peer_piecefield = peer.piecefields[sha512].tostring()
|
||||
|
@ -212,7 +212,7 @@ class UiWebsocketPlugin(object):
|
|||
num_file = len(inner_path)
|
||||
if back == "ok":
|
||||
if num_file == 1:
|
||||
self.cmd("notification", ["done", _["Pinned %s"] % cgi.escape(helper.getFilename(inner_path[0])), 5000])
|
||||
self.cmd("notification", ["done", _["Pinned %s"] % html.escape(helper.getFilename(inner_path[0])), 5000])
|
||||
else:
|
||||
self.cmd("notification", ["done", _["Pinned %s files"] % num_file, 5000])
|
||||
self.response(to, back)
|
||||
|
@ -224,7 +224,7 @@ class UiWebsocketPlugin(object):
|
|||
num_file = len(inner_path)
|
||||
if back == "ok":
|
||||
if num_file == 1:
|
||||
self.cmd("notification", ["done", _["Removed pin from %s"] % cgi.escape(helper.getFilename(inner_path[0])), 5000])
|
||||
self.cmd("notification", ["done", _["Removed pin from %s"] % html.escape(helper.getFilename(inner_path[0])), 5000])
|
||||
else:
|
||||
self.cmd("notification", ["done", _["Removed pin from %s files"] % num_file, 5000])
|
||||
self.response(to, back)
|
||||
|
@ -325,7 +325,7 @@ class UiWebsocketPlugin(object):
|
|||
self.cmd("notification", [
|
||||
"done",
|
||||
_["You started to help distribute <b>%s</b>.<br><small>Directory: %s</small>"] %
|
||||
(cgi.escape(title), cgi.escape(directory)),
|
||||
(html.escape(title), html.escape(directory)),
|
||||
10000
|
||||
])
|
||||
|
||||
|
@ -369,10 +369,10 @@ class UiWebsocketPlugin(object):
|
|||
self.cmd(
|
||||
"confirm",
|
||||
[
|
||||
_["Help distribute all new optional files on site <b>%s</b>"] % cgi.escape(site_title),
|
||||
_["Help distribute all new optional files on site <b>%s</b>"] % html.escape(site_title),
|
||||
_["Yes, I want to help!"]
|
||||
],
|
||||
lambda (res): self.cbOptionalHelpAll(to, site, True)
|
||||
lambda res: self.cbOptionalHelpAll(to, site, True)
|
||||
)
|
||||
else:
|
||||
site.settings["autodownloadoptional"] = False
|
||||
|
|
|
@ -1 +1 @@
|
|||
import OptionalManagerPlugin
|
||||
from . import OptionalManagerPlugin
|
Loading…
Add table
Add a link
Reference in a new issue