本文整理汇总了Python中oslo_utils.encodeutils.to_utf8方法的典型用法代码示例。如果您正苦于以下问题:Python encodeutils.to_utf8方法的具体用法?Python encodeutils.to_utf8怎么用?Python encodeutils.to_utf8使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oslo_utils.encodeutils
的用法示例。
在下文中一共展示了encodeutils.to_utf8方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_bgp_peer
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def add_bgp_peer(self, speaker_as, peer_ip, peer_as,
auth_type='none', password=None):
curr_speaker = self.cache.get_bgp_speaker(speaker_as)
if not curr_speaker:
raise bgp_driver_exc.BgpSpeakerNotAdded(local_as=speaker_as,
rtid=self.routerid)
# Validate peer_ip and peer_as.
utils.validate_as_num('remote_as', peer_as)
utils.validate_ip_addr(peer_ip)
utils.validate_auth(auth_type, password)
if password is not None:
password = encodeutils.to_utf8(password)
curr_speaker.neighbor_add(address=peer_ip,
remote_as=peer_as,
enable_ipv4=True,
enable_ipv6=True,
password=password,
connect_mode=CONNECT_MODE_ACTIVE)
LOG.info(_LI('Added BGP Peer %(peer)s for remote_as=%(as)d to '
'BGP Speaker running for local_as=%(local_as)d.'),
{'peer': peer_ip, 'as': peer_as, 'local_as': speaker_as})
示例2: test_add_bgp_peer_with_password
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def test_add_bgp_peer_with_password(self):
self.os_ken_bgp_driver.add_bgp_speaker(FAKE_LOCAL_AS1)
self.assertEqual(1,
self.os_ken_bgp_driver.cache.get_hosted_bgp_speakers_count())
self.os_ken_bgp_driver.add_bgp_peer(FAKE_LOCAL_AS1,
FAKE_PEER_IP,
FAKE_PEER_AS,
FAKE_AUTH_TYPE,
FAKE_PEER_PASSWORD)
speaker = self.os_ken_bgp_driver.cache.get_bgp_speaker(FAKE_LOCAL_AS1)
speaker.neighbor_add.assert_called_once_with(
address=FAKE_PEER_IP,
remote_as=FAKE_PEER_AS,
enable_ipv4=True,
enable_ipv6=True,
password=encodeutils.to_utf8(FAKE_PEER_PASSWORD),
connect_mode=CONNECT_MODE_ACTIVE)
示例3: test_add_bgp_peer_with_unicode_password
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def test_add_bgp_peer_with_unicode_password(self):
self.os_ken_bgp_driver.add_bgp_speaker(FAKE_LOCAL_AS1)
self.assertEqual(1,
self.os_ken_bgp_driver.cache.get_hosted_bgp_speakers_count())
NEW_FAKE_PEER_PASSWORD = str(FAKE_PEER_PASSWORD)
self.os_ken_bgp_driver.add_bgp_peer(
FAKE_LOCAL_AS1,
FAKE_PEER_IP,
FAKE_PEER_AS,
FAKE_AUTH_TYPE,
NEW_FAKE_PEER_PASSWORD)
speaker = self.os_ken_bgp_driver.cache.get_bgp_speaker(FAKE_LOCAL_AS1)
speaker.neighbor_add.assert_called_once_with(
address=FAKE_PEER_IP,
remote_as=FAKE_PEER_AS,
enable_ipv4=True,
enable_ipv6=True,
password=encodeutils.to_utf8(NEW_FAKE_PEER_PASSWORD),
connect_mode=CONNECT_MODE_ACTIVE)
示例4: convert_str
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def convert_str(text):
"""Convert to native string.
Convert bytes and Unicode strings to native strings:
* convert to bytes on Python 2:
encode Unicode using encodeutils.safe_encode()
* convert to Unicode on Python 3: decode bytes from UTF-8
"""
if six.PY2:
return encodeutils.to_utf8(text)
else:
if isinstance(text, bytes):
return text.decode('utf-8')
else:
return text
示例5: _insert_into_alarm_action
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def _insert_into_alarm_action(self, conn, alarm_definition_id, actions,
alarm_state):
if actions is None:
return
for action in actions:
b_id = action.encode('utf8') if six.PY2 else action
row = conn.execute(self.select_nm_query,
b_id=b_id).fetchone()
if row is None:
raise exceptions.InvalidUpdateException(
"Non-existent notification id {} submitted for {} "
"notification action".format(encodeutils.to_utf8(action),
encodeutils.to_utf8(alarm_state)))
conn.execute(self.insert_aa_query,
b_alarm_definition_id=alarm_definition_id,
b_alarm_state=alarm_state.encode('utf8') if six.PY2 else alarm_state,
b_action_id=action.encode('utf8') if six.PY2 else action
)
示例6: generate_identifier
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def generate_identifier(result):
"""
Returns a fixed length identifier based on a hash of a combined set of
playbook/task values which are as close as we can guess to unique for each
task.
"""
# Determine the playbook file path to use for the ID
if result.task.playbook and result.task.playbook.path:
playbook_file = result.task.playbook.path
else:
playbook_file = ''
play_path = u'%s.%s' % (playbook_file, result.task.play.name)
# Determine the task file path to use for the ID
if result.task.file and result.task.file.path:
task_file = result.task.file.path
else:
task_file = ''
task_path = u'%s.%s' % (task_file, result.task.name)
# Combine both of the above for a full path
identifier_path = u'%s.%s' % (play_path, task_path)
# Assign the identifier as a hash of the fully unique path.
identifier = hashlib.sha1(encodeutils.to_utf8(identifier_path)).hexdigest()
return identifier
示例7: content_sha1
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def content_sha1(context):
"""
Used by the FileContent model to automatically compute the sha1
hash of content before storing it to the database.
"""
try:
content = context.current_parameters['content']
except AttributeError:
content = context
return hashlib.sha1(encodeutils.to_utf8(content)).hexdigest()
# Primary key columns are of these type.
示例8: process_bind_param
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def process_bind_param(self, value, dialect):
return zlib.compress(encodeutils.to_utf8(jsonutils.dumps(value)))
示例9: get_certificate
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def get_certificate(self):
if self._cert_container.certificate:
return encodeutils.to_utf8(
self._cert_container.certificate.payload)
return None
示例10: get_intermediates
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def get_intermediates(self):
if self._cert_container.intermediates:
intermediates = encodeutils.to_utf8(
self._cert_container.intermediates.payload)
return list(cert_parser.get_intermediates_pems(intermediates))
return None
示例11: get_private_key
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def get_private_key(self):
if self._cert_container.private_key:
return encodeutils.to_utf8(
self._cert_container.private_key.payload)
return None
示例12: get_private_key_passphrase
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def get_private_key_passphrase(self):
if self._cert_container.private_key_passphrase:
return encodeutils.to_utf8(
self._cert_container.private_key_passphrase.payload)
return None
示例13: _sign_instance_id
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def _sign_instance_id(self, instance_id):
secret = self.conf.metadata_proxy_shared_secret
secret = encodeutils.to_utf8(secret)
instance_id = encodeutils.to_utf8(instance_id)
return hmac.new(secret, instance_id, hashlib.sha256).hexdigest()
示例14: encode_body
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def encode_body(body):
"""Encode unicode body.
WebOb requires to encode unicode body used to update response body.
"""
return encodeutils.to_utf8(body)
示例15: _get_schema_sha1
# 需要导入模块: from oslo_utils import encodeutils [as 别名]
# 或者: from oslo_utils.encodeutils import to_utf8 [as 别名]
def _get_schema_sha1(schema_raw):
return hashlib.sha1(encodeutils.to_utf8(schema_raw)).hexdigest()