def _aggregate_senddata(self, url):
     try:
         h = urlopen(url)
         h.read()
         h.close()
     except:
         return
 def _aggregate_senddata(self, url):
     try:
         h = urlopen(url)
         h.read()
         h.close()
     except:
         return
Example #3
0
    def _rerequest_single(self, t, s, l):
        try:
            closer = [None]

            def timedout(self=self, l=l, closer=closer):
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(
                            self.log_prefix +
                            '_rerequest_single:timedout: unwait: l', l, 't', t,
                            'thread',
                            currentThread().name)
                    self.errorcodes[
                        'troublecode'] = 'Problem connecting to tracker - timeout exceeded'
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single:timedout: no trip: l', l, 't', t,
                        'thread',
                        currentThread().name)
                try:
                    closer[0]()
                except:
                    pass

            self.externalsched(timedout, self.timeout)
            err = None
            try:
                if DEBUG or DEBUG_ANNOUNCE:
                    log(self.log_prefix + '_rerequest_single: request tracker',
                        merge_announce(t, s), 'thread',
                        currentThread().name)
                h = urlopen(merge_announce(t, s), silent=True)
                closer[0] = h.close
                data = h.read()
            except (IOError, socket.error) as e:
                err = 'Problem connecting to tracker - ' + str(e)
                if DEBUG:
                    log(self.log_prefix +
                        '_rerequest_single: failed to connect to tracker')
            except:
                err = 'Problem connecting to tracker'
                if DEBUG:
                    log(self.log_prefix +
                        '_rerequest_single: failed to connect to tracker')

            try:
                h.close()
            except:
                pass

            if err:
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(
                            self.log_prefix +
                            '_rerequest_single: got error, unwait: l', l, 't',
                            t, 'thread',
                            currentThread().name, 'err', err)
                    self.errorcodes['troublecode'] = err
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single: got error, no trip: l', l, 't', t,
                        'thread',
                        currentThread().name, 'err', err)
                return
            if not data:
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(
                            self.log_prefix +
                            '_rerequest_single: no date, unwait: l', l, 't', t,
                            'thread',
                            currentThread().name)
                    self.errorcodes['troublecode'] = 'no data from tracker'
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single: no data, no trip: l', l, 't', t,
                        'thread',
                        currentThread().name)
                return
            try:
                r = bdecode(data, sloppy=1)
                if DEBUG or DEBUG_ANNOUNCE:
                    log(
                        self.log_prefix +
                        '_rerequest_single: respose from tracker: t', t, 'r',
                        r, 'thread',
                        currentThread().name)
                check_peers(r)
            except ValueError as e:
                if DEBUG:
                    log_exc()
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(
                            self.log_prefix +
                            '_rerequest_single: exception while decoding data, unwait: l',
                            l, 't', t, 'thread',
                            currentThread().name)
                    self.errorcodes[
                        'bad_data'] = 'bad data from tracker - ' + str(e)
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single: exception while decoding data, no trip: l',
                        l, 't', t, 'thread',
                        currentThread().name)
                return

            if r.has_key('failure reason'):
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(
                            self.log_prefix +
                            '_rerequest_single: got failure reason, unwait: l',
                            l, 't', t, 'thread',
                            currentThread().name)
                    self.errorcodes['rejected'] = self.rejectedmessage + r[
                        'failure reason']
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single: got failure reason, no trip: l', l,
                        't', t, 'thread',
                        currentThread().name)
                return
            if self.lock.trip(l, True):
                if DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single: trip success, unwait: l', l, 't',
                        t, 'thread',
                        currentThread().name)
                self.lock.unwait(l)
            elif DEBUG_LOCK:
                log(
                    self.log_prefix +
                    '_rerequest_single: trip success, no trip: l', l, 't', t,
                    'thread',
                    currentThread().name)

            def add(self=self, r=r):
                self.postrequest(r, 'tracker=' + t, self.notifiers)

            self.externalsched(add)
        except:
            print_exc()
            if self.lock.trip(l):
                if DEBUG_LOCK:
                    log(
                        self.log_prefix +
                        '_rerequest_single: got exception, unwait: l', l, 't',
                        t, 'thread',
                        currentThread().name)
                self.lock.unwait(l)
    def _rerequest_single(self, t, s, l):
        try:
            closer = [None]

            def timedout(self = self, l = l, closer = closer):
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(self.log_prefix + '_rerequest_single:timedout: unwait: l', l, 't', t, 'thread', currentThread().name)
                    self.errorcodes['troublecode'] = 'Problem connecting to tracker - timeout exceeded'
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single:timedout: no trip: l', l, 't', t, 'thread', currentThread().name)
                try:
                    closer[0]()
                except:
                    pass

            self.externalsched(timedout, self.timeout)
            err = None
            try:
                if DEBUG or DEBUG_ANNOUNCE:
                    log(self.log_prefix + '_rerequest_single: request tracker', merge_announce(t, s), 'thread', currentThread().name)
                h = urlopen(merge_announce(t, s), silent=True)
                closer[0] = h.close
                data = h.read()
            except (IOError, socket.error) as e:
                err = 'Problem connecting to tracker - ' + str(e)
                if DEBUG:
                    log(self.log_prefix + '_rerequest_single: failed to connect to tracker')
            except:
                err = 'Problem connecting to tracker'
                if DEBUG:
                    log(self.log_prefix + '_rerequest_single: failed to connect to tracker')

            try:
                h.close()
            except:
                pass

            if err:
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(self.log_prefix + '_rerequest_single: got error, unwait: l', l, 't', t, 'thread', currentThread().name, 'err', err)
                    self.errorcodes['troublecode'] = err
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single: got error, no trip: l', l, 't', t, 'thread', currentThread().name, 'err', err)
                return
            if not data:
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(self.log_prefix + '_rerequest_single: no date, unwait: l', l, 't', t, 'thread', currentThread().name)
                    self.errorcodes['troublecode'] = 'no data from tracker'
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single: no data, no trip: l', l, 't', t, 'thread', currentThread().name)
                return
            try:
                r = bdecode(data, sloppy=1)
                if DEBUG or DEBUG_ANNOUNCE:
                    log(self.log_prefix + '_rerequest_single: respose from tracker: t', t, 'r', r, 'thread', currentThread().name)
                check_peers(r)
            except ValueError as e:
                if DEBUG:
                    log_exc()
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(self.log_prefix + '_rerequest_single: exception while decoding data, unwait: l', l, 't', t, 'thread', currentThread().name)
                    self.errorcodes['bad_data'] = 'bad data from tracker - ' + str(e)
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single: exception while decoding data, no trip: l', l, 't', t, 'thread', currentThread().name)
                return

            if r.has_key('failure reason'):
                if self.lock.trip(l):
                    if DEBUG_LOCK:
                        log(self.log_prefix + '_rerequest_single: got failure reason, unwait: l', l, 't', t, 'thread', currentThread().name)
                    self.errorcodes['rejected'] = self.rejectedmessage + r['failure reason']
                    self.lock.unwait(l)
                elif DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single: got failure reason, no trip: l', l, 't', t, 'thread', currentThread().name)
                return
            if self.lock.trip(l, True):
                if DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single: trip success, unwait: l', l, 't', t, 'thread', currentThread().name)
                self.lock.unwait(l)
            elif DEBUG_LOCK:
                log(self.log_prefix + '_rerequest_single: trip success, no trip: l', l, 't', t, 'thread', currentThread().name)

            def add(self = self, r = r):
                self.postrequest(r, 'tracker=' + t, self.notifiers)

            self.externalsched(add)
        except:
            print_exc()
            if self.lock.trip(l):
                if DEBUG_LOCK:
                    log(self.log_prefix + '_rerequest_single: got exception, unwait: l', l, 't', t, 'thread', currentThread().name)
                self.lock.unwait(l)