1 # Copyright (C) 2013-2020 Roland Lutz
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 def throws(fun
, *args
, **kwds
):
23 except Exception as e
:
27 '\x3f\x98\xd2\xd0\xad\x4b\xa8\xbf\x5b\x58\x7b\xcd\x40\x6c\x27\xba' \
28 '\x80\xc1\x29\x86\x86\x26\xc4\x0b\xc5\x29\x32\x8a\x29\x36\xfd\xa9' \
29 '\x1b\x0b\x1b\xfd\x18\xfb\xbb\xc5\x45\xb3\x66\x54\x3c\x2b\x9e\x9b' \
30 '\xff\x5d\xb7\x64\x3c\x92\xf2\xdb\x8c\xb0\x02\x96\x3f\x51\xd0\x35' \
31 '\x6d\x70\x2c\xb9\x8c\x0b\x89\xc6\xbb\xcd\xf9\x1d\xc6\x27\x33\x58' \
32 '\xd5\x84\x32\x11\xe5\xd3\xd2\x77\x36\x17\xc3\xa3\xa8\xcb\x0e\x16' \
33 '\x4d\x1d\xc9\x22\x61\xed\xb0\xb2\xbb\xfe\xd7\x03\xae\x03\xa8\x37' \
34 '\x11\xda\xc3\x57\x11\xf1\x35\x01'
37 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQLxSkyiik2\n',
38 '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS8tuMsAKW\n',
39 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR5dPSdzYX\n',
40 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHaw1cR8TUB\n'
41 ][:i
]) for i
in xrange(5)]
48 lines
[0] + 'P5jS0A==\n',
49 lines
[0] + 'P5jS0K0=\n',
50 lines
[0] + 'P5jS0K1L\n',
51 lines
[0] + 'P5jS0K1LqA==\n',
52 lines
[0] + 'P5jS0K1LqL8=\n',
53 lines
[0] + 'P5jS0K1LqL9b\n',
54 lines
[0] + 'P5jS0K1LqL9bWA==\n',
55 lines
[0] + 'P5jS0K1LqL9bWHs=\n',
56 lines
[0] + 'P5jS0K1LqL9bWHvN\n',
57 lines
[0] + 'P5jS0K1LqL9bWHvNQA==\n',
58 lines
[0] + 'P5jS0K1LqL9bWHvNQGw=\n',
59 lines
[0] + 'P5jS0K1LqL9bWHvNQGwn\n',
60 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnug==\n',
61 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoA=\n',
62 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDB\n',
63 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKQ==\n',
64 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYY=\n',
65 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaG\n',
66 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJg==\n',
67 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQ=\n',
68 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQL\n',
69 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQLxQ==\n',
70 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQLxSk=\n',
71 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQLxSky\n',
72 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQLxSkyig==\n',
73 lines
[0] + 'P5jS0K1LqL9bWHvNQGwnuoDBKYaGJsQLxSkyiik=\n',
78 lines
[1] + '/akbCw==\n',
79 lines
[1] + '/akbCxs=\n',
80 lines
[1] + '/akbCxv9\n',
81 lines
[1] + '/akbCxv9GA==\n',
82 lines
[1] + '/akbCxv9GPs=\n',
83 lines
[1] + '/akbCxv9GPu7\n',
84 lines
[1] + '/akbCxv9GPu7xQ==\n',
85 lines
[1] + '/akbCxv9GPu7xUU=\n',
86 lines
[1] + '/akbCxv9GPu7xUWz\n',
87 lines
[1] + '/akbCxv9GPu7xUWzZg==\n',
88 lines
[1] + '/akbCxv9GPu7xUWzZlQ=\n',
89 lines
[1] + '/akbCxv9GPu7xUWzZlQ8\n',
90 lines
[1] + '/akbCxv9GPu7xUWzZlQ8Kw==\n',
91 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K54=\n',
92 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b\n',
93 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/w==\n',
94 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/10=\n',
95 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123\n',
96 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZA==\n',
97 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDw=\n',
98 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS\n',
99 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS8g==\n',
100 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS8ts=\n',
101 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS8tuM\n',
102 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS8tuMsA==\n',
103 lines
[1] + '/akbCxv9GPu7xUWzZlQ8K56b/123ZDyS8tuMsAI=\n',
108 lines
[2] + 'P1HQNQ==\n',
109 lines
[2] + 'P1HQNW0=\n',
110 lines
[2] + 'P1HQNW1w\n',
111 lines
[2] + 'P1HQNW1wLA==\n',
112 lines
[2] + 'P1HQNW1wLLk=\n',
113 lines
[2] + 'P1HQNW1wLLmM\n',
114 lines
[2] + 'P1HQNW1wLLmMCw==\n',
115 lines
[2] + 'P1HQNW1wLLmMC4k=\n',
116 lines
[2] + 'P1HQNW1wLLmMC4nG\n',
117 lines
[2] + 'P1HQNW1wLLmMC4nGuw==\n',
118 lines
[2] + 'P1HQNW1wLLmMC4nGu80=\n',
119 lines
[2] + 'P1HQNW1wLLmMC4nGu835\n',
120 lines
[2] + 'P1HQNW1wLLmMC4nGu835HQ==\n',
121 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcY=\n',
122 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYn\n',
123 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnMw==\n',
124 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1g=\n',
125 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jV\n',
126 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhA==\n',
127 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDI=\n',
128 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR\n',
129 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR5Q==\n',
130 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR5dM=\n',
131 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR5dPS\n',
132 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR5dPSdw==\n',
133 lines
[2] + 'P1HQNW1wLLmMC4nGu835HcYnM1jVhDIR5dPSdzY=\n',
138 lines
[3] + 'w6Ooyw==\n',
139 lines
[3] + 'w6Ooyw4=\n',
140 lines
[3] + 'w6Ooyw4W\n',
141 lines
[3] + 'w6Ooyw4WTQ==\n',
142 lines
[3] + 'w6Ooyw4WTR0=\n',
143 lines
[3] + 'w6Ooyw4WTR3J\n',
144 lines
[3] + 'w6Ooyw4WTR3JIg==\n',
145 lines
[3] + 'w6Ooyw4WTR3JImE=\n',
146 lines
[3] + 'w6Ooyw4WTR3JImHt\n',
147 lines
[3] + 'w6Ooyw4WTR3JImHtsA==\n',
148 lines
[3] + 'w6Ooyw4WTR3JImHtsLI=\n',
149 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7\n',
150 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/g==\n',
151 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tc=\n',
152 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcD\n',
153 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrg==\n',
154 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgM=\n',
155 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOo\n',
156 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNw==\n',
157 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxE=\n',
158 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHa\n',
159 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHaww==\n',
160 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHaw1c=\n',
161 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHaw1cR\n',
162 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHaw1cR8Q==\n',
163 lines
[3] + 'w6Ooyw4WTR3JImHtsLK7/tcDrgOoNxHaw1cR8TU=\n',
167 for count
in xrange(len(expected
)):
170 s
= StringIO
.StringIO()
171 xorn
.base64
.encode(s
, data
[:count
], columns
= 40)
172 assert s
.getvalue() == expected
[count
]
174 s
= StringIO
.StringIO()
175 xorn
.base64
.encode(s
, data
[:count
], columns
= None)
177 assert s
.getvalue() == ''
179 assert s
.getvalue() == expected
[count
].replace('\n', '') + '\n'
181 s
= StringIO
.StringIO()
182 xorn
.base64
.encode(s
, data
[:count
], columns
= 40, delim
= '@@@')
183 assert s
.getvalue() == expected
[count
] + '@@@\n'
185 s
= StringIO
.StringIO()
186 xorn
.base64
.encode(s
, data
[:count
], columns
= None, delim
= '@@@')
188 assert s
.getvalue() == '@@@\n'
190 assert s
.getvalue() == expected
[count
].replace('\n', '') + '\n@@@\n'
194 s
= StringIO
.StringIO(expected
[count
])
195 assert xorn
.base64
.decode(s
) == data
[:count
]
196 assert throws(s
.next
) == StopIteration
198 s
= StringIO
.StringIO(expected
[count
])
199 assert throws(xorn
.base64
.decode
, s
, delim
= '@@@') \
200 == xorn
.base64
.DecodingError
202 s
= StringIO
.StringIO(expected
[count
] + '@@@\n%%%\n')
203 assert xorn
.base64
.decode(s
, delim
= '@@@') == data
[:count
]
204 assert s
.next() == '%%%\n'
205 assert throws(s
.next
) == StopIteration
207 s
= StringIO
.StringIO(expected
[count
] + '=')
208 assert throws(xorn
.base64
.decode
, s
) == xorn
.base64
.DecodingError