示例#1
0
def format_picture(pic_data, pic_type):
    """ Convert @pic_data to base64 and align properly with VCard prefix.

    pic_type: one of JPEG or PNG
    """
    pic_b64 = ''.join(pic_data.encode('base64').strip().split('\n'))
    prefix = "PHOTO;ENCODING=b;TYPE=%s:" % pic_type
    pic_lines = []
    pic_lines += [' %s' % ''.join(list(line)) for line in paginate(pic_b64[75-len(prefix):], 74)]
    picture = prefix + pic_b64[0:75-len(prefix)] + '\n'
    picture += '\n'.join(pic_lines) + '\n'
    return picture
示例#2
0
def format_picture(pic_data, pic_type):
    """ Convert @pic_data to base64 and align properly with VCard prefix.

    pic_type: one of JPEG or PNG
    """
    pic_b64 = ''.join(pic_data.encode('base64').strip().split('\n'))
    prefix = "PHOTO;ENCODING=b;TYPE=%s:" % pic_type
    pic_lines = []
    pic_lines += [
        ' %s' % ''.join(list(line))
        for line in paginate(pic_b64[75 - len(prefix):], 74)
    ]
    picture = prefix + pic_b64[0:75 - len(prefix)] + '\n'
    picture += '\n'.join(pic_lines) + '\n'
    return picture
示例#3
0
 def test_paginate_none(self):
     self.assertEqual(
         self._list_from_paginated(paginate(list(range(9)), 9)), [list(range(9))]
     )
示例#4
0
 def test_paginate_by_one(self):
     self.assertEqual(
         self._list_from_paginated(paginate(list(range(9)), 1)),
         [[0], [1], [2], [3], [4], [5], [6], [7], [8]],
     )
示例#5
0
 def test_paginate_even(self):
     self.assertEqual(
         self._list_from_paginated(paginate(list(range(9)), 3)),
         [[0, 1, 2], [3, 4, 5], [6, 7, 8]],
     )
示例#6
0
 def test_paginate_simple(self):
     self.assertEqual(
         self._list_from_paginated(paginate(list(range(10)), 3)),
         [[0, 1, 2], [3, 4, 5], [6, 7, 8], [9]],
     )
示例#7
0
 def test_paginate_none(self):
     self.assertEqual(self._list_from_paginated(paginate(range(9), 9)),
                      [list(range(9))]
                      )
示例#8
0
 def test_paginate_by_one(self):
     self.assertEqual(self._list_from_paginated(paginate(range(9), 1)),
                      [[0],[1],[2],[3],[4],[5],[6],[7],[8]]
                      )
示例#9
0
 def test_paginate_even(self):
     self.assertEqual(self._list_from_paginated(paginate(range(9), 3)),
                      [[0,1,2], [3,4,5], [6,7,8]]
                      )
示例#10
0
 def test_paginate_simple(self):
     self.assertEqual(self._list_from_paginated(paginate(range(10), 3)),
                      [[0,1,2], [3,4,5], [6,7,8], [9]]
                      )