def __init__(self): super(FindTransactionsRequestFilter, self).__init__( { 'addresses': (f.Array | f.FilterRepeater( f.Required | AddressNoChecksum() | f.Unicode(encoding='ascii', normalize=False))), 'approvees': (f.Array | f.FilterRepeater( f.Required | Trytes(result_type=TransactionHash) | f.Unicode(encoding='ascii', normalize=False))), 'bundles': (f.Array | f.FilterRepeater( f.Required | Trytes(result_type=TransactionHash) | f.Unicode(encoding='ascii', normalize=False))), 'tags': (f.Array | f.FilterRepeater( f.Required | Trytes(result_type=Tag) | f.Unicode(encoding='ascii', normalize=False))), }, # Technically, all of the parameters for this command are # optional, so long as at least one of them is present and not # empty. allow_missing_keys=True, )
def __init__(self): super(GetInclusionStatesRequestFilter, self).__init__( { # Required parameters. 'transactions': ( f.Required | f.Array | f.FilterRepeater( f.Required | Trytes(result_type=TransactionHash) | f.Unicode(encoding='ascii', normalize=False) ) ), # Optional parameters. 'tips': ( f.Array | f.FilterRepeater( f.Required | Trytes(result_type=TransactionHash) | f.Unicode(encoding='ascii', normalize=False) ) | f.Optional(default=[]) ), }, allow_missing_keys = { 'tips', }, )
def __init__(self): super(StoreTransactionsRequestFilter, self).__init__({ 'trytes': f.Required | f.Array | f.FilterRepeater( f.Required | Trytes(TransactionTrytes) | f.Unicode(encoding='ascii', normalize=False), ), })
def StringifiedTrytesArray(trytes_type=TryteString): # type: (Type[TryteString]) -> f.FilterChain """ Validates that the incoming value is an array containing tryte strings corresponding to the specified type (e.g., ``TransactionHash``). When a value doesn't pass the filter, a ``ValueError`` is raised with lots of contextual info attached to it. :param TryteString result_type: Any subclass of :py:class:`~iota.TryteString` that you want the filter to validate. :return: :py:class:`filters.FilterChain` object. .. important:: This filter will return string values, suitable for inclusion in an API request. If you are expecting objects (e.g., :py:class:`Address`), then this is not the filter to use! .. note:: This filter will allow empty arrays and `None`. If this is not desirable, chain this filter with ``f.NotEmpty`` or ``f.Required``, respectively. """ return f.Array | f.FilterRepeater( f.Required | Trytes(trytes_type) | f.Unicode(encoding='ascii', normalize=False), )
def __init__(self): super(WereAddressesSpentFromRequestFilter, self).__init__({ 'addresses': f.Required | f.Array | f.FilterRepeater( f.Required | AddressNoChecksum() | f.Unicode(encoding='ascii', normalize=False), ), })
def __init__(self): super(BroadcastTransactionsRequestFilter, self).__init__({ 'trytes': f.Required | f.Array | f.FilterRepeater(f.Required | Trytes(result_type=TransactionTrytes) | f.Unicode(encoding='ascii', normalize=False)), })
def __init__(self): super(IsReattachableRequestFilter, self).__init__( { 'addresses': f.Required | f.Array | f.FilterRepeater( f.Required | Trytes(Address) | f.Unicode(encoding='ascii', normalize=False), ), }, )
def __init__(self): super(GetTrytesRequestFilter, self).__init__({ 'hashes': (f.Required | f.Array | f.FilterRepeater(f.Required | Trytes(result_type=TransactionHash) | f.Unicode(encoding='ascii', normalize=False))), })
def __init__(self) -> None: super(GetBalancesRequestFilter, self).__init__( { 'addresses': f.Required | f.Array | f.FilterRepeater( f.Required | AddressNoChecksum() | f.Unicode(encoding='ascii', normalize=False), ), 'tips': StringifiedTrytesArray(TransactionHash), }, allow_missing_keys={ 'tips', }, )
def __init__(self): super(GetBalancesRequestFilter, self).__init__( { 'addresses': f.Required | f.Array | f.FilterRepeater( f.Required | AddressNoChecksum() | f.Unicode(encoding='ascii', normalize=False), ), 'threshold': f.Type(int) | f.Min(0) | f.Max(100) | f.Optional(default=100), }, allow_missing_keys={ 'threshold', }, )
def StringifiedTrytesArray(trytes_type=TryteString): # type: (Type[TryteString]) -> f.FilterChain """ Validates that the incoming value is an array containing tryte strings corresponding to the specified type (e.g., ``TransactionHash``). .. important:: This filter will return string values, suitable for inclusion in an API request. If you are expecting objects (e.g., :py:class:`Address`), then this is not the filter to use! .. note:: This filter will allow empty arrays and `None`. If this is not desirable, chain this filter with ``f.NotEmpty`` or ``f.Required``, respectively. """ return f.Array | f.FilterRepeater( f.Required | Trytes(trytes_type) | f.Unicode(encoding='ascii', normalize=False), )
def get_logger_context(self, logger=None, context=None): """ Returns a configured logger instance, for use as a context manager. Example usage:: with context.get_logger_context() as logger: ... do stuff ... :param logger: The logger instance to use. If not provided, a :py:class:`LocalLogger` instance will be returned. :param context: Additional context vars to add to the logger. """ logger =\ LoggerAdapter(logger or LocalLogger(), {'context': context or {}}) # type: Union[LoggerAdapter, LocalLogger] # Track the severity of emitted logs. logs = LogLevelHandler() logger.addHandler(logs) with closing(logger): try: yield logger except Exception as e: # Ensure exceptions get logged, but do not prevent them # from propagating. logger.exception(msg=f.Unicode().apply(e), extra={'context': getattr(e, 'context', {})}) raise finally: logger.removeHandler(logs) self.log_level =\ max(self.log_level, logs.max_level_emitted)