2012-06-14 18:27:23 +02:00
|
|
|
"""
|
|
|
|
This module is in charge of taking care of all the infomation related to
|
|
|
|
individual files. Files are identified by the account name and its sid.
|
|
|
|
|
|
|
|
|
2018-04-07 23:06:48 +02:00
|
|
|
>>> print(FilesProp.getFileProp('jabberid', '10'))
|
2012-06-14 18:27:23 +02:00
|
|
|
None
|
|
|
|
>>> fp = FilesProp()
|
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
Exception: this class should not be instatiated
|
2018-04-07 23:06:48 +02:00
|
|
|
>>> print(FilesProp.getAllFileProp())
|
2012-06-14 18:27:23 +02:00
|
|
|
[]
|
|
|
|
>>> fp = FilesProp.getNewFileProp('jabberid', '10')
|
|
|
|
>>> fp2 = FilesProp.getFileProp('jabberid', '10')
|
|
|
|
>>> fp == fp2
|
|
|
|
True
|
|
|
|
"""
|
|
|
|
|
|
|
|
class FilesProp:
|
|
|
|
_files_props = {}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
raise Exception('this class should not be instatiated')
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getNewFileProp(cls, account, sid):
|
|
|
|
fp = FileProp(account, sid)
|
|
|
|
cls.setFileProp(fp, account, sid)
|
|
|
|
return fp
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getFileProp(cls, account, sid):
|
|
|
|
if (account, sid) in cls._files_props.keys():
|
|
|
|
return cls._files_props[account, sid]
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getFilePropByAccount(cls, account):
|
|
|
|
# Returns a list of file_props in one account
|
|
|
|
file_props = []
|
|
|
|
for account, sid in cls._files_props:
|
|
|
|
if account == account:
|
|
|
|
file_props.append(cls._files_props[account, sid])
|
|
|
|
return file_props
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getFilePropByType(cls, type_, sid):
|
|
|
|
# This method should be deleted. Getting fileprop by type and sid is not
|
|
|
|
# unique enough. More than one fileprop might have the same type and sid
|
|
|
|
files_prop = cls.getAllFileProp()
|
|
|
|
for fp in files_prop:
|
|
|
|
if fp.type_ == type_ and fp.sid == sid:
|
|
|
|
return fp
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def getFilePropBySid(cls, sid):
|
|
|
|
# This method should be deleted. It is kept to make things compatible
|
|
|
|
# This method should be replaced and instead get the file_props by
|
|
|
|
# account and sid
|
|
|
|
files_prop = cls.getAllFileProp()
|
|
|
|
for fp in files_prop:
|
|
|
|
if fp.sid == sid:
|
|
|
|
return fp
|
|
|
|
|
2014-02-24 22:13:25 +01:00
|
|
|
@classmethod
|
|
|
|
def getFilePropByTransportSid(cls, account, sid):
|
|
|
|
files_prop = cls.getAllFileProp()
|
|
|
|
for fp in files_prop:
|
|
|
|
if fp.account == account and fp.transport_sid == sid:
|
|
|
|
return fp
|
|
|
|
|
2012-06-14 18:27:23 +02:00
|
|
|
@classmethod
|
|
|
|
def getAllFileProp(cls):
|
2013-01-02 17:53:42 +01:00
|
|
|
return list(cls._files_props.values())
|
2012-06-14 18:27:23 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setFileProp(cls, fp, account, sid):
|
|
|
|
cls._files_props[account, sid] = fp
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def deleteFileProp(cls, file_prop):
|
|
|
|
files_props = cls._files_props
|
|
|
|
a = s = None
|
|
|
|
for account, sid in files_props:
|
|
|
|
fp = files_props[account, sid]
|
|
|
|
if fp is file_prop:
|
|
|
|
a = account
|
|
|
|
s = sid
|
|
|
|
if a != None and s != None:
|
|
|
|
del files_props[a, s]
|
|
|
|
|
|
|
|
|
|
|
|
class FileProp(object):
|
|
|
|
|
|
|
|
def __init__(self, account, sid):
|
|
|
|
# Do not instatiate this class directly. Call FilesProp.getNeFileProp
|
|
|
|
# instead
|
|
|
|
self.streamhosts = []
|
|
|
|
self.transfered_size = []
|
|
|
|
self.started = False
|
|
|
|
self.completed = False
|
|
|
|
self.paused = False
|
|
|
|
self.stalled = False
|
|
|
|
self.connected = False
|
|
|
|
self.stopped = False
|
|
|
|
self.is_a_proxy = False
|
|
|
|
self.proxyhost = None
|
|
|
|
self.proxy_sender = None
|
|
|
|
self.proxy_receiver = None
|
|
|
|
self.streamhost_used = None
|
|
|
|
# method callback called in case of transfer failure
|
|
|
|
self.failure_cb = None
|
|
|
|
# method callback called when disconnecting
|
|
|
|
self.disconnect_cb = None
|
|
|
|
self.continue_cb = None
|
|
|
|
self.sha_str = None
|
|
|
|
# transfer type: 's' for sending and 'r' for receiving
|
|
|
|
self.type_ = None
|
|
|
|
self.error = None
|
2012-10-13 23:32:19 +02:00
|
|
|
# Elapsed time of the file transfer
|
|
|
|
self.elapsed_time = 0
|
2012-06-14 18:27:23 +02:00
|
|
|
self.last_time = None
|
|
|
|
self.received_len = None
|
|
|
|
# full file path
|
|
|
|
self.file_name = None
|
|
|
|
self.name = None
|
2012-08-29 21:06:04 +02:00
|
|
|
self.date = None
|
2012-08-28 15:46:52 +02:00
|
|
|
self.desc = None
|
2012-06-14 18:27:23 +02:00
|
|
|
self.offset = None
|
|
|
|
self.sender = None
|
|
|
|
self.receiver = None
|
|
|
|
self.tt_account = None
|
|
|
|
self.size = None
|
|
|
|
self._sid = sid
|
2012-08-25 18:09:50 +02:00
|
|
|
self.transport_sid = None
|
2012-06-14 18:27:23 +02:00
|
|
|
self.account = account
|
|
|
|
self.mime_type = None
|
|
|
|
self.algo = None
|
|
|
|
self.direction = None
|
|
|
|
self.syn_id = None
|
|
|
|
self.seq = None
|
|
|
|
self.hash_ = None
|
|
|
|
self.fd = None
|
|
|
|
self.startexmpp = None
|
2013-01-20 02:40:19 +01:00
|
|
|
# Type of the session, if it is 'jingle' or 'si'
|
2012-06-14 18:27:23 +02:00
|
|
|
self.session_type = None
|
2012-06-14 18:45:11 +02:00
|
|
|
self.request_id = None
|
2012-06-20 23:58:23 +02:00
|
|
|
self.proxyhosts = None
|
2012-08-23 13:10:30 +02:00
|
|
|
self.dstaddr = None
|
2012-06-14 18:27:23 +02:00
|
|
|
|
|
|
|
def getsid(self):
|
|
|
|
# Getter of the property sid
|
|
|
|
return self._sid
|
|
|
|
|
|
|
|
def setsid(self, value):
|
|
|
|
# The sid value will change
|
|
|
|
# we need to change the in _files_props key as well
|
|
|
|
del FilesProp._files_props[self.account, self._sid]
|
|
|
|
self._sid = value
|
|
|
|
FilesProp._files_props[self.account, self._sid] = self
|
|
|
|
|
|
|
|
sid = property(getsid, setsid)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
import doctest
|
|
|
|
doctest.testmod()
|