Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self):
self.fcpNode = fcp.FCPNode(host="localhost")
def n():
if node is None:
return fcp.FCPNode()
return node
with n() as node:
"""Send a message to the Web of Trust plugin
>>> name = wotmessage("RandomName")["Replies.Name"]
"""
params["Message"] = messagetype
def sendmessage(params):
with fcp.FCPNode() as n:
return n.fcpPluginMessage(plugin_name="plugins.WebOfTrust.WebOfTrust",
plugin_params=params)[0]
try:
resp = sendmessage(params)
except fcp.FCPProtocolError as e:
if str(e) == "ProtocolError;No such plugin":
logging.warn("Plugin Web Of Trust not loaded. Trying to load it.")
with fcp.FCPNode() as n:
jobid = n._getUniqueId()
resp = n._submitCmd(jobid, "LoadPlugin",
PluginURL="WebOfTrust",
URLType="official",
OfficialSource="freenet")[0]
resp = sendmessage(params)
else: raise
return resp
% self.basedir)
# get a node object
#print "load: verbosity=%s" % self.verbosity
nodeopts = dict(host=self.fcpHost,
port=self.fcpPort,
verbosity=self.verbosity,
name="freesitemgr",
)
if self.logfile:
nodeopts['logfile'] = self.logfile
try:
# create node, if we can
self.node = fcp.FCPNode(**nodeopts)
if not self.chkCalcNode:
self.chkCalcNode = self.node
self.node.listenGlobal()
# borrow the node's logger
self.log = self.node._log
except Exception as e:
# limited functionality - no node
self.node = None
self.log = self.fallbackLogger
self.log(ERROR, "Could not create an FCPNode, functionality will be limited. Reason: %s" % str(e))
log = self.log
self.sites = []
def n():
if node is None:
return fcp.FCPNode()
return node
with n() as node:
>>> k1 = "KSK@tcshrietshcrietsnhcrie-Test"
>>> k2 = "KSK@tcshrietshcrietsnhcrie-Test2"
>>> if slowtests or True:
... k1res = fastput(k1, d1)
... k2res = fastput(k2, d2)
... watcher = watchcaptchas([k1,k2])
... [i for i in watcher if i is not None] # drain watcher.
... # note: I cannot use i.next() in the doctest, else I’d get "I/O operation on closed file"
... else:
... [(k1, d1), (k2, d2)]
[('KSK@tcshrietshcrietsnhcrie-Test', 'Test'), ('KSK@tcshrietshcrietsnhcrie-Test2', 'Test2')]
"""
# TODO: in Python3 this could be replaced with less than half the lines using futures.
# use a shared fcp connection for all get requests
node = fcp.FCPNode()
tasks = []
for i in solutions:
job = node.get(i,
realtime=True, priority=4,
followRedirect=False,
async=True)
tasks.append((i, job))
while tasks:
atleastone = False
for key, job in tasks:
if job.isComplete():
tasks.remove((key, job))
atleastone = True
res = key, job.getResult()[1]
yield res
fcpHost = ""
# get fcp port
while 1:
fcpPort = raw_input("FCP Port [%s]: " % sitemgr.fcpPort).strip()
if not fcpPort:
fcpPort = sitemgr.fcpPort
try:
fcpPort = int(fcpPort)
except:
continue
break
print "Trying FCP port at %s:%s" % (fcpHost, fcpPort)
try:
fcpnode = fcp.FCPNode(host=fcpHost, port=fcpPort)
except:
traceback.print_exc()
print "Failed to connect to FCP Port"
print "Please ensure your node is running, with its FCP port"
print "reachable at %s:%s, and try this command again" % (fcpHost, fcpPort)
print "Setup aborted"
return
fcpnode.shutdown()
sitemgr.fcpHost = fcpHost
sitemgr.fcpPort = fcpPort
# confirm and save
if getyesno("Save configuration", True):
sitemgr.save()
def getPeerUpdateHelper( fcp_host, fcp_port ):
cpeers = 0
tpeers = 0
f = None;
try:
f = fcp.FCPNode( host = fcp_host, port = fcp_port )
returned_peerlist = f.listpeers( WithVolatile = True )
except Exception, msg:
if(f != None):
f.shutdown()
return { "status" : -1, "status_msg" : msg, "cpeers" : None, "tpeers" : None }
try:
f.shutdown();
except Exception, msg:
pass # Ignore a failure to end the FCP session as we've got what we want now
if( type( returned_peerlist ) != type( [] )):
returned_peerlist = [ returned_peerlist ];
for peer in returned_peerlist:
if( peer[ "header" ] != "Peer" ):
break
if( not peer.has_key( "volatile.status" )):
continue;
def prepareintroduce(identities, requesturis, ownidentity, trustifmissing, commentifmissing):
"""Prepare announcing to the identities.
This ensures that the identity is known to WoT, gives it trust to
ensure that it will be fetched, pre-fetches the ID and fetches the
captchas. It returns an iterator which yields either a captcha to
solve or None.
"""
# ensure that we have a real copy to avoid mutating the original lists.
ids = identities[:]
keys = requesturis[:]
tasks = zip(ids, keys)
# use a single node for all the the get requests in the iterator.
node = fcp.FCPNode()
while tasks:
for identity, requesturi in tasks[:]:
ensureavailability(identity, requesturi, ownidentity, trustifmissing, commentifmissing)
try:
print "Getting identity information for {}".format(identity)
name, info = getidentity(identity, ownidentity)
except ProtocolError as e:
unknowniderror = 'plugins.WebOfTrust.exceptions.UnknownIdentityException: {}'.format(identity)
if e.args[0]['Replies.Description'] == unknowniderror:
logging.warn("identity to introduce not yet known. Adding trust {} for {}".format(trustifmissing, identity))
addidentity(requesturi)
settrust(ownidentity, identity, trustifmissing, commentifmissing)
name, info = getidentity(identity, ownidentity)
if "babcomcaptchas" in info["Properties"]:
print "Getting CAPTCHAs for id", identity
captchas = fastget(info["Properties"]["babcomcaptchas"],