Esempio n. 1
0
    def getSomeMetadata(self, channel_id, infohash):

            
        s1 = SubtitleInfo("eng", None)
        s2 = SubtitleInfo("rus", None)
        
        self.content1 = u"Subtitle Content 1"
        self.content2 = u"Subtitle Content 2"
        
        hasher = sha()
        hasher.update(self.content1)
        s1.checksum = hasher.digest()
        
        hasher = sha()
        hasher.update(self.content2)
        s2.checksum = hasher.digest()
            
        metadata = MetadataDTO(channel_id, infohash, time.time(),
                               "", {"eng":s1, "rus":s2})
        
        if self.nextKeypair is None:
            metadata.signature = "fake"
        else:
            metadata.sign(self.nextKeypair)
   
        return metadata
Esempio n. 2
0
def _createSubtitlesDict(bitmask, listOfChecksums):
    langList = _languagesUtil.maskToLangCodes(bitmask)
    if len(langList) != len(listOfChecksums):
        raise SerializationException("Unexpected num of checksums")

    subtitles = {}
    for i in range(0, len(langList)):
        sub = SubtitleInfo(langList[i])
        sub.checksum = listOfChecksums[i]
        subtitles[langList[i]] = sub
    return subtitles
Esempio n. 3
0
 def testChecksums(self):
     path = os.path.join(RES_DIR,PATH_TO_SRT)
     sub = SubtitleInfo("ita",path)
     #I know from the outside the the correct sha1 is
     # eb8ada2a2094675ea047c27207e449fbfce04e85
     sha1Hasher = hashlib.sha1()
     with codecs.open(path, "rb", "utf-8") as subFile:
         sha1Hasher.update(subFile.read())
     expectedChecksum = sha1Hasher.digest()
     
     
     sub.computeChecksum()
     
     self.assertEquals(expectedChecksum,
                       sub.checksum)
     
     self.assertTrue(sub.verifyChecksum())
Esempio n. 4
0
 def __init__(self):
     
     self.returnMetadata = True
     self.getAllSubsCount = 0
     self.getAllSubsParametersHistory = list()
     
     self.getMetadataCount = 0
     self.getMetadataParametesHistory = list()
     
     self.updateSubtitleCount = 0
     self.updateSubtitleParameterHistory = list()
     
     self.commitCount = 0
     
     s1 = SubtitleInfo("eng", os.path.join(RES_DIR,"fake0.srt"))
     s1.computeChecksum()
     s2 = SubtitleInfo("rus", os.path.join(RES_DIR,"fake1.srt"))
     s2.computeChecksum()
     
     self.returnSubs = {
                         "eng" : s1,
                         "rus" : s2
                         }
     
     self.insertMetadataCount = 0
     self.insertMetadataParameters = list()
     self.nextKeypair = None
 def setupDB(self,nickname):
     TestChannels.setupDB(self,nickname)
     try:
         self.richMetadata_db = self.session.open_dbhandler(NTFY_RICH_METADATA)
         #add some metadata for torrents (they are defined in TestChannels.setupDB()
         self.mdto = MetadataDTO(self.hispermid, self.infohash1)
         subtitle1 = SubtitleInfo("nld", os.path.join(RES_DIR,"fake.srt"))
         subtitle1.computeChecksum()
         
         subtitle2 = SubtitleInfo("eng", os.path.join(RES_DIR, "fake0.srt"))
         subtitle2.computeChecksum()
         self.mdto.addSubtitle(subtitle1)
         self.mdto.addSubtitle(subtitle2)
         
         self.mdto.sign(self.his_keypair)
         
         self.richMetadata_db.insertMetadata(self.mdto)
     except:
         print_exc()
Esempio n. 6
0
    def setUpDB(self):
        try:
            self.richMetadata_db = self.session.open_dbhandler(NTFY_RICH_METADATA)

            #add some metadata
            self.mdto = MetadataDTO(self.anotherpermid, self.testInfohash)
            subtitle1 = SubtitleInfo("nld", self.sub1)
            subtitle1.computeChecksum()
            subtitle2 = SubtitleInfo("eng", os.path.join(RES_DIR, "fake0.srt"))
            subtitle2.computeChecksum()
            self.mdto.addSubtitle(subtitle1)
            self.mdto.addSubtitle(subtitle2)
            
            self.mdto.sign(self.another_keypair)
            
            self.richMetadata_db.insertMetadata(self.mdto)
            
            
            
            #hisoermid has the nld subtitle but doesn't have the english one
            self.richMetadata_db.updateSubtitlePath(self.mdto.channel,self.mdto.infohash,"eng",None)
            
        except:
            print_exc()
Esempio n. 7
0
 def testSubsExists(self):
     path = os.path.join(RES_DIR,PATH_TO_SRT)
     sub = SubtitleInfo("rus","fakepath")
     self.assertFalse(sub.subtitleExists())
     sub.path = os.path.abspath(path)
     self.assertTrue(sub.subtitleExists())
Esempio n. 8
0
 def testInitialization(self):
     sub = SubtitleInfo("eng","fakepath")
     self.assertFalse(sub is None)
     self.assertFalse(sub.subtitleExists())
     self.assertRaises(AssertionError, sub.computeChecksum)