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


Python httplib.REQUEST_TIMEOUT屬性代碼示例

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


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

示例1: post

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import REQUEST_TIMEOUT [as 別名]
def post(self):  # pylint:disable-msg=invalid-name
    """Handles HTTP POST requests."""
    repo_url = self.request.data.get('repo_url')
    if not repo_url:
      Abort(httplib.BAD_REQUEST, 'repo_url required')
    repo = model.GetRepo(repo_url)
    if not repo:
      html_url = name = description = repo_url
      repo = model.CreateRepoAsync(owner=model.GetManualTemplateOwner(),
                                   repo_url=repo_url,
                                   html_url=html_url,
                                   name=name,
                                   description=description,
                                   show_files=[],
                                   read_only_files=[],
                                   read_only_demo_url=None)
    template_project = repo.project.get()
    if not template_project or template_project.in_progress_task_name:
      Abort(httplib.REQUEST_TIMEOUT,
            'Sorry. Requested template is not yet available. '
            'Please try again in 30 seconds.')
    expiration_seconds = self.request.data.get('expiration_seconds')
    project = model.CopyProject(self.user, template_project, expiration_seconds,
                                new_project_name=template_project.project_name)
    return self.DictOfProject(project) 
開發者ID:googlearchive,項目名稱:cloud-playground,代碼行數:27,代碼來源:playground.py

示例2: _should_retry

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import REQUEST_TIMEOUT [as 別名]
def _should_retry(resp):
  """Given a urlfetch response, decide whether to retry that request."""
  return (resp.status_code == httplib.REQUEST_TIMEOUT or
          (resp.status_code >= 500 and
           resp.status_code < 600)) 
開發者ID:googlearchive,項目名稱:billing-export-python,代碼行數:7,代碼來源:api_utils.py

示例3: timed_out

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import REQUEST_TIMEOUT [as 別名]
def timed_out(self):
    return self.__http_response.http_code in [httplib.REQUEST_TIMEOUT,
                                              httplib.GATEWAY_TIMEOUT] 
開發者ID:google,項目名稱:citest,代碼行數:5,代碼來源:http_agent.py

示例4: check_status

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import REQUEST_TIMEOUT [as 別名]
def check_status(status, expected, path, headers=None,
                 resp_headers=None, extras=None):
  """Check HTTP response status is expected.

  Args:
    status: HTTP response status. int.
    expected: a list of expected statuses. A list of ints.
    path: filename or a path prefix.
    headers: HTTP request headers.
    resp_headers: HTTP response headers.
    extras: extra info to be logged verbatim if error occurs.

  Raises:
    AuthorizationError: if authorization failed.
    NotFoundError: if an object that's expected to exist doesn't.
    TimeoutError: if HTTP request timed out.
    ServerError: if server experienced some errors.
    FatalError: if any other unexpected errors occurred.
  """
  if status in expected:
    return

  msg = ('Expect status %r from Google Storage. But got status %d.\n'
         'Path: %r.\n'
         'Request headers: %r.\n'
         'Response headers: %r.\n'
         'Extra info: %r.\n' %
         (expected, status, path, headers, resp_headers, extras))

  if status == httplib.UNAUTHORIZED:
    raise AuthorizationError(msg)
  elif status == httplib.FORBIDDEN:
    raise ForbiddenError(msg)
  elif status == httplib.NOT_FOUND:
    raise NotFoundError(msg)
  elif status == httplib.REQUEST_TIMEOUT:
    raise TimeoutError(msg)
  elif status == httplib.REQUESTED_RANGE_NOT_SATISFIABLE:
    raise InvalidRange(msg)
  elif status >= 500:
    raise ServerError(msg)
  else:
    raise FatalError(msg) 
開發者ID:googlearchive,項目名稱:billing-export-python,代碼行數:45,代碼來源:errors.py

示例5: check_status

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import REQUEST_TIMEOUT [as 別名]
def check_status(status, expected, path, headers=None,
                 resp_headers=None, body=None, extras=None):
  """Check HTTP response status is expected.

  Args:
    status: HTTP response status. int.
    expected: a list of expected statuses. A list of ints.
    path: filename or a path prefix.
    headers: HTTP request headers.
    resp_headers: HTTP response headers.
    body: HTTP response body.
    extras: extra info to be logged verbatim if error occurs.

  Raises:
    AuthorizationError: if authorization failed.
    NotFoundError: if an object that's expected to exist doesn't.
    TimeoutError: if HTTP request timed out.
    ServerError: if server experienced some errors.
    FatalError: if any other unexpected errors occurred.
  """
  if status in expected:
    return

  msg = ('Expect status %r from Google Storage. But got status %d.\n'
         'Path: %r.\n'
         'Request headers: %r.\n'
         'Response headers: %r.\n'
         'Body: %r.\n'
         'Extra info: %r.\n' %
         (expected, status, path, headers, resp_headers, body, extras))

  if status == httplib.UNAUTHORIZED:
    raise AuthorizationError(msg)
  elif status == httplib.FORBIDDEN:
    raise ForbiddenError(msg)
  elif status == httplib.NOT_FOUND:
    raise NotFoundError(msg)
  elif status == httplib.REQUEST_TIMEOUT:
    raise TimeoutError(msg)
  elif status == httplib.REQUESTED_RANGE_NOT_SATISFIABLE:
    raise InvalidRange(msg)
  elif (status == httplib.OK and 308 in expected and
        httplib.OK not in expected):
    raise FileClosedError(msg)
  elif status >= 500:
    raise ServerError(msg)
  else:
    raise FatalError(msg) 
開發者ID:einaregilsson,項目名稱:MyLife,代碼行數:50,代碼來源:errors.py


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