python类Iterable()的实例源码

api_base.py 文件源码 项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def subscribe(id_or_symbols):
    """
    ???????????????????????????handle_bar???bar??????

    ?????????????????????????????handle_bar??????

    :param id_or_ins: ???
    :type id_or_ins: :class:`~Instrument` object | `str` | List[:class:`~Instrument`] | List[`str`]
    """
    current_universe = Environment.get_instance().universe
    if isinstance(id_or_symbols, six.string_types):
        order_book_id = instruments(id_or_symbols).order_book_id
        current_universe.add(order_book_id)
    elif isinstance(id_or_symbols, Instrument):
        current_universe.add(id_or_symbols.order_book_id)
    elif isinstance(id_or_symbols, Iterable):
        for item in id_or_symbols:
            current_universe.add(assure_order_book_id(item))
    else:
        raise RQInvalidArgument(_("unsupported order_book_id type"))
    verify_that('id_or_symbols')._are_valid_instruments("subscribe", id_or_symbols)
    Environment.get_instance().update_universe(current_universe)
api_base.py 文件源码 项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def unsubscribe(id_or_symbols):
    """
    ?????????????????????????????????????????????????

    :param id_or_ins: ???
    :type id_or_ins: :class:`~Instrument` object | `str` | List[:class:`~Instrument`] | List[`str`]
    """
    current_universe = Environment.get_instance().universe
    if isinstance(id_or_symbols, six.string_types):
        order_book_id = instruments(id_or_symbols).order_book_id
        current_universe.discard(order_book_id)
    elif isinstance(id_or_symbols, Instrument):
        current_universe.discard(id_or_symbols.order_book_id)
    elif isinstance(id_or_symbols, Iterable):
        for item in id_or_symbols:
            i = assure_order_book_id(item)
            current_universe.discard(i)
    else:
        raise RQInvalidArgument(_("unsupported order_book_id type"))

    Environment.get_instance().update_universe(current_universe)
api_base.py 文件源码 项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def subscribe(id_or_symbols):
    """
    ???????????????????????????handle_bar???bar??????

    ?????????????????????????????handle_bar??????

    :param id_or_ins: ???
    :type id_or_ins: :class:`~Instrument` object | `str` | List[:class:`~Instrument`] | List[`str`]
    """
    current_universe = Environment.get_instance().get_universe()
    if isinstance(id_or_symbols, six.string_types):
        order_book_id = instruments(id_or_symbols).order_book_id
        current_universe.add(order_book_id)
    elif isinstance(id_or_symbols, Instrument):
        current_universe.add(id_or_symbols.order_book_id)
    elif isinstance(id_or_symbols, Iterable):
        for item in id_or_symbols:
            current_universe.add(assure_order_book_id(item))
    else:
        raise RQInvalidArgument(_(u"unsupported order_book_id type"))
    verify_that('id_or_symbols')._are_valid_instruments("subscribe", id_or_symbols)
    Environment.get_instance().update_universe(current_universe)
api_base.py 文件源码 项目:InplusTrader_Linux 作者: zhengwsh 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def unsubscribe(id_or_symbols):
    """
    ?????????????????????????????????????????????????

    :param id_or_ins: ???
    :type id_or_ins: :class:`~Instrument` object | `str` | List[:class:`~Instrument`] | List[`str`]
    """
    current_universe = Environment.get_instance().get_universe()
    if isinstance(id_or_symbols, six.string_types):
        order_book_id = instruments(id_or_symbols).order_book_id
        current_universe.discard(order_book_id)
    elif isinstance(id_or_symbols, Instrument):
        current_universe.discard(id_or_symbols.order_book_id)
    elif isinstance(id_or_symbols, Iterable):
        for item in id_or_symbols:
            i = assure_order_book_id(item)
            current_universe.discard(i)
    else:
        raise RQInvalidArgument(_(u"unsupported order_book_id type"))

    Environment.get_instance().update_universe(current_universe)
pyparsing.py 文件源码 项目:ivaochdoc 作者: ivaoch 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
pyparsing.py 文件源码 项目:ivaochdoc 作者: ivaoch 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
pyparsing.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
pyparsing.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
query.py 文件源码 项目:pyuniprot 作者: cebel 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _limit_and_df(self, query, limit, as_df=False):
        """adds a limit (limit==None := no limit) to any query and allow a return as pandas.DataFrame

        :param bool as_df: if is set to True results return as pandas.DataFrame
        :param `sqlalchemy.orm.query.Query` query: SQL Alchemy query 
        :param int or tuple[int] limit: maximum number of results
        :return: query result of pyuniprot.manager.models.XY objects
        """
        if limit:

            if isinstance(limit, int):
                query = query.limit(limit)

            if isinstance(limit, Iterable) and len(limit) == 2 and [int, int] == [type(x) for x in limit]:
                page, page_size = limit
                query = query.limit(page_size)
                query = query.offset(page * page_size)

        if as_df:
            results = read_sql(query.statement, self.engine)

        else:
            results = query.all()

        return results
query.py 文件源码 项目:pyuniprot 作者: cebel 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _one_to_many_query(cls, query_obj, search4, model_attrib):
        """extends and returns a SQLAlchemy query object to allow one-to-many queries

        :param query_obj: SQL Alchemy query object
        :param str search4: search string
        :param model_attrib: attribute in model
        """
        model = model_attrib.parent.class_

        if isinstance(search4, str):
            query_obj = query_obj.join(model).filter(model_attrib.like(search4))

        elif isinstance(search4, int):
            query_obj = query_obj.join(model).filter(model_attrib == search4)

        elif isinstance(search4, Iterable):
            query_obj = query_obj.join(model).filter(model_attrib.in_(search4))

        return query_obj
spe2fits.py 文件源码 项目:spe2fits 作者: jerryjiahaha 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def loadSpeImg(self, index):
        """ return a list of images' data
        """
        from collections import Iterable
        if isinstance(index, Iterable):
            index = list(index)
        else:
            try:
                index = [int(index)]
            except: # get all images
                print("Warning: invalid image index", index, ". Fetch all available images")
                index = list(range(self._img_count))

        datas = {}
        fmt = str(self._xdim * self._ydim) + self._datatype
        for i in index:
            self._fileObj.seek(SPE.SPE_DATA_OFFSET + i * self._img_size)
            data = self._fileObj.read(self._img_size)
            datas[i] = np.array(
                    struct.unpack(fmt, data),
                    dtype = self._ndtype
                    ).reshape(self._ydim, self._xdim)
        return datas
pyparsing.py 文件源码 项目:django 作者: alexsukhrin 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
portinterface.py 文件源码 项目:autosar 作者: cogu 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def possibleErrors(self, data):
      if self.parent is None:
         raise ValueError('cannot call this method without valid parent object')
      if isinstance(data, str):
         data=[data]         
      if isinstance(data, collections.Iterable):
         del self.errorRefs[:]
         for name in data:
            found=False
            for error in self.parent.applicationErrors:
               if error.name == name:
                  self.errorRefs.append(error.ref)
                  found=True
                  break
            if found==False:
               raise ValueError('invalid error name: "%s"'%name)
      else:
         raise ValueError("input argument must be string or iterrable")
component.py 文件源码 项目:autosar 作者: cogu 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def __init__(self,name, portInterfaceRef, comspec=None, parent=None):
      self.name = name      
      if portInterfaceRef is not None and not isinstance(portInterfaceRef,str):
         raise ValueError('portInterfaceRef needs to be of type None or str')
      self.portInterfaceRef = portInterfaceRef
      self.comspec=[] 
      self.parent=parent
      if comspec is not None:
         ws = self.rootWS()
         assert(ws is not None)
         if isinstance(comspec, collections.Mapping):
            comspecObj = self.createComSpecFromDict(ws,portInterfaceRef,comspec)
            if comspecObj is None:
               raise ValueError('failed to create comspec from comspec data: '+repr(comspec))
            self.comspec.append(comspecObj)
         elif isinstance(comspec, collections.Iterable):
            for data in comspec:
               comspecObj = self.createComSpecFromDict(ws,portInterfaceRef,data)
               if comspecObj is None:
                  raise ValueError('failed to create comspec from comspec data: '+repr(data))
               self.comspec.append(comspecObj)
         else:
            raise NotImplementedError("not supported")
package.py 文件源码 项目:autosar 作者: cogu 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def createClientServerInterface(self, name, operations, errors=None, isService=False, adminData=None):
      """
      creates a new client server interface in current package
      name: name of the interface (string)
      operations: names of the operations in the interface (list of strings)
      errors: possible errors dict containing key-value pair where key is the name and value is the error code (must be integer)
      isService: True if this interface is a service interface (bool)
      adminData: optional admindata (dict or autosar.base.AdminData object)
      """
      portInterface = autosar.portinterface.ClientServerInterface(name, isService, self, adminData)
      for name in operations:
         portInterface.append(autosar.portinterface.Operation(name))      
      if errors is not None:
         if isinstance(errors, collections.Iterable):
            for error in errors:
               portInterface.append(error)
         else:            
            assert( isinstance(errors, autosar.portinterface.ApplicationError))
            portInterface.append(errors)
      self.append(portInterface)
      return portInterface
pyparsing.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
serde.py 文件源码 项目:ngraph 作者: NervanaSystems 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _serialize_graph(ops):
    """
    Serializes a graph and returns the actual protobuf python object (rather than serialized
    byte string as done by `serialize_graph`).
    """
    assert isinstance(ops, Iterable), "Ops passed into `serialize_graph` must be an iterable"
    ops = Op.all_op_references(ops)

    pb_ops = []
    pb_edges = []
    for op in ops:
        pb_ops.append(op_to_protobuf(op))
        add_edges(pb_edges, pb_ops, op)

    graph_def = ops_pb.GraphDef()
    for edge in pb_edges:
        temp = graph_def.edges.add()
        temp.CopyFrom(edge)
    for op in pb_ops:
        temp = graph_def.ops.add()
        temp.CopyFrom(op)
    return graph_def
axes.py 文件源码 项目:ngraph 作者: NervanaSystems 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def _reduce_nested(elem, agg, func):
    """
    Reduces a nested sequence by applying a function to each
    of its elements and returns an aggregation.

    Arguments:
      elem: The object to be reduced, either a sequence
        or a singleton.
      agg: A variable holding information collected
        as the sequence is collapsed.
      func: A function to augment the aggregate by processing
        a singleton. Should have the form func(agg, elem) -> agg

    Returns:
        agg: The final aggregate returned by the function.
    """
    if isinstance(elem, collections.Iterable):
        for sub in elem:
            agg = _reduce_nested(sub, agg, func)
        return agg
    else:
        return func(agg, elem)
pyparsing.py 文件源码 项目:Taigabot 作者: FrozenPigs 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False
pyparsing.py 文件源码 项目:AshsSDK 作者: thehappydinoa 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def __init__( self, exprs, savelist = False ):
        super(ParseExpression,self).__init__(savelist)
        if isinstance( exprs, _generatorType ):
            exprs = list(exprs)

        if isinstance( exprs, basestring ):
            self.exprs = [ ParserElement._literalStringClass( exprs ) ]
        elif isinstance( exprs, collections.Iterable ):
            exprs = list(exprs)
            # if sequence of strings provided, wrap with Literal
            if all(isinstance(expr, basestring) for expr in exprs):
                exprs = map(ParserElement._literalStringClass, exprs)
            self.exprs = list(exprs)
        else:
            try:
                self.exprs = list( exprs )
            except TypeError:
                self.exprs = [ exprs ]
        self.callPreparse = False


问题


面经


文章

微信
公众号

扫码关注公众号