uuencode/uudecode main program
()
| 175 | f.close() |
| 176 | |
| 177 | def test(): |
| 178 | """uuencode/uudecode main program""" |
| 179 | |
| 180 | import optparse |
| 181 | parser = optparse.OptionParser(usage='usage: %prog [-d] [-t] [input [output]]') |
| 182 | parser.add_option('-d', '--decode', dest='decode', help='Decode (instead of encode)?', default=False, action='store_true') |
| 183 | parser.add_option('-t', '--text', dest='text', help='data is text, encoded format unix-compatible text?', default=False, action='store_true') |
| 184 | |
| 185 | (options, args) = parser.parse_args() |
| 186 | if len(args) > 2: |
| 187 | parser.error('incorrect number of arguments') |
| 188 | sys.exit(1) |
| 189 | |
| 190 | # Use the binary streams underlying stdin/stdout |
| 191 | input = sys.stdin.buffer |
| 192 | output = sys.stdout.buffer |
| 193 | if len(args) > 0: |
| 194 | input = args[0] |
| 195 | if len(args) > 1: |
| 196 | output = args[1] |
| 197 | |
| 198 | if options.decode: |
| 199 | if options.text: |
| 200 | if isinstance(output, str): |
| 201 | output = open(output, 'wb') |
| 202 | else: |
| 203 | print(sys.argv[0], ': cannot do -t to stdout') |
| 204 | sys.exit(1) |
| 205 | decode(input, output) |
| 206 | else: |
| 207 | if options.text: |
| 208 | if isinstance(input, str): |
| 209 | input = open(input, 'rb') |
| 210 | else: |
| 211 | print(sys.argv[0], ': cannot do -t from stdin') |
| 212 | sys.exit(1) |
| 213 | encode(input, output) |
| 214 | |
| 215 | if __name__ == '__main__': |
| 216 | test() |
no test coverage detected