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


Python httplib.PRECONDITION_FAILED屬性代碼示例

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


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

示例1: disable_chrome_device

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import PRECONDITION_FAILED [as 別名]
def disable_chrome_device(self, device_id):
    """Disable a Chrome device within an organization.

    Args:
      device_id: String, The unique Chrome device id.

    Raises:
      DirectoryRPCError: An error when the RPC call to the directory API fails.
    """
    logging.info('Disabling chrome device %s.', device_id)
    try:
      self._client.chromeosdevices().action(
          customerId=constants.CUSTOMER_ID,
          resourceId=device_id,
          body={
              'action': 'disable'
          }).execute()
    except errors.HttpError as err:
      if err.resp.status == httplib.PRECONDITION_FAILED:
        raise DeviceAlreadyDisabledError(err.resp.reason)
      logging.error(
          'Directory API call to disable Chrome device failed with a %s '
          'exception because %s.', str(type(err)), err.resp.reason)
      raise DirectoryRPCError(err.resp.reason) 
開發者ID:google,項目名稱:loaner,代碼行數:26,代碼來源:directory.py

示例2: Dispatch

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import PRECONDITION_FAILED [as 別名]
def Dispatch(self, request, outfile, base_env_dict=None):
    """Reads the file and returns the response status and data."""
    full_path = self._path_adjuster.AdjustPath(request.path)
    status, data = self._read_data_file(full_path)
    content_type = self._static_file_config_matcher.GetMimeType(request.path)
    static_file = self._static_file_config_matcher.IsStaticFile(request.path)
    expiration = self._static_file_config_matcher.GetExpiration(request.path)
    current_etag = self.CreateEtag(data)
    if_match_etag = request.headers.get('if-match', None)
    if_none_match_etag = request.headers.get('if-none-match', '').split(',')

    http_headers = self._static_file_config_matcher.GetHttpHeaders(request.path)
    def WriteHeader(name, value):
      if http_headers.Get(name) is None:
        outfile.write('%s: %s\r\n' % (name, value))





    if if_match_etag and not self._CheckETagMatches(if_match_etag.split(','),
                                                    current_etag,
                                                    False):
      outfile.write('Status: %s\r\n' % httplib.PRECONDITION_FAILED)
      WriteHeader('ETag', current_etag)
      outfile.write('\r\n')
    elif self._CheckETagMatches(if_none_match_etag, current_etag, True):
      outfile.write('Status: %s\r\n' % httplib.NOT_MODIFIED)
      WriteHeader('ETag', current_etag)
      outfile.write('\r\n')
    else:



      outfile.write('Status: %d\r\n' % status)

      WriteHeader('Content-Type', content_type)


      if expiration:
        fmt = email.Utils.formatdate
        WriteHeader('Expires', fmt(time.time() + expiration, usegmt=True))
        WriteHeader('Cache-Control', 'public, max-age=%i' % expiration)


      if static_file:
        WriteHeader('ETag', '"%s"' % current_etag)

      for header in http_headers.iteritems():
        outfile.write('%s: %s\r\n' % header)

      outfile.write('\r\n')
      outfile.write(data) 
開發者ID:elsigh,項目名稱:browserscope,代碼行數:55,代碼來源:dev_appserver.py

示例3: _handle_put

# 需要導入模塊: import httplib [as 別名]
# 或者: from httplib import PRECONDITION_FAILED [as 別名]
def _handle_put(gcs_stub, filename, param_dict, headers, payload):
  """Handle PUT."""
  if _iscopy(headers):
    return _copy(gcs_stub, filename, headers)


  token = _get_param('upload_id', param_dict)
  content_range = _ContentRange(headers)

  if _is_query_progress(content_range):
    return _find_progress(gcs_stub, filename, token)

  if not content_range.value:
    raise ValueError('Missing header content-range.', httplib.BAD_REQUEST)




  if (headers.get('x-goog-if-generation-match', None) == '0' and
      gcs_stub.head_object(filename) is not None):
    return _FakeUrlFetchResult(httplib.PRECONDITION_FAILED, {}, '')



  if not token:

    if content_range.length is None:
      raise ValueError('Content-Range must have a final length.',
                       httplib.BAD_REQUEST)
    elif not content_range.no_data and content_range.range[0] != 0:
      raise ValueError('Content-Range must specify complete object.',
                       httplib.BAD_REQUEST)
    else:

      token = gcs_stub.post_start_creation(filename, headers)

  try:
    gcs_stub.put_continue_creation(token,
                                   payload,
                                   content_range.range,
                                   content_range.length)
  except ValueError, e:
    return _FakeUrlFetchResult(e.args[1], {}, e.args[0]) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:45,代碼來源:stub_dispatcher.py


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