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
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
def test_paginate_none(self): self.assertEqual( self._list_from_paginated(paginate(list(range(9)), 9)), [list(range(9))] )
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]], )
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]], )
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]], )
def test_paginate_none(self): self.assertEqual(self._list_from_paginated(paginate(range(9), 9)), [list(range(9))] )
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]] )
def test_paginate_even(self): self.assertEqual(self._list_from_paginated(paginate(range(9), 3)), [[0,1,2], [3,4,5], [6,7,8]] )
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]] )