added __len__ to Ticket and TMD (lets you do len(tik) or len(tmd) to get the length, including TMD contents)

This commit is contained in:
icefire 2009-06-14 22:11:53 -07:00
parent 87067fc3e2
commit 02fd26a836

View File

@ -106,7 +106,9 @@ class Ticket:
else: else:
open(fn, "wb").write(self.tik.pack()) open(fn, "wb").write(self.tik.pack())
return fn return fn
def __len__(self):
sz = len(self.tik)
return sz
class TMD: class TMD:
"""This class allows you to edit TMDs. TMD (Title Metadata) files are used in many places to hold information about titles. The parameter f to the initialization is the filename to open and create a TMD from.""" """This class allows you to edit TMDs. TMD (Title Metadata) files are used in many places to hold information about titles. The parameter f to the initialization is the filename to open and create a TMD from."""
@ -188,7 +190,12 @@ class TMD:
out += "\n" out += "\n"
return out return out
def __len__(self):
contents = self.getContents()
sz = len(self.tmd)
for i in range(len(contents)):
sz += len(contents[i])
return sz
def dump(self, fn = ""): def dump(self, fn = ""):
"""Dumps the TMD to the filename specified in fn, if not empty. If that is empty, it overwrites the original. This fakesigns the TMD, but does not update the hashes and the sizes, that is left as a job for you. Returns output filename.""" """Dumps the TMD to the filename specified in fn, if not empty. If that is empty, it overwrites the original. This fakesigns the TMD, but does not update the hashes and the sizes, that is left as a job for you. Returns output filename."""
for i in range(65536): for i in range(65536):
@ -456,6 +463,4 @@ class WAD:
out += str(Ticket(rawtik)) out += str(Ticket(rawtik))
out += str(TMD(rawtmd)) out += str(TMD(rawtmd))
return out return out