當前位置: 首頁>>代碼示例>>Python>>正文


Python typing.Iterator方法代碼示例

本文整理匯總了Python中typing.Iterator方法的典型用法代碼示例。如果您正苦於以下問題:Python typing.Iterator方法的具體用法?Python typing.Iterator怎麽用?Python typing.Iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在typing的用法示例。


在下文中一共展示了typing.Iterator方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_options_to_test

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def get_options_to_test(self, tokens):  # type: (Iterator[str]) -> List[str]
        options_to_test = []
        token = next(tokens, None)

        while token:
            # "--" stops option parsing
            if token == "--":
                break

            if token[:1] and token[0] == "-":
                if token[:2] == "--" and len(token) > 2:
                    options_to_test.append(token[2:])
                elif len(token) == 2:
                    options_to_test.append(token[1:])

            token = next(tokens, None)

        return options_to_test 
開發者ID:sdispater,項目名稱:clikit,代碼行數:20,代碼來源:default_resolver.py

示例2: set_authentication

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_authentication(application: Flask, authentication: bool) -> Iterator:
    """
    Set the whether API needs to be authenticated or not (before it is run in main.py).

    :param application: Flask app object
            <flask.app.Flask>
    :param authentication : Bool. API Auth needed or not
            <bool>


    Raises:
        TypeError: If `authentication` is not a boolean value.

    """
    if not isinstance(authentication, bool):
        raise TypeError("Authentication flag must be of type <bool>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.authentication_ = authentication
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:23,代碼來源:utils.py

示例3: set_api_name

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_api_name(application: Flask, api_name: str) -> Iterator:
    """
    Set the server name or EntryPoint for the app (before it is run in main.py).
    :param application: Flask app object
            <flask.app.Flask>
    :param api_name : API/Server name or EntryPoint
            <str>

    Raises:
        TypeError: If `api_name` is not a string.

    """
    if not isinstance(api_name, str):
        raise TypeError("The api_name is not of type <str>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.api_name = api_name
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例4: set_page_size

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_page_size(application: Flask, page_size: int) -> Iterator:
    """
    Set the page_size of a page view.
    :param application: Flask app object
            <flask.app.Flask>
    :param page_size : Number of maximum elements a page can contain
            <int>

    Raises:
        TypeError: If `page_size` is not an int.

    """
    if not isinstance(page_size, int):
        raise TypeError("The page_size is not of type <int>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.page_size = page_size
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例5: set_pagination

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_pagination(application: Flask, paginate: bool) -> Iterator:
    """
    Enable or disable pagination.
    :param application: Flask app object
            <flask.app.Flask>
    :param paginate : Pagination enabled or not
            <bool>

    Raises:
        TypeError: If `paginate` is not a bool.

    """
    if not isinstance(paginate, bool):
        raise TypeError("The CLI argument 'pagination' is not of type <bool>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.paginate = paginate
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例6: set_doc

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_doc(application: Flask, APIDOC: HydraDoc) -> Iterator:
    """
    Set the API Documentation for the app (before it is run in main.py).
    :param application: Flask app object
            <flask.app.Flask>
    :param APIDOC : Hydra Documentation object
            <hydra_python_core.doc_writer.HydraDoc>

    Raises:
        TypeError: If `APIDOC` is not an instance of `HydraDoc`.

    """
    if not isinstance(APIDOC, HydraDoc):
        raise TypeError(
            "The API Doc is not of type <hydra_python_core.doc_writer.HydraDoc>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.doc = APIDOC
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:22,代碼來源:utils.py

示例7: set_hydrus_server_url

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_hydrus_server_url(application: Flask, server_url: str) -> Iterator:
    """
    Set the server URL for the app (before it is run in main.py).
    :param application: Flask app object
            <flask.app.Flask>
    :param server_url : Server URL
            <str>

    Raises:
        TypeError: If the `server_url` is not a string.

    """
    if not isinstance(server_url, str):
        raise TypeError("The server_url is not of type <str>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.hydrus_server_url = server_url
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:21,代碼來源:utils.py

示例8: set_session

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def set_session(application: Flask, DB_SESSION: scoped_session) -> Iterator:
    """
    Set the Database Session for the app before it is run in main.py.
    :param application: Flask app object
            <flask.app.Flask>
    :param DB_SESSION: SQLalchemy Session object
            <sqlalchemy.orm.session.Session>

    Raises:
        TypeError: If `DB_SESSION` is not an instance of `scoped_session` or `Session`.

    """
    if not isinstance(DB_SESSION, scoped_session) and not isinstance(
            DB_SESSION, Session):
        raise TypeError(
            "The API Doc is not of type <sqlalchemy.orm.session.Session> or"
            " <sqlalchemy.orm.scoping.scoped_session>")

    def handler(sender: Flask, **kwargs: Any) -> None:
        g.dbsession = DB_SESSION
    with appcontext_pushed.connected_to(handler, application):
        yield 
開發者ID:HTTP-APIs,項目名稱:hydrus,代碼行數:24,代碼來源:utils.py

示例9: __init__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def __init__(
        self,
        trim_log_values: bool = False,
        validate_against_schema: bool = True,
        id_generator: Optional[Iterator] = None,
        basic_logging: bool = False,
    ) -> None:
        """
        Args:
            trim_log_values: Abbreviate the log entries of requests and responses.
            validate_against_schema: Validate response against the JSON-RPC schema.
            id_generator: Iterable of values to use as the "id" part of the request.
            basic_logging: Will create log handlers to output request & response
                messages.
        """
        self.trim_log_values = trim_log_values
        self.validate_against_schema = validate_against_schema
        self.id_generator = id_generator
        if basic_logging:
            self.basic_logging() 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:22,代碼來源:client.py

示例10: request

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def request(
        self,
        method_name: str,
        *args: Any,
        trim_log_values: bool = False,
        validate_against_schema: bool = True,
        id_generator: Optional[Iterator] = None,
        **kwargs: Any
    ) -> Response:
        """
        Async version of Client.request.
        """
        return await self.send(
            Request(method_name, id_generator=id_generator, *args, **kwargs),
            trim_log_values=trim_log_values,
            validate_against_schema=validate_against_schema,
        ) 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:19,代碼來源:async_client.py

示例11: __init__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def __init__(
        self,
        method: str,
        *args: Any,
        id_generator: Optional[Iterator[Any]] = None,
        **kwargs: Any
    ) -> None:
        # If 'request_id' is passed, use the specified id
        if "request_id" in kwargs:
            id_ = kwargs.pop("request_id", None)
        else:  # Get the next id from the generator
            id_generator = (
                id_generator if id_generator is not None else self.id_generator
            )
            id_ = next(id_generator)
        # We call super last, after popping the request_id
        super().__init__(method, *args, **kwargs)
        self.update(id=id_) 
開發者ID:bcb,項目名稱:jsonrpcclient,代碼行數:20,代碼來源:requests.py

示例12: __iter__

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def __iter__(self) -> Iterator[int]:
            image_ratios = torch.tensor(self._image_ratios)
            tall_indices = (image_ratios < 1).nonzero().view(-1)
            fat_indices = (image_ratios >= 1).nonzero().view(-1)

            tall_indices_length = len(tall_indices)
            fat_indices_length = len(fat_indices)

            tall_indices = tall_indices[torch.randperm(tall_indices_length)]
            fat_indices = fat_indices[torch.randperm(fat_indices_length)]

            num_tall_remainder = tall_indices_length % self._num_neighbors
            num_fat_remainder = fat_indices_length % self._num_neighbors

            tall_indices = tall_indices[:tall_indices_length - num_tall_remainder]
            fat_indices = fat_indices[:fat_indices_length - num_fat_remainder]

            tall_indices = tall_indices.view(-1, self._num_neighbors)
            fat_indices = fat_indices.view(-1, self._num_neighbors)
            merge_indices = torch.cat([tall_indices, fat_indices], dim=0)
            merge_indices = merge_indices[torch.randperm(len(merge_indices))].view(-1)

            return iter(merge_indices.tolist()) 
開發者ID:potterhsu,項目名稱:easy-faster-rcnn.pytorch,代碼行數:25,代碼來源:base.py

示例13: _match_sequence_variable

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def _match_sequence_variable(self, wildcard: Wildcard, transition: _Transition) -> Iterator[_State]:
        min_count = wildcard.min_count
        if len(self.subjects) < min_count:
            return
        matched_subject = []
        for _ in range(min_count):
            matched_subject.append(self.subjects.popleft())
        while True:
            if self.associative[-1] and wildcard.fixed_size:
                assert min_count == 1, "Fixed wildcards with length != 1 are not supported."
                if len(matched_subject) > 1:
                    wrapped = self.associative[-1](*matched_subject)
                else:
                    wrapped = matched_subject[0]
            else:
                if len(matched_subject) == 0 and wildcard.optional is not None:
                    wrapped = wildcard.optional
                else:
                    wrapped = tuple(matched_subject)
            yield from self._check_transition(transition, wrapped, False)
            if not self.subjects:
                break
            matched_subject.append(self.subjects.popleft())
        self.subjects.extendleft(reversed(matched_subject)) 
開發者ID:HPAC,項目名稱:matchpy,代碼行數:26,代碼來源:many_to_one.py

示例14: _match_with_bipartite

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def _match_with_bipartite(
            self,
            subject_ids: MultisetOfInt,
            pattern_set: MultisetOfInt,
            substitution: Substitution,
    ) -> Iterator[Tuple[Substitution, MultisetOfInt]]:
        bipartite = self._build_bipartite(subject_ids, pattern_set)
        for matching in enum_maximum_matchings_iter(bipartite):
            if len(matching) < len(pattern_set):
                break
            if not self._is_canonical_matching(matching):
                continue
            for substs in itertools.product(*(bipartite[edge] for edge in matching.items())):
                try:
                    bipartite_substitution = substitution.union(*substs)
                except ValueError:
                    continue
                matched_subjects = Multiset(subexpression for subexpression, _ in matching)
                yield bipartite_substitution, matched_subjects 
開發者ID:HPAC,項目名稱:matchpy,代碼行數:21,代碼來源:many_to_one.py

示例15: _match_sequence_variables

# 需要導入模塊: import typing [as 別名]
# 或者: from typing import Iterator [as 別名]
def _match_sequence_variables(
            self,
            subjects: MultisetOfExpression,
            pattern_vars: Sequence[VariableWithCount],
            substitution: Substitution,
    ) -> Iterator[Substitution]:
        only_counts = [info for info, _ in pattern_vars]
        wrapped_vars = [name for (name, _, _, _), wrap in pattern_vars if wrap and name]
        for variable_substitution in commutative_sequence_variable_partition_iter(subjects, only_counts):
            for var in wrapped_vars:
                operands = variable_substitution[var]
                if isinstance(operands, (tuple, list, Multiset)):
                    if len(operands) > 1:
                        variable_substitution[var] = self.associative(*operands)
                    else:
                        variable_substitution[var] = next(iter(operands))
            try:
                result_substitution = substitution.union(variable_substitution)
            except ValueError:
                continue
            yield result_substitution 
開發者ID:HPAC,項目名稱:matchpy,代碼行數:23,代碼來源:many_to_one.py


注:本文中的typing.Iterator方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。