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

All Samples(13)  |  Call(12)  |  Derive(0)  |  Import(1)
Raise value error if obj does not match type or triggers predicate

        def check_type(obj, types, errmsg='', pred=lambda x: False):
    """Raise value error if obj does not match type or triggers predicate"""
    if not isinstance(obj, types) or pred(obj):
        raise ValueError(errmsg)
        


src/b/i/BitTornado-HEAD/BitTornado/BT1/Rerequester.py   BitTornado(Download)
import urllib
import hashlib
from BitTornado.zurllib import urlopen
from BitTornado.Info import check_type
from BitTornado.bencode import bdecode
def check_peers(message):
    """Validate a dictionary with a list of peers"""
    check_type(message, dict)
    if 'failure reason' in message:
        check_type(message['failure reason'], str)
    if isinstance(peers, list):
        for peer in peers:
            check_type(peer, dict)
            check_type(peer.get('ip'), str)
            check_type(peer.get('port'), (int, long), pred=lambda x: x <= 0)