本文整理汇总了Python中inc.Commons.Commons.string_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Commons.string_from_file方法的具体用法?Python Commons.string_from_file怎么用?Python Commons.string_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inc.Commons.Commons
的用法示例。
在下文中一共展示了Commons.string_from_file方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_string_from_file
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import string_from_file [as 别名]
def test_string_from_file(self):
true_list = ['1', 'true', 't', 'yes', 'y', 'on', 'enabled', 'enable']
for true_str in true_list:
assert Commons.string_from_file(true_str)
false_list = ['0', 'false', 'f', 'no', 'n', 'off', 'disabled', 'disable']
for false_str in false_list:
assert not Commons.string_from_file(false_str)
null_list = ['', 'nul', 'null', 'none', 'nil']
for null_str in null_list:
assert Commons.string_from_file(null_str) is None
invalid_list = ["hello", "example", "test"]
for invalid_str in invalid_list:
assert Commons.string_from_file(invalid_str) == invalid_str
示例2: load_from_xml
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import string_from_file [as 别名]
def load_from_xml():
try:
doc = ElementTree.parse("config/config.xml")
except (OSError, IOError):
print("No current config, loading from default.")
doc = ElementTree.parse("config/config-default.xml")
new_hallo = Hallo()
root = doc.getroot()
new_hallo.default_nick = root.findtext("default_nick")
new_hallo.default_prefix = Commons.string_from_file(root.findtext("default_prefix"))
new_hallo.default_full_name = root.findtext("default_full_name")
new_hallo.function_dispatcher = FunctionDispatcher.from_xml(
ElementTree.tostring(root.find("function_dispatcher")), new_hallo)
user_group_list_xml = root.find("user_group_list")
for user_group_xml in user_group_list_xml.findall("user_group"):
user_group_obj = UserGroup.from_xml(ElementTree.tostring(user_group_xml), new_hallo)
new_hallo.add_user_group(user_group_obj)
server_list_xml = root.find("server_list")
for server_xml in server_list_xml.findall("server"):
server_obj = new_hallo.server_factory.new_server_from_xml(ElementTree.tostring(server_xml))
new_hallo.add_server(server_obj)
if root.find("permission_mask") is not None:
new_hallo.permission_mask = PermissionMask.from_xml(ElementTree.tostring(root.find("permission_mask")))
api_key_list_xml = root.find("api_key_list")
for api_key_xml in api_key_list_xml.findall("api_key"):
api_key_name = api_key_xml.findtext("name")
api_key_key = api_key_xml.findtext("key")
new_hallo.add_api_key(api_key_name, api_key_key)
return new_hallo
示例3: from_xml
# 需要导入模块: from inc.Commons import Commons [as 别名]
# 或者: from inc.Commons.Commons import string_from_file [as 别名]
def from_xml(xml_string, server):
"""
Loads a new Channel object from XML
:param xml_string: XML string representation of the channel
:type xml_string: str
:param server: Server the channel is on
:type server: Server.Server
"""
doc = minidom.parseString(xml_string)
new_name = doc.getElementsByTagName("channel_name")[0].firstChild.data
channel = Channel(new_name, server)
channel.logging = Commons.string_from_file(doc.getElementsByTagName("logging")[0].firstChild.data)
channel.use_caps_lock = Commons.string_from_file(doc.getElementsByTagName("caps_lock")[0].firstChild.data)
if len(doc.getElementsByTagName("password")) != 0:
channel.password = doc.getElementsByTagName("password")[0].firstChild.data
channel.passive_enabled = Commons.string_from_file(
doc.getElementsByTagName("passive_enabled")[0].firstChild.data)
channel.auto_join = Commons.string_from_file(doc.getElementsByTagName("auto_join")[0].firstChild.data)
if len(doc.getElementsByTagName("permission_mask")) != 0:
channel.permission_mask = PermissionMask.from_xml(doc.getElementsByTagName("permission_mask")[0].toxml())
return channel