Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(2)  |  Call(1)  |  Derive(0)  |  Import(1)

        def check_peers(message):
    if type(message) != dict:
        raise BTFailure
    if message.has_key('failure reason'):
        if type(message['failure reason']) != str:
            raise BTFailure('non-text failure reason')
        return
    if message.has_key('warning message'):
        if type(message['warning message']) != str:
            raise BTFailure('non-text warning message')
    peers = message.get('peers', [])
    if type(peers) != list:
        raise BTFailure('invalid peer list')
    for p in peers:
        if type(p) != dict:
            raise BTFailure('invalid entry in peer list')
        if type(p.get('ip')) != str:
            raise BTFailure('invalid entry in peer list')
        port = p.get('port')
        if type(port) not in ints or p <= 0:
            raise BTFailure('invalid entry in peer list')
        if p.has_key('nid'):
            nid = p.get('nid')
            if type(nid) != str or len(nid) != 1:
                raise BTFailure('invalid entry in peer list')
        #PeerID only used in BitTorrent
        #if p.has_key('peer id'):
        #    peerid = p.get('peer id')
        #    if type(peerid) != str or len(peerid) != 20:
        #        raise BTFailure('invalid entry in peer list')
    interval = message.get('interval', 1)
    if type(interval) not in ints or interval <= 0:
        raise BTFailure('invalid announce interval')
    minint = message.get('min interval', 1)
    if type(minint) not in ints or minint <= 0:
        raise BTFailure('invalid min announce interval')
    tcodes = message.get('tracking codes', [])
    if type(tcodes) != list:
        raise BTFailure('invalid tracking code list')
    for t in tcodes:
        if type(t) != list:
            raise BTFailure('invalid entry in tracking code list')
        if len(t) != 2:
            raise BTFailure('invalid tracking code entry length')
        if type(t[0]) != str or type(t[1]) != str:
            raise BTFailure('invalid format for tracking code components')
        


src/a/n/Anomos-HEAD/Anomos/Rerequester.py   Anomos(Download)
 
from Anomos.bencode import bdecode
from Anomos.btformats import check_peers
 
from M2Crypto import version_info as m2version
            # Here's where we receive/decrypt data from the tracker
            r = bdecode(data)
            check_peers(r)
        except BTFailure, e:
            if data != '':