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


Python six.ensure_str方法代码示例

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


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

示例1: test_response

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def test_response(self, response_object, regex):
        """
        Checks if the response response contains a regex specified in the
        output stage. It will assert that the regex is present.
        """
        if response_object is None:
            raise errors.TestError(
                'Searching before response received',
                {
                    'regex': regex,
                    'response_object': response_object,
                    'function': 'testrunner.TestRunner.test_response'
                })
        if regex.search(ensure_str(response_object.response)):
            assert True
        else:
            assert False 
开发者ID:CRS-support,项目名称:ftw,代码行数:19,代码来源:testrunner.py

示例2: to_document

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def to_document(self):
    """Creates a search.Document representation of a model.

    Returns:
      search.Document of the current model to be indexed with a valid doc_id. A
          doc_id will be autogenerated when inserted into the Index if one is
          not provided.

    Raises:
      DocumentCreationError: when unable to create a document for the
          model.
    """
    try:
      return search.Document(
          doc_id=six.ensure_str(self.key.urlsafe()),
          fields=self._get_document_fields())

    except (TypeError, ValueError) as e:
      raise DocumentCreationError(e) 
开发者ID:google,项目名称:loaner,代码行数:21,代码来源:base_model.py

示例3: _PredictContinuously

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def _PredictContinuously(self):
    """Waits for new checkpoints and runs predictor continuously."""
    prev_step = -1000000
    while True:
      # TODO(jonathanasdf): how to determine when training finished?
      path = tf.train.latest_checkpoint(self._checkpoint)
      step_str = re.search(r'ckpt-(\d{8})', six.ensure_str(path)).group(1)
      step = int(step_str)
      if step - prev_step >= self._prediction_step_interval:
        if not self._output_dir:
          raise ValueError(
              'output_dir must be specified for _PredictContinuously.')
        output_dir = os.path.join(self._output_dir, 'step_' + step_str)
        tf.io.gfile.makedirs(output_dir)
        self._PredictOneCheckpoint(path, output_dir)
        prev_step = step
        tf.logging.info('Waiting for next checkpoint...')
      time.sleep(_RETRY_SLEEP_SECONDS) 
开发者ID:tensorflow,项目名称:lingvo,代码行数:20,代码来源:predictor_runner_base.py

示例4: GetNvccOptions

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def GetNvccOptions(argv):
  """Collect the -nvcc_options values from argv.

  Args:
    argv: A list of strings, possibly the argv passed to main().

  Returns:
    1. The string that can be passed directly to nvcc.
    2. The leftover options.
  """

  parser = ArgumentParser()
  parser.add_argument('-nvcc_options', nargs='*', action='append')

  args, leftover = parser.parse_known_args(argv)

  if args.nvcc_options:
    options = _update_options(sum(args.nvcc_options, []))
    return (['--' + six.ensure_str(a) for a in options], leftover)
  return ([], leftover) 
开发者ID:tensorflow,项目名称:lingvo,代码行数:22,代码来源:msvc_wrapper_for_nvcc.py

示例5: _tabulate

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def _tabulate(output, headers, fmt):
    fmt = fmt or git_config('pw.format') or 'table'

    if fmt == 'table':
        return tabulate(output, headers, tablefmt='psql')
    elif fmt == 'simple':
        return tabulate(output, headers, tablefmt='simple')
    elif fmt == 'csv':
        result = six.StringIO()
        writer = csv.writer(
            result, quoting=csv.QUOTE_ALL, lineterminator=os.linesep)
        writer.writerow([ensure_str(h) for h in headers])
        for item in output:
            writer.writerow([ensure_str(i) for i in item])
        return result.getvalue()

    print('pw.format must be one of: table, simple, csv')
    sys.exit(1) 
开发者ID:getpatchwork,项目名称:git-pw,代码行数:20,代码来源:utils.py

示例6: test_full_tokenizer

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def test_full_tokenizer(self):
    vocab_tokens = [
        "[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn",
        "##ing", ","
    ]
    with tempfile.NamedTemporaryFile(delete=False) as vocab_writer:
      if six.PY2:
        vocab_writer.write("".join([x + "\n" for x in vocab_tokens]))
      else:
        contents = "".join([six.ensure_str(x) + "\n" for x in vocab_tokens])
        vocab_writer.write(six.ensure_binary(contents, "utf-8"))

      vocab_file = vocab_writer.name

    tokenizer = tokenization.FullTokenizer(vocab_file)
    os.unlink(vocab_file)

    tokens = tokenizer.tokenize(u"UNwant\u00E9d,running")
    self.assertAllEqual(tokens, ["un", "##want", "##ed", ",", "runn", "##ing"])

    self.assertAllEqual(
        tokenizer.convert_tokens_to_ids(tokens), [7, 4, 5, 10, 8, 9]) 
开发者ID:google-research,项目名称:albert,代码行数:24,代码来源:tokenization_test.py

示例7: evaluate_v1

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def evaluate_v1(dataset, predictions):
  f1 = exact_match = total = 0
  for article in dataset:
    for paragraph in article["paragraphs"]:
      for qa in paragraph["qas"]:
        total += 1
        if qa["id"] not in predictions:
          message = ("Unanswered question " + six.ensure_str(qa["id"]) +
                     "  will receive score 0.")
          print(message, file=sys.stderr)
          continue
        ground_truths = [x["text"] for x in qa["answers"]]
        # ground_truths = list(map(lambda x: x["text"], qa["answers"]))
        prediction = predictions[qa["id"]]
        exact_match += metric_max_over_ground_truths(exact_match_score,
                                                     prediction, ground_truths)
        f1 += metric_max_over_ground_truths(f1_score, prediction, ground_truths)

  exact_match = 100.0 * exact_match / total
  f1 = 100.0 * f1 / total

  return {"exact_match": exact_match, "f1": f1}

####### above are from official SQuAD v1.1 evaluation scripts
####### following are from official SQuAD v2.0 evaluation scripts 
开发者ID:google-research,项目名称:albert,代码行数:27,代码来源:squad_utils.py

示例8: readAtleast

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def readAtleast(transport, length, timeout):
  """
  Awaits reciept of at least length bytes from underlying transport, till timeout

  :param transport: Handle to a stream based transport
  :param timeout: Max amount to time to await for incoming data
  :param length: Length of data to read

  """
  import six
  LOGGER.debug('Awaiting data %d bytes', length)
  data = ''
  while len(data) < length:
    bufLen = length - len(data)
    block = transport.receive(bufLen, timeout)
    block = six.ensure_str(block)
    if block:
      data = data + block
    else:
      raise Exception('socket closed - failed to read datagram')

  logData = data if length < 400 else '{} ...'.format(data[0:45])
  LOGGER.debug('Received data |%s|', logData)
  return data 
开发者ID:Morgan-Stanley,项目名称:Xpedite,代码行数:26,代码来源:__init__.py

示例9: downloadFile

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def downloadFile(url, path):
  """
  Downloads micro architecture specifications from internet

  :param url: url of the website hosting the specifications
  :param path: Path of download directory

  """
  import six
  try:
    connection = urllib.request.urlopen(urllib.request.Request(url), context=CONFIG.sslContext)
    data = connection.read()
    with open(path, 'w') as fileHandle:
      fileHandle.write(six.ensure_str(data))
    return True
  except urllib.error.HTTPError as ex:
    LOGGER.exception('failed to retrieve file "%s" from url - %s', os.path.basename(path), url)
    raise Exception(ex)
  except IOError:
    LOGGER.exception('failed to open file - %s', path) 
开发者ID:Morgan-Stanley,项目名称:Xpedite,代码行数:22,代码来源:uarchSpecLoader.py

示例10: retrieve_pod_logs

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def retrieve_pod_logs(self, pod_name, namespace):
        '''Retrieves the raw pod logs for the pod named `pod_name` from Kubernetes.

        Args:
            pod_name (str): The name of the pod from which to retrieve logs.
            namespace (str): The namespace of the pod.

        Returns:
            str: The raw logs retrieved from the pod.
        '''
        check.str_param(pod_name, 'pod_name')
        check.str_param(namespace, 'namespace')

        # We set _preload_content to False here to prevent the k8 python api from processing the response.
        # If the logs happen to be JSON - it will parse in to a dict and then coerce back to a str leaving
        # us with invalid JSON as the quotes have been switched to '
        #
        # https://github.com/kubernetes-client/python/issues/811
        return six.ensure_str(
            self.core_api.read_namespaced_pod_log(
                name=pod_name, namespace=namespace, _preload_content=False
            ).data
        ) 
开发者ID:dagster-io,项目名称:dagster,代码行数:25,代码来源:client.py

示例11: model_eval_fn

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def model_eval_fn(
      self,
      features,
      labels,
      inference_outputs,
      train_loss,
      train_outputs,
      mode,
      config = None,
      params = None):
    """Log the streaming mean of any train outputs. See also base class."""
    if train_outputs is not None:
      eval_outputs = {}
      for key, value in train_outputs.items():
        eval_outputs['mean_' + six.ensure_str(key)] = tf.metrics.mean(value)
      return eval_outputs 
开发者ID:google-research,项目名称:tensor2robot,代码行数:18,代码来源:vrgripper_env_wtl_models.py

示例12: plot_labels

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def plot_labels(labels, max_label=1, predictions=None, name=''):
  """Plots integer labels and optionally predictions as images.

  By default takes the first 3 in the batch.

  Args:
    labels: Batch x 1 size tensor of labels
    max_label:  An integer indicating the largest possible label
    predictions: Batch x max_label size tensor of predictions (range 0-1.0)
    name: string to name tensorflow summary
  """
  if max_label > 1:
    labels = tf.one_hot(
        labels, max_label, on_value=1.0, off_value=0.0, dtype=tf.float32)
  labels_image = tf.reshape(labels[:3], (1, 3, max_label, 1))
  empty_image = tf.zeros((1, 3, max_label, 1))
  image = tf.concat([labels_image, empty_image, empty_image], axis=-1)
  if predictions is not None:
    pred_image = tf.reshape(predictions[:3], (1, 3, 4, 1))
    image2 = tf.concat([empty_image, pred_image, empty_image], axis=-1)
    image = tf.concat([image, image2], axis=1)
  tf.summary.image('labels_' + six.ensure_str(name), image, max_outputs=1) 
开发者ID:google-research,项目名称:tensor2robot,代码行数:24,代码来源:visualization.py

示例13: add_heatmap_summary

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def add_heatmap_summary(feature_query, feature_map, name):
  """Plots dot produce of feature_query on feature_map.

  Args:
    feature_query: Batch x embedding size tensor of goal embeddings
    feature_map: Batch x h x w x embedding size of pregrasp scene embeddings
    name: string to name tensorflow summaries
  Returns:
     Batch x h x w x 1 heatmap
  """
  batch, dim = feature_query.shape
  reshaped_query = tf.reshape(feature_query, (int(batch), 1, 1, int(dim)))
  heatmaps = tf.reduce_sum(
      tf.multiply(feature_map, reshaped_query), axis=3, keep_dims=True)
  tf.summary.image(name, heatmaps)
  shape = tf.shape(heatmaps)
  softmaxheatmaps = tf.nn.softmax(tf.reshape(heatmaps, (int(batch), -1)))
  tf.summary.image(
      six.ensure_str(name) + 'softmax', tf.reshape(softmaxheatmaps, shape))
  return heatmaps 
开发者ID:google-research,项目名称:tensor2robot,代码行数:22,代码来源:visualization.py

示例14: _authorization

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def _authorization(self, data):

        auth = "MediaBrowser "
        auth += "Client=%s, " % self.config.data.get('app.name', "Jellyfin for Kodi")
        auth += "Device=%s, " % self.config.data.get('app.device_name', 'Unknown Device')
        auth += "DeviceId=%s, " % self.config.data.get('app.device_id', 'Unknown Device id')
        auth += "Version=%s" % self.config.data.get('app.version', '0.0.0')

        data['headers'].update({'x-emby-authorization': ensure_str(auth, 'utf-8')})

        if self.config.data.get('auth.token') and self.config.data.get('auth.user_id'):

            auth += ', UserId=%s' % self.config.data.get('auth.user_id')
            data['headers'].update({
                'x-emby-authorization': ensure_str(auth, 'utf-8'),
                'X-MediaBrowser-Token': self.config.data.get('auth.token')})

        return data 
开发者ID:jellyfin,项目名称:jellyfin-kodi,代码行数:20,代码来源:http.py

示例15: get_default_headers

# 需要导入模块: import six [as 别名]
# 或者: from six import ensure_str [as 别名]
def get_default_headers(self):
        auth = "MediaBrowser "
        auth += "Client=%s, " % self.config.data['app.name']
        auth += "Device=%s, " % self.config.data['app.device_name']
        auth += "DeviceId=%s, " % self.config.data['app.device_id']
        auth += "Version=%s" % self.config.data['app.version']

        return {
            "Accept": "application/json",
            "Content-type": "application/x-www-form-urlencoded; charset=UTF-8",
            "X-Application": "%s/%s" % (self.config.data['app.name'], self.config.data['app.version']),
            "Accept-Charset": "UTF-8,*",
            "Accept-encoding": "gzip",
            "User-Agent": self.config.data['http.user_agent'] or "%s/%s" % (self.config.data['app.name'], self.config.data['app.version']),
            "x-emby-authorization": ensure_str(auth, 'utf-8')
        } 
开发者ID:jellyfin,项目名称:jellyfin-kodi,代码行数:18,代码来源:api.py


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