Logo Search packages:      
Sourcecode: hellanzb version File versions  Download package

def Hellanzb::NZBLeecher::ArticleDecoder::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 

Definition at line 417 of file ArticleDecoder.py.

00417                                                         :
    """ 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:
        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
                # FIXME: I've seen CRC errors at the end of archive cause logNow = True to
                # print I think after handleNZBDone appends a newline (looks like crap)
                error(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
                    error(message)
            
        else:
            decoded = yDecode(segment.articleData)

            # CRC check
            passedCRC = yDecodeCRCCheck(segment, decoded)

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

        # Handle dupes if they exist
        handleDupeNZBSegment(segment)
        if handleCanceledSegment(segment):
            return YENCODE
        
        out = open(segment.getDestination(), '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)

        return YENCODE

    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
        
        # Write the decoded segment to disk
        writeLines(segment.getDestination(), decodedLines)

        return UUENCODE

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

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

        touch(segment.getDestination())

    else:
        # FIXME: should this be an info instead of debug? Should probably change the
        # above: articleData == '' check to articleData.strip() == ''. that block would
        # cover all null articleData and would be safer to always info() about
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug('Mysterious data, did not YY/UDecode!! Touching file: ' + \
                  segment.getDestination())

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

        touch(segment.getDestination())

    return UNKNOWN

# Build the yEnc decode table
YDEC_TRANS = ''.join([chr((i + 256 - 42) % 256) for i in range(256)])


Generated by  Doxygen 1.6.0   Back to index