%PDF- %PDF-
Direktori : /usr/lib/cups/driver/ |
Current File : //usr/lib/cups/driver/pxljr |
#!/usr/bin/env python3 # compressor.py from subprocess import Popen, PIPE def compress(value): """Compresses a byte array with the xz binary""" process = Popen(["xz", "--compress", "--force"], stdin=PIPE, stdout=PIPE) return process.communicate(value)[0] def decompress(value): """Decompresses a byte array with the xz binary""" process = Popen(["xz", "--decompress", "--stdout", "--force"], stdin=PIPE, stdout=PIPE) return process.communicate(value)[0] def compress_file(path): """Compress the file at 'path' with the xz binary""" process = Popen(["xz", "--compress", "--force", "--stdout", path], stdout=PIPE) return process.communicate()[0] # compressor.py import os import sys from optparse import OptionParser from sys import argv import base64 import json from io import BytesIO from os.path import basename from errno import EPIPE import lzma def load(): ppds_compressed = base64.b64decode(ppds_compressed_b64) ppds_decompressed = decompress(ppds_compressed) ppds = json.loads(ppds_decompressed.decode(encoding='ASCII')) return ppds def ls(): binary_name = basename(argv[0]) ppds = load() for key, value in ppds.items(): if key == 'ARCHIVE': continue for ppd in value[2]: try: print(ppd.replace('"', '"' + binary_name + ':', 1)) except IOError as e: # Errors like broken pipes (program which takes the standard # output terminates before this program terminates) should not # generate a traceback. if e.errno == EPIPE: exit(0) raise def cat(ppd): # Ignore driver's name, take only PPD's ppd = ppd.split(":")[-1] # Remove also the index ppd = "0/" + ppd[ppd.find("/")+1:] # Object for streaming decompression decompressor = lzma.LZMADecompressor() # size for one decompression i.e. ~20MB size = 20000000 ppds = load() ppds['ARCHIVE'] = base64.b64decode(ppds['ARCHIVE'].encode('ASCII')) ppdtext=bytearray() if ppd in ppds: start = ppds[ppd][0] length = ppds[ppd][1] text = BytesIO(decompressor.decompress(ppds['ARCHIVE'],size)) for i in range(int(start/size)): text = BytesIO(decompressor.decompress(ppds['ARCHIVE'],size)) text.seek(start%size) if((size-(start%size)) < length): ppdtext.extend(text.read()) length = length - (size-(start%size)) text = BytesIO(decompressor.decompress(ppds['ARCHIVE'],size)) while(size < length): ppdtext.extend(text.read()) length = length - size text = BytesIO(decompressor.decompress(ppds['ARCHIVE'],size)) ppdtext.extend(text.read(length)) else: ppdtext.extend(text.read(length)) return ppdtext def main(): usage = "usage: %prog list\n" \ " %prog cat URI" version = "%prog 1.1.0\n" \ "Copyright (c) 2013 Vitor Baptista.\n" \ "This is free software; see the source for copying conditions.\n" \ "There is NO warranty; not even for MERCHANTABILITY or\n" \ "FITNESS FOR A PARTICULAR PURPOSE." parser = OptionParser(usage=usage, version=version) (options, args) = parser.parse_args() if len(args) == 0 or len(args) > 2: parser.error("incorrect number of arguments") if args[0].lower() == 'list': ls() elif args[0].lower() == 'cat': if not len(args) == 2: parser.error("incorrect number of arguments") ppd = cat(args[1]) if not ppd: parser.error("Printer '%s' does not have default driver!" % args[1]) try: # avoid any assumption of encoding or system locale; just print the # bytes of the PPD as they are if sys.version_info.major < 3: sys.stdout.write(ppd) else: sys.stdout.buffer.write(ppd) except IOError as e: # Errors like broken pipes (program which takes the standard output # terminates before this program terminates) should not generate a # traceback. if e.errno == EPIPE: exit(0) raise else: parser.error("argument " + args[0] + " invalid") # PPDs Archive ppds_compressed_b64 = b"/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4Bc8ERJdAD2IggMSmC9yvLZRrzMRHujavOoKYFlPTyBHOz5Ha6tWtlqwzkWnlGIwKJ54p+QdtDwrm7omxmyDowHYowdnZHFr8uBEI8MnUxxJ6mLOSigNhd5SrF6jbUgEPOUbSsgaSdq9++stxsDuRSnGntPQ1I3DH8Md7SX9eIGaFEfNybnnKsqeELJ7umkxLCEcprap53OQ24vSwZ5wUyI2fwZVyvSw2rjX76kqbeiPGgFKlSEy4lcXb2K+lFlByk3zvRWGX80CYT2GnMZwUd/653RCYDbiyPRuc2LwOQ+KxdPfO5q8OUELObQwXiXzlQci7YtItxseebPIQngv0cJnac7NNmZN9b7M2Ypk4m4KZjpR2H3a3VbFU025KSTEY33laemRTHRkrXoScnInDK462kAoKPMK7oyimv9EpQXwg9L/hrXGyD+ds160P10DxGn3oKnW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axxGf7AgAAAAAEWVo=" if __name__ == "__main__": try: main() except KeyboardInterrupt: # We don't want a KeyboardInterrupt throwing a # traceback into stdout. pass