Beispiel #1
0
    def getBodyFailed(self, err):
        """ Handle a failure of the BODY command. Ensure the failed segment gets a 0 byte file
        written to the filesystem when this occurs """
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug(str(self) + ' get BODY FAILED, errno: ' + str(err) + \
                      ' for messageId: <' + self.currentSegment.messageId + '> ' + \
                      self.currentSegment.getDestination() + ' expected size: ' + \
                      str(self.currentSegment.bytes))
        self.gotResponseCode = False  # for dataReceivedToFile
        self.lastChunk = ''

        code = extractCode(err)
        if code is not None:
            code, msg = code
            if code in (423, 430):
                try:
                    Hellanzb.queue.requeueMissing(self.factory,
                                                  self.currentSegment)
                    debug(str(self) + ' ' + self.currentSegment.nzbFile.showFilename + \
                          ' segment: ' + str(self.currentSegment.number) + \
                          ' Article is missing! Attempting to requeue on a different pool!')
                    Hellanzb.scroller.removeClient(self.currentSegment,
                                                   self.factory.color)
                    self.resetCurrentSegment(removeEncFile=True)
                    reactor.callLater(0, self.fetchNextNZBSegment)
                    return

                except PoolsExhausted:
                    info(self.currentSegment.nzbFile.showFilename + ' segment: ' + \
                         str(self.currentSegment.number) + ' Article is missing!')

        if self.handle400Message(err):
            return
        self.finishedSegmentDownload()
Beispiel #2
0
    def getBodyFailed(self, err):
        """ Handle a failure of the BODY command. Ensure the failed segment gets a 0 byte file
        written to the filesystem when this occurs """
        if Hellanzb.DEBUG_MODE_ENABLED:
            debug(str(self) + ' get BODY FAILED, errno: ' + str(err) + \
                      ' for messageId: <' + self.currentSegment.messageId + '> ' + \
                      self.currentSegment.getDestination() + ' expected size: ' + \
                      str(self.currentSegment.bytes))
        self.gotResponseCode = False # for dataReceivedToFile
        self.lastChunk = ''
        
        code = extractCode(err)
        if code is not None:
            code, msg = code
            if code in (423, 430):
                try:
                    Hellanzb.queue.requeueMissing(self.factory, self.currentSegment)
                    debug(str(self) + ' ' + self.currentSegment.nzbFile.showFilename + \
                          ' segment: ' + str(self.currentSegment.number) + \
                          ' Article is missing! Attempting to requeue on a different pool!')
                    Hellanzb.scroller.removeClient(self.currentSegment, self.factory.color)
                    self.resetCurrentSegment(removeEncFile = True)
                    reactor.callLater(0, self.fetchNextNZBSegment)
                    return
                
                except PoolsExhausted:
                    info(self.currentSegment.nzbFile.showFilename + ' segment: ' + \
                         str(self.currentSegment.number) + ' Article is missing!')

        if self.handle400Message(err):
            return
        self.finishedSegmentDownload()
Beispiel #3
0
    def dataReceivedToFile(self, data, EOF=EOF, EOFLen=EOFLen):
        """ Dump the raw recieved data to the current segment's encoded-data-temp file. This
        function is faster than parsing the received data into individual lines
        (dataReceivedToLines) -- it simply dumps the data to file, and looks for the EOF
        string for usenet messages: "\r\n.\r\n".

        It manually rstrip()s every chunk of data received, then matches both the
        rstripped data and rstripped-off data with their associated usenet EOF pieces (to
        safely detect the EOF across potentially two data chunks)

        It is smarter about parsing the usenet response code (lineReceived does this for
        dataReceivedToLines and is lazier about it)
        
        Ultimately, significantly less work than dataReceivedToLines """
        if not self.gotResponseCode:
            # find the nntp response in the header of the message (the BODY command)
            if self.lastChunk == '':
                data = data.lstrip()
            else:
                data = self.lastChunk + data

            off = data.find(self.delimiter)
            if off == -1:
                # Haven't received the entire first line yet
                self.lastChunk = data
                return

            line = data[:off]

            code = extractCode(line)
            if code is None or (not (200 <= code[0] < 400)
                                and code[0] != 100):  # An error!
                try:
                    # getBodyFailed or finishedSegmentDownload will close it
                    ##self.currentSegment.encodedDataFile.close()
                    self._error[0](line)
                # FIXME: why is this exception thrown? it was previously breaking
                # connections -- this is now caught to avoid the completely breaking of
                # the connection
                except TypeError, te:
                    debug(str(self) + ' lineReceived GOT TYPE ERROR!: ' + str(te) + ' state name: ' + \
                          self._state[0].__name__ + ' code: ' + str(code) + ' line: ' + line)
                self._endState()
                return
            else:
                self._setResponseCode(code)
                self.gotResponseCode = True
                data = data[off:]
                self.lastChunk = ''
Beispiel #4
0
    def dataReceivedToFile(self, data, EOF=EOF, EOFLen=EOFLen):
        """ Dump the raw recieved data to the current segment's encoded-data-temp file. This
        function is faster than parsing the received data into individual lines
        (dataReceivedToLines) -- it simply dumps the data to file, and looks for the EOF
        string for usenet messages: "\r\n.\r\n".

        It manually rstrip()s every chunk of data received, then matches both the
        rstripped data and rstripped-off data with their associated usenet EOF pieces (to
        safely detect the EOF across potentially two data chunks)

        It is smarter about parsing the usenet response code (lineReceived does this for
        dataReceivedToLines and is lazier about it)
        
        Ultimately, significantly less work than dataReceivedToLines """
        if not self.gotResponseCode:
            # find the nntp response in the header of the message (the BODY command)
            if self.lastChunk == '':
                data = data.lstrip()
            else:
                data = self.lastChunk + data
                
            off = data.find(self.delimiter)
            if off == -1:
                # Haven't received the entire first line yet
                self.lastChunk = data
                return
            
            line = data[:off]

            code = extractCode(line)
            if code is None or (not (200 <= code[0] < 400) and code[0] != 100): # An error!
                try:
                    # getBodyFailed or finishedSegmentDownload will close it
                    ##self.currentSegment.encodedDataFile.close()
                    self._error[0](line)
                # FIXME: why is this exception thrown? it was previously breaking
                # connections -- this is now caught to avoid the completely breaking of
                # the connection
                except TypeError, te:
                    debug(str(self) + ' lineReceived GOT TYPE ERROR!: ' + str(te) + ' state name: ' + \
                          self._state[0].__name__ + ' code: ' + str(code) + ' line: ' + line)
                self._endState()
                return
            else:
                self._setResponseCode(code)
                self.gotResponseCode = True
                data = data[off:]
                self.lastChunk = ''
Beispiel #5
0
 def lineReceived(self, line):
     """ cut & paste from NNTPClient -- also allows 100 codes for HELP responses """
     if not len(self._state):
         self._statePassive(line)
     elif self._getResponseCode() is None:
         code = extractCode(line)
         if code is None or (not (200 <= code[0] < 400) and code[0] != 100):    # An error!
             try:
                 self._error[0](line)
             except TypeError, te:
                 debug(str(self) + ' lineReceived GOT TYPE ERROR!: ' + str(te) + ' state name: ' + \
                       self._state[0].__name__ + ' code: ' + str(code) + ' line: ' + line)
             self._endState()
         else:
             self._setResponseCode(code)
             if self._responseHandlers[0]:
                 self._responseHandlers[0](code)
Beispiel #6
0
 def lineReceived(self, line):
     """ cut & paste from NNTPClient -- also allows 100 codes for HELP responses """
     if not len(self._state):
         self._statePassive(line)
     elif self._getResponseCode() is None:
         code = extractCode(line)
         if code is None or (not (200 <= code[0] < 400)
                             and code[0] != 100):  # An error!
             try:
                 self._error[0](line)
             except TypeError, te:
                 debug(str(self) + ' lineReceived GOT TYPE ERROR!: ' + str(te) + ' state name: ' + \
                       self._state[0].__name__ + ' code: ' + str(code) + ' line: ' + line)
             self._endState()
         else:
             self._setResponseCode(code)
             if self._responseHandlers[0]:
                 self._responseHandlers[0](code)
Beispiel #7
0
 def handle400Message(self, err):
     code = extractCode(err)
     if code is not None:
         code, msg = code
         if code == 400 and \
                 (msg.lower().find('idle timeout') > -1 or \
                  msg.lower().find('session timeout') > -1):
             # Handle:
             # 2005-05-05 14:41:18,232 DEBUG NZBLeecher[7] get BODY FAILED, error: 400
             # fe01-unl.iad01.newshosting.com: Idle timeout. for messageId:
             # <part59of201.2T6kmGJqWQXOuewjuk&[email protected]>
             # 2005-05-13 08:25:23,260 DEBUG NZBLeecher[24] get BODY FAILED, error: 400
             # fe02-unl.iad01.newshosting.com: Session timeout. for messageId:
             # <*****@*****.**>
              
             # fine, be that way
             debug(str(self) + ' received Session/Idle TIMEOUT from server, disconnecting')
             self.transport.loseConnection()
             return True
     return False
Beispiel #8
0
    def handle400Message(self, err):
        code = extractCode(err)
        if code is not None:
            code, msg = code
            if code == 400 and \
                    (msg.lower().find('idle timeout') > -1 or \
                     msg.lower().find('session timeout') > -1):
                # Handle:
                # 2005-05-05 14:41:18,232 DEBUG NZBLeecher[7] get BODY FAILED, error: 400
                # fe01-unl.iad01.newshosting.com: Idle timeout. for messageId:
                # <part59of201.2T6kmGJqWQXOuewjuk&[email protected]>
                # 2005-05-13 08:25:23,260 DEBUG NZBLeecher[24] get BODY FAILED, error: 400
                # fe02-unl.iad01.newshosting.com: Session timeout. for messageId:
                # <*****@*****.**>

                # fine, be that way
                debug(
                    str(self) +
                    ' received Session/Idle TIMEOUT from server, disconnecting'
                )
                self.transport.loseConnection()
                return True
        return False