示例#1
0
def _real_test_mencode_implementation_speed():
    import os
    import time
    msgpath = os.path.join(os.environ.get('HOME'), 'tmp/messages')
    filenamelist = os.listdir(msgpath)
    filenamelist.sort()
    decoded_messages = []
    sizes_list = []
    for name in filenamelist:
        encoding = open(os.path.join(msgpath, name), 'rb').read()
        sizes_list.append( len(encoding) )
        decoded_messages.append( mdecode(encoding) )
    totalbytes = reduce(lambda a,b: a+b, sizes_list)
    average = totalbytes / len(sizes_list)
    sizes_list.sort()
    median = sizes_list[len(sizes_list)/2]
    print 'read and decoded %d messages totaling %d bytes, averaging %d bytes, median size of %d' % (len(sizes_list), totalbytes, average, median)

    ### 100% python speed test
    print 'encoding using python implementation...'

    # setup
    # TODO none needed yet
    # end setup

    t1 = time.time()
    for m in decoded_messages:
        try:
            mencode(m)
        except:
            print '!',
    t2 = time.time()
    print 'done.  total encoding time: %3.3f' % (t2 - t1,)
示例#2
0
def _bench_it_mencode(n):
    """
    For use with utilscripts/benchfunc.py.
    """
    d = {}
    for i in xrange(n):
        d[i] = { i: 'spam', i + 1: 'eggs', i * 2: 'bacon'}

    mencode(d)
示例#3
0
 def test_rej_float(self):
     try:
         s = mencode(0.9873)
         assert 0, "You can't encode floats!  Anyway, the result: %s, is probably not what we meant." % humanreadable.hr(s)
     except MencodeError, le:
         try:
             s2 = mencode(0.9873)
             assert 0, "You can't encode floats!  Anyway, the result: %s, is probably not what we meant." % humanreadable.hr(s2)
         except MencodeError, le:
             # Good!  we want an exception when we try this.
             return
示例#4
0
 def test_rej_dict_with_float(self):
     try:
         s = mencode({'foo': 0.9873})
         assert 0, "You can't encode floats!  Anyway, the result: %s, is probably not what we meant." % humanreadable.hr(s)
     except MencodeError, le:
         try:
             # print "got exce1: %s" % humanreadable.hr(le)
             s2 = mencode({'foo': 0.9873})
             assert 0, "You can't encode floats!  Anyway, the result: %s, is probably not what we meant." % humanreadable.hr(s2)
         except MencodeError, le:
             # print "got exce2: %s" % humanreadable.hr(le)
             # Good!  we want an exception when we try this.
             return
示例#5
0
 def adityaarchi(self, sd, dd, ss, split, msg, tex, nama=[]):
     selection = mencode(split, range(1, len(nama) + 1))
     k = len(nama) // 100
     for a in range(k + 1):
         if a == 0: eto = '「 ' + sd + ' 」'
         else: eto = ''
         text = ''
         mids = []
         no = a
         for i in selection.parse()[a * 100:(a + 1) * 100]:
             mids.append(nama[i - 1])
             if dd == 'kick':
                 self.kickoutFromGroup(ss, [nama[i - 1]])
                 hh = ''
             if dd == 'delfriend':
                 try:
                     self.deleteContact(nama[i - 1])
                     hh = 'Del Friend'
                 except:
                     hh = 'Not Friend User'
             if dd == '': hh = ''
             if dd == 'tag': hh = ''
             no += 1
             if no == len(selection.parse()):
                 text += "\n{}. @! {}".format(i, hh)
             else:
                 text += "\n{}. @! {}".format(i, hh)
         if dd == 'tag': self.sendMention(ss, eto + text, sd, mids)
         else: self.sendMention(msg.to, eto + text, sd, mids)
     if dd == 'tag':
         self.sendMessage(
             msg.to, 'Status: Success tag {} mem'.format(
                 tex,
                 len(nama) - (len(nama) - len(selection.parse()))))
示例#6
0
 def openqr(self, to, cmd):
     gid = self.getGroupIdsJoined()
     if len(cmd.split(" ")) == 3:
         selection = mencode(cmd.split(' ')[2], range(1, len(gid) + 1))
         k = len(gid) // 100
         for a in range(k + 1):
             if a == 0: eto = '╭「 QR Group 」─'
             else: eto = ''
             text = ''
             no = 0
             for i in selection.parse()[a * 100:(a + 1) * 100]:
                 group = self.getGroup(gid[i - 1])
                 if group.preventedJoinByTicket == True:
                     group.preventedJoinByTicket = False
                     self.updateGroup(group)
                 no += 1
                 if no == len(selection.parse()):
                     text += "\n│{}. {}\n╰   line://ti/g/{}".format(
                         i,
                         self.getGroup(gid[i - 1]).name,
                         self.reissueGroupTicket(gid[i - 1]))
                 else:
                     text += "\n│{}. {}\n│   line://ti/g/{}".format(
                         i,
                         self.getGroup(gid[i - 1]).name,
                         self.reissueGroupTicket(gid[i - 1]))
             self.sendMessage(to, eto + text)
示例#7
0
 def surahlist(self, msg):
     if msg.text.lower() == "alquran":
         data = self.requestsin("http://api.alquran.cloud/surah")
     if msg.text.lower().startswith("alqur'an "):
         data = self.requestsin("http://api.alquran.cloud/surah/{}".format(
             self.mainsplit(msg.text)))
     if len(msg.text.split(' ')) == 1:
         if data["data"] != []:
             no = 0
             ret_ = "「 Al Qur'an 」\n"
             for music in data["data"]:
                 no += 1
                 if no == len(data['data']):
                     ret_ += "\n{}. {}".format(no, music['englishName'])
                 else:
                     ret_ += "\n{}. {}".format(no, music['englishName'])
             return self.sendMessage(msg.to, ret_)
     if len(msg.text.split(' ')) == 2:
         try:
             no = 0
             ret_ = " 「 Al Qur'an 」\nSurah: {}".format(
                 data['data']['englishName'])
             for music in data["data"]["ayahs"]:
                 no += 1
                 ret_ += "\n{}. {}".format(no, music['text'])
             k = len(ret_) // 9999
             for aa in range(k + 1):
                 self.sendMessage(
                     msg.to, '{}'.format(ret_[aa * 9999:(aa + 1) * 9999]))
         except:
             pass
     if len(msg.text.split(' ')) == 3:
         try:
             nama = data["data"]["ayahs"]
             selection = mencode(self.mainsplit(msg.text.lower(), 's'),
                                 range(1,
                                       len(nama) + 1))
             k = len(nama) // 100
             text = " 「 Al Qur'an 」\nSurah: {}".format(
                 data['data']['englishName'])
             no = 0
             for i in selection.parse():
                 no += 1
                 text += "\n{}. {}".format(i, nama[i - 1]['text'])
             k = len(text) // 10000
             for aa in range(k + 1):
                 self.sendMessage(
                     to, '{}'.format(text[aa * 10000:(aa + 1) * 10000]))
         except:
             pass
示例#8
0
 def delgroups(self, to, cmd):
     gid = self.getGroupIdsJoined()
     if len(cmd.split(" ")) == 3:
         selection = mencode(cmd.split(' ')[2], range(1, len(gid) + 1))
         k = len(gid) // 100
         for a in range(k + 1):
             if a == 0: eto = '╭「 Leave Group 」─'
             else: eto = ''
             text = ''
             no = 0
             for i in selection.parse()[a * 100:(a + 1) * 100]:
                 self.leaveGroup(gid[i - 1])
                 no += 1
                 if no == len(selection.parse()):
                     text += "\n╰{}. {}".format(
                         i,
                         self.getGroup(gid[i - 1]).name)
                 else:
                     text += "\n│{}. {}".format(
                         i,
                         self.getGroup(gid[i - 1]).name)
             self.sendMessage(to, eto + text)
示例#9
0
 def test_encode_and_decode_hash_key(self):
     x = {42: 3}
     y = {'42': 3}
     assert mdecode(mencode(x)) == x
     assert mdecode(mencode(y)) == y
示例#10
0
 def test_encode_and_decode_tuple(self):
     assert mdecode(mencode(())) == []
示例#11
0
 def test_encode_and_decode_int(self):
     assert mdecode(mencode(2)) == 2
示例#12
0
 def test_encode_and_decode_dict(self):
     assert mdecode(mencode({})) == {}
示例#13
0
 def test_encode_and_decode_long(self):
     assert mdecode(mencode(-23452422452342L)) == -23452422452342L
示例#14
0
 def test_encode_and_decode_none(self):
     assert mdecode(mencode(None)) == None
示例#15
0
 def test_encode_and_decode_complex_object(self):
     spam = [[], 0, -3, -345234523543245234523L, {}, 'spam', None, {'a': 3}, {69: []}]
     assert mencode(mdecode(mencode(spam))) == mencode(spam)
     assert mdecode(mencode(spam)) == spam
示例#16
0
 def test_encode_and_decode_list(self):
     assert mdecode(mencode([])) == []
示例#17
0
 def test_preencoded_thing(self):
     thing = {"dirty limmerk": ["there once was a man from peru", "who set out to sail a canoe"]}
     pthing = PreEncodedThing(thing)
     assert len(mencode(thing)) == len(pthing)
     assert mencode(pthing) == mencode(thing)
     assert mdecode(mencode(thing)) == mdecode(mencode(pthing))