Esempio n. 1
0
 def generate(self, info, save=True, add_index=True):
   for i, tmpl in enumerate(self.template_paths, 1):
     filler = Filler(template_path=tmpl, output_folder=self.output_path)
     filler.render(info=info)
     if save:
       prefix = '{:02d}-'.format(i) if add_index else ''
       filler.save(info=info, close=True, prefix=prefix)
Esempio n. 2
0
    def test_repeated_score(self):
        """
        Test that weighting a list with repeated features returns boolean weights.
        """

        tokens = ['a', 'b', 'a']
        scheme = Filler()
        self.assertEqual({'a': 1, 'b': 1}, scheme.score(tokens))
Esempio n. 3
0
    def test_list_score(self):
        """
        Test that weighting a list returns the weights of the documents.
        """

        tokens = ['a', 'b']
        scheme = Filler()
        self.assertEqual({'a': 1, 'b': 1}, scheme.score(tokens))
Esempio n. 4
0
    def test_empty_list_score(self):
        """
        Test that weighting an empty list returns no weights.
        """

        tokens = []
        scheme = Filler()
        self.assertEqual({}, scheme.score(tokens))
Esempio n. 5
0
 def __zero_loca(self, output):  # more advanced filling needed
   self.font = TTFont(output)
   loca_off = self.font.reader.tables['loca'].offset
   loca_len = self.font.reader.tables['loca'].length
   self.font.close()
   filler = Filler(output)
   filler.fill(loca_off, loca_len, '\0')
   filler.close()
Esempio n. 6
0
 def __zero_glyf(self, output):
   self.font = TTFont(output)
   glyf_off = self.font.reader.tables['glyf'].offset
   glyf_len = self.font.reader.tables['glyf'].length
   self.font.close()
   filler = Filler(output)
   filler.fill(glyf_off, glyf_len, '\0')
   filler.close()
Esempio n. 7
0
 def detect_required_fields(self, quick=False):
   '''quick=Ture -> preview required_fields from config.yaml
      quick=False -> detect from open tmpl files and check by string "{{*}}
   '''
   field_names = []
   if quick:
     default_templates = self.read_config()['default_templates']
     for tmpl in self.template_paths:
       found = [item for item in default_templates if item['file'] == tmpl]
       if found and found[-1].get('required_fields'):
         field_names.extend(found[-1]['required_fields'])
   else:
     for tmpl in self.template_paths:
       filler = Filler(template_path=tmpl, output_folder=self.output_path)
       field_names.extend(filler.detect_required_fields(close=True, unique=True))
   return list(pylon.dedupe(field_names))
Esempio n. 8
0
 def __end_char_strings(self, output):
   self.font = TTFont(output)
   assert 'CFF ' in self.font
   cffTableOffset = self.font.reader.tables['CFF '].offset
   cffTable = self.font['CFF '].cff
   assert len(cffTable.fontNames) == 1
   charStringOffset = cffTable[cffTable.fontNames[0]].rawDict['CharStrings']
   inner_file = self.font.reader.file
   inner_file.seek(cffTableOffset + charStringOffset)
   rawIndexFile = Index(inner_file)
   baseOffset = rawIndexFile.offsetBase
   size = rawIndexFile.offsets[-1] - 1
   offset = baseOffset + rawIndexFile.offsets[0]
   self.font.close()
   filler = Filler(output)
   filler.fill(offset, size, '\x00')
   filler.close()
Esempio n. 9
0
 def __zero_charset_fmt(self,output):
   font = TTFont(output)
   cffTableOffset = font.reader.tables['CFF '].offset
   cffTable = font['CFF '].cff
   assert len(cffTable.fontNames) == 1 #only one font should be present
   charsetOffset = cffTable[cffTable.fontNames[0]].rawDict['charset']
   numGlyphs = font['maxp'].numGlyphs
   inner_file = font.reader.file
   inner_file.seek(cffTableOffset+charsetOffset)
   format = readCard8(inner_file);
   if format != 2 and format != 1:
     return None
   record_len = 4 if format == 2 else 3
   seenGlyphCount = 0
   size = 0
   while seenGlyphCount < numGlyphs:
     inner_file.seek(2,io.SEEK_CUR)
     if format == 2:
       nLeft = readCard16(inner_file)
     else: #format 1
       nLeft = readCard8(inner_file)
     seenGlyphCount += nLeft + 1
     size += 1
   font.close()
   filler = Filler(output)
   filler.fill(cffTableOffset+charsetOffset+1, record_len*size, '\x00')
   filler.close()
Esempio n. 10
0
  def __zero_cmaps(self,output):
    font = TTFont(output)
    old_cmap_method = change_method(_c_m_a_p.table__c_m_a_p, _decompile_in_table_cmap,'decompile')
    old_12_method = change_method(_c_m_a_p.cmap_format_12_or_13,_decompile_in_cmap_format_12_13, 'decompile')
    old_4_method = change_method(_c_m_a_p.cmap_format_4,_decompile_in_cmap_format_4, 'decompile')

    cmap_offset = font.reader.tables['cmap'].offset
    cmapTables = font['cmap']
    cmap12 = cmapTables.getcmap(3, 10) #format 12
    cmap4 = cmapTables.getcmap(3, 1) #format 4

    ranges_to_zero = []
    if cmap12:
      ranges_to_zero.append((cmap_offset+cmap12.offset+16,cmap12.length-16))
    #if cmap4:
    #  ranges_to_zero.append((cmap_offset+cmap4.offset+14,cmap4.length-14))

    change_method(_c_m_a_p.cmap_format_12_or_13,old_12_method,'decompile')
    change_method(_c_m_a_p.cmap_format_4,old_4_method,'decompile')
    change_method(_c_m_a_p.table__c_m_a_p,old_cmap_method,'decompile')

    font.close()

    #if len(ranges_to_zero)<2: #return if both doesn't exist
    #  return

    for block in ranges_to_zero:
      filler = Filler(output)
      filler.fill(block[0], block[1], '\x00')
      filler.close()
Esempio n. 11
0
def fill_database():
    filler = Filler()
    start = time.time()

    allClients = server.clientlist()
    clientList = []

    channels = server.send_command('channellist').data

    afk_cid = ''

    for x in channels:
        if x['channel_name'] == 'AFK':
            afk_cid = x['cid']

    for x in allClients:
        if (int(allClients[x]['client_type']) == 0) and (str(allClients[x]['cid']) != str(afk_cid)):
            clientList.append(allClients[x])
            continue

    for x in clientList:
        x['username'] = x['client_nickname']
        x['clientDatabaseId'] = x['client_database_id']
        x['startTime'] = datetime.datetime.now()
        x['endTime'] = datetime.datetime.now()
        x['totalTime'] = 0
        x['idleTime'] = 0
        x['messegeSent'] = False
        x['online'] = True

        x.pop("cid", None)
        x.pop("client_type", None)
        x.pop("client_nickname", None)
        x.pop("client_database_id", None)

    filler.add_all_users(clientList, server, afk_cid)

    print(time.time() - start)
Esempio n. 12
0
def fill_it_up():
    filler = Filler()
    start = time.time()
    for region in regions:
        api = RiotApi('70f53e5d-eea1-46f0-9e8a-19889489902f', region)
        dataC = api.getchallenger()
        x = 0
        for g in dataC['entries']:
            y = 0
            dataT = api.getteam(g['playerOrTeamName'])
            # Grabs all games form a team (dataT)
            for j in dataT['matchHistory']:
                match = filler.session.query(MatchDetail).\
                    filter(MatchDetail.matchId == j['gameId']).first()
                if match is not None:
                    continue
                try:
                    dataM = api.getmatch(g['playerOrTeamName'], str(j['gameId']))
                except:
                    logger.exception('Exception while calling getmatch on team \"%s\" match %s',
                                     g['playerOrTeamName'].encode('utf-8'), str(j['gameId']).encode('utf-8'))
                    continue
                try:
                    statgetter = GetStats(dataM)
                    realdata = statgetter.returnMatchDetail()
                except:
                    logger.exception('Exception while creating statgetter on team \"%s\" match %s',
                                     g['playerOrTeamName'].encode('utf-8'), str(j['gameId']).encode('utf-8'))
                    continue
                filler.add_match(realdata)
                print(time.time() - start)
                logger.info('Successfully added team \"%s\" match %s', g['playerOrTeamName'].encode('utf-8'),
                            str(j['gameId']).encode('utf-8'))
                x += 1
            logger.info('Finished adding all matches for team \"%s\"', g['playerOrTeamName'].encode('utf-8'))
        logger.info('Finished adding all matches for region %s', region)
Esempio n. 13
0
 def __zero_glyf(self, output):
   self.font = TTFont(output)
   # Do not clear the .notdef outlines
   offset_table = self.font['loca'].locations
   notdef_len = offset_table[1] - offset_table[0]
   glyf_off = self.font.reader.tables['glyf'].offset + notdef_len
   glyf_len = self.font.reader.tables['glyf'].length - notdef_len
   self.font.close()
   filler = Filler(output)
   filler.fill(glyf_off, glyf_len, '\x00')
   filler.close()
Esempio n. 14
0
 def __zero_char_strings(self, output):
   self.font = TTFont(output)
   assert 'CFF ' in self.font
   cffTableOffset = self.font.reader.tables['CFF '].offset
   cffTable = self.font['CFF '].cff
   assert len(cffTable.fontNames) == 1
   charStringOffset = cffTable[cffTable.fontNames[0]].rawDict['CharStrings']
   inner_file = self.font.reader.file
   inner_file.seek(cffTableOffset + charStringOffset)
   rawIndexFile = Index(inner_file)
   baseOffset = rawIndexFile.offsetBase
   notdef_glyph_size = rawIndexFile.offsets[1] - rawIndexFile.offsets[0]
   size = rawIndexFile.offsets[-1] - 1 - notdef_glyph_size
   offset = baseOffset + rawIndexFile.offsets[0] + notdef_glyph_size
   self.font.close()
   filler = Filler(output)
   filler.fill(offset, size, '\x00')
   filler.close()