示例#1
0
def decodeSegmentToFile(segment, encodingType = YENCODE):
    """ Decode the clean data (clean as in it's headers (mime and yenc/uudecode) have been
    removed) list to the specified destination """
    decodedLines = []

    if encodingType == YENCODE:
        message = None
        if Hellanzb.HAVE_C_YENC:
            decoded, crc, cruft = yDecode(segment.articleData)
            
            # CRC check. FIXME: use yDecodeCRCCheck for this!
            if segment.yCrc is None:
                passedCRC = False
                message = segment.nzbFile.showFilename + ' segment: ' + str(segment.number) + \
                    ' does not have a valid CRC/yend line!'
            else:
                crc = '%08X' % ((crc ^ -1) & 2**32L - 1)
                passedCRC = crc == segment.yCrc
                if not passedCRC:
                    message = segment.nzbFile.showFilename + ' segment ' + str(segment.number) + \
                        ': CRC mismatch ' + crc + ' != ' + segment.yCrc
            
        else:
            decoded = yDecode(segment.articleData)

            # CRC check
            passedCRC, message = yDecodeCRCCheck(segment, decoded)

        # Write the decoded segment to disk
        size = len(decoded)

        # Handle dupes if they exist
        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return YENCODE, None

        filename = segment.getDestination()
        if not passedCRC:
            filename += '-hellafailed_%s' % segment.fromServer.factory.serverPoolName
        out = open(filename, 'wb')
        try:
            out.write(decoded)
        except IOError, ioe:
            out.close()
            handleIOError(ioe) # will re-raise
        out.close()
              
        if passedCRC:
            # File size check vs ydecode header. We only do the file size check if the CRC
            # passed. If the CRC didn't pass the CRC check, the file size check will most
            # likely fail as well, so we skip it
            yDecodeFileSizeCheck(segment, size)
        else:
            return YENCODE_CRC_FAILED, message

        return YENCODE, None
示例#2
0
def decodeSegmentToFile(segment, encodingType = YENCODE):
    """ Decode the clean data (clean as in it's headers (mime and yenc/uudecode) have been
    removed) list to the specified destination """
    decodedLines = []

    if encodingType == YENCODE:
        message = None
        if Hellanzb.HAVE_C_YENC:
            decoded, crc, cruft = yDecode(segment.articleData)
            
            # CRC check. FIXME: use yDecodeCRCCheck for this!
            if segment.yCrc is None:
                passedCRC = False
                message = segment.nzbFile.showFilename + ' segment: ' + str(segment.number) + \
                    ' does not have a valid CRC/yend line!'
            else:
                crc = '%08X' % ((crc ^ -1) & 2**32L - 1)
                passedCRC = crc == segment.yCrc
                if not passedCRC:
                    message = segment.nzbFile.showFilename + ' segment ' + str(segment.number) + \
                        ': CRC mismatch ' + crc + ' != ' + segment.yCrc
            
        else:
            decoded = yDecode(segment.articleData)

            # CRC check
            passedCRC, message = yDecodeCRCCheck(segment, decoded)

        # Write the decoded segment to disk
        size = len(decoded)

        # Handle dupes if they exist
        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return YENCODE, None

        filename = segment.getDestination()
        if not passedCRC:
            filename += '-hellafailed_%s' % segment.fromServer.factory.serverPoolName
        out = open(filename, 'wb')
        try:
            out.write(decoded)
        except IOError, ioe:
            out.close()
            handleIOError(ioe) # will re-raise
        out.close()
              
        if passedCRC:
            # File size check vs ydecode header. We only do the file size check if the CRC
            # passed. If the CRC didn't pass the CRC check, the file size check will most
            # likely fail as well, so we skip it
            yDecodeFileSizeCheck(segment, size)
        else:
            return YENCODE_CRC_FAILED, message

        return YENCODE, None
示例#3
0
            # likely fail as well, so we skip it
            yDecodeFileSizeCheck(segment, size)
        else:
            return YENCODE_CRC_FAILED, message

        return YENCODE, None

    elif encodingType == UUENCODE:
        decodedLines = []
        try:
            decodedLines = UUDecode(segment.articleData)
        except binascii.Error, msg:
            error('UUDecode failed in file: %s (part number: %d) error: %s' % \
                  (segment.getDestination(), segment.number, msg))

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UUENCODE, None
        
        # Write the decoded segment to disk
        writeLines(segment.getDestination(), decodedLines)

        return UUENCODE, None

    elif segment.articleData == '':
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('NO articleData, touching file: ' + segment.getDestination())

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UNKNOWN, None
示例#4
0
            # likely fail as well, so we skip it
            yDecodeFileSizeCheck(segment, size)
        else:
            return YENCODE_CRC_FAILED, message

        return YENCODE, None

    elif encodingType == UUENCODE:
        decodedLines = []
        try:
            decodedLines = UUDecode(segment.articleData)
        except binascii.Error, msg:
            error('UUDecode failed in file: %s (part number: %d) error: %s' % \
                  (segment.getDestination(), segment.number, msg))

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UUENCODE, None
        
        # Write the decoded segment to disk
        writeLines(segment.getDestination(), decodedLines)

        return UUENCODE, None

    elif segment.articleData == '':
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('NO articleData, touching file: ' + segment.getDestination())

        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return UNKNOWN, None