Пример #1
0
 def decode(self, optionsMap):
     inputStream = BufferedInputStream(sys.stdin)
     outputStream = BufferedOutputStreamWrapper(FileOutputStream(sys.stdout))
     standardInput = True
     standardOutput = True
     for keyOriginal in optionsMap:
         key = keyOriginal.lower()
         if key == "fi":
             fileHandle = open(optionsMap[keyOriginal], "rb")
             inputStream = BufferedInputStream(fileHandle)
             standardInput = False
         elif key == "fo":
             fileName = optionsMap[keyOriginal]
             outputStream = BufferedOutputStreamWrapper(
                 DelayedFileOutputStream(fileName))
             standardOutput = False
         else:
             self.err("Not suitable or unknown option: " + keyOriginal)
             return
     Coder.decode(inputStream, outputStream, 65536)
     outputStream.flush()
     allDecoded = inputStream.readByte() == -1
     if not standardInput:
         inputStream.close()
     if not standardOutput:
         outputStream.close()
     if not allDecoded:
         raise IOError("Not entire input was decoded.")
Пример #2
0
 def decode(self, optionsMap):
     inputStream = BufferedInputStream(sys.stdin)
     outputStream = BufferedOutputStreamWrapper(FileOutputStream(
         sys.stdout))
     standardInput = True
     standardOutput = True
     for keyOriginal in optionsMap:
         key = keyOriginal.lower()
         if key == "fi":
             fileHandle = open(optionsMap[keyOriginal], "rb")
             inputStream = BufferedInputStream(fileHandle)
             standardInput = False
         elif key == "fo":
             fileName = optionsMap[keyOriginal]
             outputStream = BufferedOutputStreamWrapper(
                 DelayedFileOutputStream(fileName))
             standardOutput = False
         else:
             self.err("Not suitable or unknown option: " + keyOriginal)
             return
     Coder.decode(inputStream, outputStream, 65536)
     outputStream.flush()
     allDecoded = inputStream.readByte() == -1
     if not standardInput:
         inputStream.close()
     if not standardOutput:
         outputStream.close()
     if not allDecoded:
         raise IOError("Not entire input was decoded.")
Пример #3
0
 def encode(self, optionsMap):
     inputStream = BufferedInputStream(sys.stdin)
     outputStream = BufferedOutputStreamWrapper(FileOutputStream(
         sys.stdout))
     standardInput = True
     standardOutput = True
     options = Options.getDefault()
     for keyOriginal in optionsMap:
         key = keyOriginal.lower()
         if key == "fi":
             fileHandle = open(optionsMap[keyOriginal], "rb")
             inputStream = BufferedInputStream(fileHandle)
             standardInput = False
         elif key == "fo":
             fileName = optionsMap[keyOriginal]
             outputStream = BufferedOutputStreamWrapper(
                 DelayedFileOutputStream(fileName))
             standardOutput = False
         elif key == "lzpLowContextLength".lower():
             options.lzpLowContextLength = int(optionsMap[keyOriginal])
         elif key == "lzpLowMaskSize".lower():
             options.lzpLowMaskSize = int(optionsMap[keyOriginal])
         elif key == "lzpHighContextLength".lower():
             options.lzpHighContextLength = int(optionsMap[keyOriginal])
         elif key == "lzpHighMaskSize".lower():
             options.lzpHighMaskSize = int(optionsMap[keyOriginal])
         elif key == "literalCoderOrder".lower():
             options.literalCoderOrder = int(optionsMap[keyOriginal])
         elif key == "literalCoderInit".lower():
             options.literalCoderInit = int(optionsMap[keyOriginal])
         elif key == "literalCoderStep".lower():
             options.literalCoderStep = int(optionsMap[keyOriginal])
         elif key == "literalCoderLimit".lower():
             options.literalCoderLimit = int(optionsMap[keyOriginal])
         else:
             self.err("Not suitable or unknown option: " + keyOriginal)
             return
     if not options.isValid():
         self.err("Wrong encoding options combination.")
         return
     Coder.encode(inputStream, outputStream, 65536, options)
     outputStream.flush()
     if not standardInput:
         inputStream.close()
     if not standardOutput:
         outputStream.close()
Пример #4
0
 def encode(self, optionsMap):
     inputStream = BufferedInputStream(sys.stdin)
     outputStream = BufferedOutputStreamWrapper(FileOutputStream(sys.stdout))
     standardInput = True
     standardOutput = True
     options = Options.getDefault()
     for keyOriginal in optionsMap:
         key = keyOriginal.lower()
         if key == "fi":
             fileHandle = open(optionsMap[keyOriginal], "rb")
             inputStream = BufferedInputStream(fileHandle)
             standardInput = False
         elif key == "fo":
             fileName = optionsMap[keyOriginal]
             outputStream = BufferedOutputStreamWrapper(
                 DelayedFileOutputStream(fileName))
             standardOutput = False
         elif key == "lzpLowContextLength".lower():
             options.lzpLowContextLength = int(optionsMap[keyOriginal])
         elif key == "lzpLowMaskSize".lower():
             options.lzpLowMaskSize = int(optionsMap[keyOriginal])
         elif key == "lzpHighContextLength".lower():
             options.lzpHighContextLength = int(optionsMap[keyOriginal])
         elif key == "lzpHighMaskSize".lower():
             options.lzpHighMaskSize = int(optionsMap[keyOriginal])
         elif key == "literalCoderOrder".lower():
             options.literalCoderOrder = int(optionsMap[keyOriginal])
         elif key == "literalCoderInit".lower():
             options.literalCoderInit = int(optionsMap[keyOriginal])
         elif key == "literalCoderStep".lower():
             options.literalCoderStep = int(optionsMap[keyOriginal])
         elif key == "literalCoderLimit".lower():
             options.literalCoderLimit = int(optionsMap[keyOriginal])
         else:
             self.err("Not suitable or unknown option: " + keyOriginal)
             return
     if not options.isValid():
         self.err("Wrong encoding options combination.")
         return
     Coder.encode(inputStream, outputStream, 65536, options)
     outputStream.flush()
     if not standardInput:
         inputStream.close()
     if not standardOutput:
         outputStream.close()
Пример #5
0
 def showOptions(self, optionsMap):
     inputStream = BufferedInputStream(sys.stdin)
     standardInput = True
     for keyOriginal in optionsMap:
         key = keyOriginal.lower()
         if key == "fi":
             fileHandle = open(optionsMap[keyOriginal], "rb")
             inputStream = BufferedInputStream(fileHandle)
             standardInput = False
         else:
             self.err("Not suitable or unknown option: " + keyOriginal)
             return
     options = Coder.getOptions(inputStream)
     self.err(repr(options))
     if not standardInput:
         inputStream.close()
Пример #6
0
 def showOptions(self, optionsMap):
     inputStream = BufferedInputStream(sys.stdin)
     standardInput = True
     for keyOriginal in optionsMap:
         key = keyOriginal.lower()
         if key == "fi":
             fileHandle = open(optionsMap[keyOriginal], "rb")
             inputStream = BufferedInputStream(fileHandle)
             standardInput = False
         else:
             self.err("Not suitable or unknown option: " + keyOriginal)
             return
     options = Coder.getOptions(inputStream)
     self.err(repr(options))
     if not standardInput:
         inputStream.close()