Replaced ti_-functions with lambdas

This commit is contained in:
bendikro 2013-02-12 01:21:32 +01:00
parent 5bcb104a01
commit 31ecaacbc8
1 changed files with 6 additions and 36 deletions

View File

@ -763,6 +763,12 @@ class Torrent(object):
"trackers": lambda: self.trackers, "trackers": lambda: self.trackers,
"tracker_status": lambda: self.tracker_status, "tracker_status": lambda: self.tracker_status,
"upload_payload_rate": lambda: self.status.upload_payload_rate, "upload_payload_rate": lambda: self.status.upload_payload_rate,
"comment": lambda: decode_string(self.torrent_info.comment()) if self.has_metadata() else u"",
"num_files": lambda: self.torrent_info.num_files() if self.has_metadata() else 0,
"num_pieces": lambda: self.torrent_info.num_pieces() if self.has_metadata() else 0,
"piece_length": lambda: self.torrent_info.piece_length() if self.has_metadata() else 0,
"private": lambda: self.torrent_info.priv() if self.has_metadata() else False,
"total_size": lambda: self.torrent_info.total_size() if self.has_metadata() else 0,
"eta": self.get_eta, "eta": self.get_eta,
"file_progress": self.get_file_progress, # Adjust progress to be 0-100 value "file_progress": self.get_file_progress, # Adjust progress to be 0-100 value
"files": self.get_files, "files": self.get_files,
@ -774,44 +780,8 @@ class Torrent(object):
"last_seen_complete": self.get_last_seen_complete, "last_seen_complete": self.get_last_seen_complete,
"name": self.get_name, "name": self.get_name,
"pieces": self._get_pieces_info, "pieces": self._get_pieces_info,
"comment": ti_comment,
"num_files": ti_num_files,
"num_pieces": ti_num_pieces,
"piece_length": ti_piece_length,
"private": ti_priv,
"total_size": ti_total_size,
} }
def ti_comment():
if self.has_metadata():
return decode_string(self.torrent_info.comment())
return u""
def ti_priv():
if self.has_metadata():
return self.torrent_info.priv()
return False
def ti_total_size():
if self.has_metadata():
return self.torrent_info.total_size()
return 0
def ti_num_files():
if self.has_metadata():
return self.torrent_info.num_files()
return 0
def ti_num_pieces():
if self.has_metadata():
return self.torrent_info.num_pieces()
return 0
def ti_piece_length():
if self.has_metadata():
return self.torrent_info.piece_length()
return 0
def get_name(self): def get_name(self):
if self.has_metadata(): if self.has_metadata():
name = self.torrent_info.file_at(0).path.replace("\\", "/", 1).split("/", 1)[0] name = self.torrent_info.file_at(0).path.replace("\\", "/", 1).split("/", 1)[0]