当前位置: 首页>>代码示例>>Python>>正文


Python http.BatchHttpRequest方法代码示例

本文整理汇总了Python中googleapiclient.http.BatchHttpRequest方法的典型用法代码示例。如果您正苦于以下问题:Python http.BatchHttpRequest方法的具体用法?Python http.BatchHttpRequest怎么用?Python http.BatchHttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在googleapiclient.http的用法示例。


在下文中一共展示了http.BatchHttpRequest方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _add_basic_methods

# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import BatchHttpRequest [as 别名]
def _add_basic_methods(self, resourceDesc, rootDesc, schema):
    # If this is the root Resource, add a new_batch_http_request() method.
    if resourceDesc == rootDesc:
      batch_uri = '%s%s' % (
        rootDesc['rootUrl'], rootDesc.get('batchPath', 'batch'))
      def new_batch_http_request(callback=None):
        """Create a BatchHttpRequest object based on the discovery document.

        Args:
          callback: callable, A callback to be called for each response, of the
            form callback(id, response, exception). The first parameter is the
            request id, and the second is the deserialized response object. The
            third is an apiclient.errors.HttpError exception object if an HTTP
            error occurred while processing the request, or None if no error
            occurred.

        Returns:
          A BatchHttpRequest object based on the discovery document.
        """
        return BatchHttpRequest(callback=callback, batch_uri=batch_uri)
      self._set_dynamic_attr('new_batch_http_request', new_batch_http_request)

    # Add basic methods to Resource
    if 'methods' in resourceDesc:
      for methodName, methodDesc in six.iteritems(resourceDesc['methods']):
        fixedMethodName, method = createMethod(
            methodName, methodDesc, rootDesc, schema)
        self._set_dynamic_attr(fixedMethodName,
                               method.__get__(self, self.__class__))
        # Add in _media methods. The functionality of the attached method will
        # change when it sees that the method name ends in _media.
        if methodDesc.get('supportsMediaDownload', False):
          fixedMethodName, method = createMethod(
              methodName + '_media', methodDesc, rootDesc, schema)
          self._set_dynamic_attr(fixedMethodName,
                                 method.__get__(self, self.__class__)) 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:38,代码来源:discovery.py

示例2: __init__

# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import BatchHttpRequest [as 别名]
def __init__(self, callback=None, batch_uri=None):
    """Constructor for a BatchHttpRequest.

    Args:
      callback: callable, A callback to be called for each response, of the
        form callback(id, response, exception). The first parameter is the
        request id, and the second is the deserialized response object. The
        third is an googleapiclient.errors.HttpError exception object if an HTTP error
        occurred while processing the request, or None if no error occurred.
      batch_uri: string, URI to send batch requests to.
    """
    if batch_uri is None:
      batch_uri = 'https://www.googleapis.com/batch'
    self._batch_uri = batch_uri

    # Global callback to be called for each individual response in the batch.
    self._callback = callback

    # A map from id to request.
    self._requests = {}

    # A map from id to callback.
    self._callbacks = {}

    # List of request ids, in the order in which they were added.
    self._order = []

    # The last auto generated id.
    self._last_auto_id = 0

    # Unique ID on which to base the Content-ID headers.
    self._base_id = None

    # A map from request id to (httplib2.Response, content) response pairs
    self._responses = {}

    # A map of id(Credentials) that have been refreshed.
    self._refreshed_credentials = {} 
开发者ID:luci,项目名称:luci-py,代码行数:40,代码来源:http.py

示例3: send_all

# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import BatchHttpRequest [as 别名]
def send_all(self, messages, dry_run=False):
        """Sends the given messages to FCM via the batch API."""
        if not isinstance(messages, list):
            raise ValueError('messages must be a list of messaging.Message instances.')
        if len(messages) > 500:
            raise ValueError('messages must not contain more than 500 elements.')

        responses = []

        def batch_callback(_, response, error):
            exception = None
            if error:
                exception = self._handle_batch_error(error)
            send_response = SendResponse(response, exception)
            responses.append(send_response)

        batch = http.BatchHttpRequest(
            callback=batch_callback, batch_uri=_MessagingService.FCM_BATCH_URL)
        for message in messages:
            body = json.dumps(self._message_data(message, dry_run))
            req = http.HttpRequest(
                http=self._transport,
                postproc=self._postproc,
                uri=self._fcm_url,
                method='POST',
                body=body,
                headers=self._fcm_headers
            )
            batch.add(req)

        try:
            batch.execute()
        except googleapiclient.http.HttpError as error:
            raise self._handle_batch_error(error)
        else:
            return BatchResponse(responses) 
开发者ID:firebase,项目名称:firebase-admin-python,代码行数:38,代码来源:messaging.py

示例4: __init__

# 需要导入模块: from googleapiclient import http [as 别名]
# 或者: from googleapiclient.http import BatchHttpRequest [as 别名]
def __init__(self, callback=None, batch_uri=None):
    """Constructor for a BatchHttpRequest.

    Args:
      callback: callable, A callback to be called for each response, of the
        form callback(id, response, exception). The first parameter is the
        request id, and the second is the deserialized response object. The
        third is an googleapiclient.errors.HttpError exception object if an HTTP error
        occurred while processing the request, or None if no error occurred.
      batch_uri: string, URI to send batch requests to.
    """
    if batch_uri is None:
      batch_uri = _LEGACY_BATCH_URI

    if batch_uri == _LEGACY_BATCH_URI:
      LOGGER.warn(
        "You have constructed a BatchHttpRequest using the legacy batch "
        "endpoint %s. This endpoint will be turned down on March 25, 2019. "
        "Please provide the API-specific endpoint or use "
        "service.new_batch_http_request(). For more details see "
        "https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html"
        "and https://developers.google.com/api-client-library/python/guide/batch.",
        _LEGACY_BATCH_URI)
    self._batch_uri = batch_uri

    # Global callback to be called for each individual response in the batch.
    self._callback = callback

    # A map from id to request.
    self._requests = {}

    # A map from id to callback.
    self._callbacks = {}

    # List of request ids, in the order in which they were added.
    self._order = []

    # The last auto generated id.
    self._last_auto_id = 0

    # Unique ID on which to base the Content-ID headers.
    self._base_id = None

    # A map from request id to (httplib2.Response, content) response pairs
    self._responses = {}

    # A map of id(Credentials) that have been refreshed.
    self._refreshed_credentials = {} 
开发者ID:fniephaus,项目名称:alfred-gmail,代码行数:50,代码来源:http.py


注:本文中的googleapiclient.http.BatchHttpRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。