本文整理汇总了Python中dNG.data.settings.Settings.is_defined方法的典型用法代码示例。如果您正苦于以下问题:Python Settings.is_defined方法的具体用法?Python Settings.is_defined怎么用?Python Settings.is_defined使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dNG.data.settings.Settings
的用法示例。
在下文中一共展示了Settings.is_defined方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def send(self):
"""
Sends a message.
:since: v1.0.0
"""
if (self._log_handler is not None): self._log_handler.debug("#echo(__FILEPATH__)# -{0!r}.send()- (#echo(__LINE__)#)", self, context = "pas_email")
if (self.message is None): raise IOException("No message defined to be send")
if (not self.message.is_recipient_set): raise ValueException("No recipients defined for e-mail")
if (not self.message.is_subject_set): raise IOException("No subject defined for e-mail")
bcc_list = self.message.bcc
cc_list = self.message.cc
to_list = self.message.to
rcpt_list = to_list
if (len(bcc_list) > 0): rcpt_list = Client._filter_unique_list(rcpt_list, bcc_list)
if (len(cc_list) > 0): rcpt_list = Client._filter_unique_list(rcpt_list, cc_list)
is_auth_possible = False
smtp_user = None
smtp_password = None
if (Settings.is_defined("pas_smtp_client_user") and Settings.is_defined("pas_smtp_client_password")):
is_auth_possible = True
smtp_user = Settings.get("pas_smtp_client_user")
smtp_password = Settings.get("pas_smtp_client_password")
#
smtp_connection = None
try:
smtp_connection = (self._get_lmtp_connection()
if (Settings.is_defined("pas_smtp_client_lmtp_host")
or Settings.is_defined("pas_smtp_client_lmtp_path_name")
)
else self._get_smtp_connection()
)
if (is_auth_possible): smtp_connection.login(smtp_user, smtp_password)
if (not self.message.is_sender_set):
self.message.sender = (Settings.get("pas_email_sender_public")
if (Settings.is_defined("pas_email_sender_public")) else
Settings.get("pas_email_address_public")
)
#
sender = self.message.sender
smtp_connection.sendmail(sender, rcpt_list, self.message.as_string())
self.message = None
finally:
try:
if (smtp_connection is not None): smtp_connection.quit()
except SMTPServerDisconnected: pass
示例2: is_available
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def is_available():
"""
True if a persistent tasks executing scheduler is available.
:return: (bool) True if available
:since: v0.2.00
"""
if (not Settings.is_defined("pas_tasks_daemon_listener_address")):
Settings.read_file("{0}/settings/pas_tasks_daemon.json".format(Settings.get("path_data")))
#
return Settings.is_defined("pas_tasks_daemon_listener_address")
示例3: execute_logout
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def execute_logout(self):
"""
Action for "logout"
:since: v0.2.00
"""
source_iline = InputFilter.filter_control_chars(self.request.get_dsd("source", "")).strip()
target_iline = InputFilter.filter_control_chars(self.request.get_dsd("target", "")).strip()
if (target_iline == ""):
if (Settings.is_defined("pas_http_user_logout_default_target_lang_{0}".format(self.request.get_lang()))): target_iline = Settings.get("pas_http_user_logout_default_target_lang_{0}".format(self.request.get_lang()))
elif (Settings.is_defined("pas_http_user_logout_default_target")): target_iline = Settings.get("pas_http_user_logout_default_target")
else: target_iline = source_iline
#
L10n.init("pas_http_user")
if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("mini_default_sprite.min.css")
Link.set_store("servicemenu",
Link.TYPE_RELATIVE_URL,
L10n.get("core_back"),
{ "__query__": re.sub("\\_\\_\\w+\\_\\_", "", source_iline) },
icon = "mini-default-back",
priority = 7
)
if (not self.request.is_supported("session")): raise TranslatableError("core_unknown_error", 500)
session = Session.load(session_create = False)
if (session is not None):
session.delete()
self.request.set_session(None)
#
Link.clear_store("servicemenu")
target_iline = re.sub("\\_\\_\\w+\\_\\_", "", target_iline)
redirect_request = PredefinedHttpRequest()
redirect_request.set_module("output")
redirect_request.set_service("http")
redirect_request.set_action("done")
redirect_request.set_parameter_chained("title", L10n.get("pas_http_user_logout"))
redirect_request.set_parameter_chained("message", L10n.get("pas_http_user_done_logout"))
redirect_request.set_parameter_chained("target_iline", target_iline)
self.request.redirect(redirect_request)
示例4: get_user_agent_identifiers
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def get_user_agent_identifiers(user_agent):
"""
Returns a UPnP client based on the given HTTP or SSDP user agent value.
:param user_agent: HTTP or SSDP user agent value
:return: (object) UPnP client; None on error
:since: v0.2.00
"""
_return = ""
if (not Settings.is_defined("pas_upnp_client_replacement_list")): Settings.read_file("{0}/settings/pas_upnp.json".format(Settings.get("path_data")))
replacement_list = Settings.get("pas_upnp_client_replacement_list", None)
if (type(replacement_list) is dict):
replacement_list_keys = sorted(replacement_list.keys(), reverse = True)
for upnp_value in replacement_list_keys: user_agent = user_agent.replace(upnp_value, replacement_list[upnp_value])
#
for re_result in re.finditer("([\\d\\w\\.]+/([0-9\\.]+(\\W|$))+)", user_agent):
if (_return != ""): _return += "_"
_return += re.sub("\\W+", "_", re_result.group(1)).strip("_")
#
if (_return == ""): _return = re.sub("\\W+", "_", user_agent).lower()
else: _return = _return.lower()
return _return
示例5: __init__
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def __init__(self, scheme = None, host = None, port = None, path = None):
"""
Constructor __init__(Link)
:param scheme: URL scheme
:param host: URL host
:param port: URL port
:param path: URL path
:since: v0.2.00
"""
self.host = host
"""
Override for the URL host
"""
self.path = path
"""
Override for the URL path
"""
self.port = port
"""
Override for the URL port
"""
self.scheme = scheme
"""
Override for the URL scheme
"""
if (not Settings.is_defined("pas_http_site_preferred_url_base")): Settings.read_file("{0}/settings/pas_http.json".format(Settings.get("path_data")))
示例6: _is_file_access_allowed
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def _is_file_access_allowed(self, file_path_name):
"""
Checks if the file access is allowed for streaming.
:param file_path_name: Path to the requested file
:return: (bool) True if allowed
:since: v0.2.00
"""
_return = False
if Settings.is_defined("pas_streamer_file_basedir_list"):
basedir_list = Settings.get("pas_streamer_file_basedir_list")
if type(basedir_list) is list:
file_absolute_path_name = path.abspath(file_path_name)
for basedir in basedir_list:
if file_absolute_path_name.startswith(basedir):
_return = True
break
#
#
if (not _return) and self.log_handler is not None:
self.log_handler.warning(
"streamer.File denied access to {0}", file_path_name, context="pas_streamer"
)
#
else:
_return = True
return _return
示例7: _ensure_settings
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def _ensure_settings():
"""
Check and read settings if needed.
:since: v1.0.0
"""
if (not Connection._settings_initialized):
with Connection._serialized_lock:
# Thread safety
if (not Connection._settings_initialized):
Settings.read_file("{0}/settings/pas_database.json".format(Settings.get("path_data")), True)
if (not Settings.is_defined("pas_database_url")): raise ValueException("Minimum database configuration missing")
url = Settings.get("pas_database_url").replace("__path_base__", path.abspath(Settings.get("path_base")))
if (not Settings.is_defined("pas_database_table_prefix")): Settings.set("pas_database_table_prefix", "pas")
Connection._serialized = (not Settings.get("pas_database_threaded", True))
if (Connection._serialized):
LogLine.debug("pas.database access is serialized", context = "pas_database")
Connection._serialized_lock.timeout = Settings.get("pas_database_lock_timeout", 30)
#
url_elements = urlsplit(url)
Settings.set("x_pas_database_backend_name", url_elements.scheme.split("+")[0])
if (url_elements.username is None
and url_elements.password is None
and Settings.is_defined("pas_database_user")
and Settings.is_defined("pas_database_password")
):
url = "{0}://{1}:{2}@{3}{4}".format(url_elements.scheme,
Settings.get("pas_database_user"),
Settings.get("pas_database_password"),
url_elements.hostname,
url_elements.path
)
if (url_elements.query != ""): url += "?{0}".format(url_elements.query)
if (url_elements.fragment != ""): url += "#{0}".format(url_elements.fragment)
#
Settings.set("pas_database_sqlalchemy_url", url)
Connection._settings_initialized = True
示例8: _get_lmtp_connection
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def _get_lmtp_connection(self):
"""
Returns an established LMTP connection.
:return: (object) LMTP connection
:since: v1.0.0
"""
smtp_options = { }
if (Settings.is_defined("pas_smtp_client_sender_hostname")): smtp_options['local_hostname'] = Settings.get("pas_smtp_client_sender_hostname")
_return = (LMTP(Settings.get("pas_smtp_client_lmtp_host"), int(Settings.get("pas_smtp_client_lmtp_port", 24)))
if (Settings.is_defined("pas_smtp_client_lmtp_host")) else
LMTP(Settings.get("pas_smtp_client_lmtp_path_name"))
)
return _return
示例9: execute_index
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def execute_index(self):
"""
Action for "index"
:since: v0.2.00
"""
if (self.request.is_dsd_set("cdid")): self.execute_view()
elif (self.request.is_dsd_set("ccid") or Settings.is_defined("pas_http_contentor_category_default")): self.execute_list()
示例10: execute_index
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def execute_index(self):
#
"""
Action for "index"
:since: v0.1.00
"""
if (self.request.is_dsd_set("dtid")): self.execute_topic()
elif (self.request.is_dsd_set("dpid")): self.execute_post()
elif (self.request.is_dsd_set("dlid") or Settings.is_defined("pas_http_discuss_list_default")): self.execute_list()
示例11: _on_run
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def _on_run(self, args):
"""
Callback for execution.
:param args: Parsed command line arguments
:since: v0.2.00
"""
# pylint: disable=attribute-defined-outside-init
Settings.read_file("{0}/settings/pas_global.json".format(Settings.get("path_data")))
Settings.read_file("{0}/settings/pas_core.json".format(Settings.get("path_data")), True)
Settings.read_file("{0}/settings/pas_tasks_daemon.json".format(Settings.get("path_data")), True)
if (args.additional_settings is not None): Settings.read_file(args.additional_settings, True)
if (not Settings.is_defined("pas_tasks_daemon_listener_address")): raise IOException("No listener address defined for the TasksDaemon")
if (args.reload_plugins):
client = BusClient("pas_tasks_daemon")
client.request("dNG.pas.Plugins.reload")
elif (args.stop):
client = BusClient("pas_tasks_daemon")
pid = client.request("dNG.pas.Status.getOSPid")
client.request("dNG.pas.Status.stop")
self._wait_for_os_pid(pid)
else:
self.cache_instance = NamedLoader.get_singleton("dNG.data.cache.Content", False)
if (self.cache_instance is not None): Settings.set_cache_instance(self.cache_instance)
self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
if (self.log_handler is not None):
Hook.set_log_handler(self.log_handler)
NamedLoader.set_log_handler(self.log_handler)
#
Hook.load("tasks")
Hook.register("dNG.pas.Status.getOSPid", self.get_os_pid)
Hook.register("dNG.pas.Status.getTimeStarted", self.get_time_started)
Hook.register("dNG.pas.Status.getUptime", self.get_uptime)
Hook.register("dNG.pas.Status.stop", self.stop)
self.server = BusServer("pas_tasks_daemon")
self._set_time_started(time())
if (self.log_handler is not None): self.log_handler.info("TasksDaemon starts listening", context = "pas_tasks")
Hook.call("dNG.pas.Status.onStartup")
Hook.call("dNG.pas.tasks.Daemon.onStartup")
self.set_mainloop(self.server.run)
示例12: _get_smtp_connection
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def _get_smtp_connection(self):
"""
Returns an established SMTP connection.
:return: (object) SMTP connection
:since: v1.0.0
"""
smtp_host = Settings.get("pas_smtp_client_host", "localhost")
smtp_port = int(Settings.get("pas_smtp_client_port", 25))
smtp_options = { }
is_tls_connection = Settings.get("pas_smtp_client_tls", False)
ssl_cert_file_path_name = ""
ssl_key_file_path_name = ""
if (Settings.is_defined("pas_smtp_client_ssl_cert_file") and Settings.is_defined("pas_smtp_client_ssl_key_file")):
ssl_cert_file_path_name = Settings.get("pas_smtp_client_ssl_cert_file")
ssl_key_file_path_name = Settings.get("pas_smtp_client_ssl_key_file")
if (ssl_cert_file_path_name + ssl_key_file_path_name == ""): raise IOException("TLS requested for incomplete configuration")
#
if (ssl_cert_file_path_name + ssl_key_file_path_name != "" and (not is_tls_connection)):
smtp_options['certfile'] = ssl_cert_file_path_name
smtp_options['keyfile'] = ssl_key_file_path_name
#
if (Settings.is_defined("pas_smtp_client_sender_hostname")): smtp_options['local_hostname'] = Settings.get("pas_smtp_client_sender_hostname")
_return = (SMTP_SSL(smtp_host, smtp_port, timeout = self.timeout, **smtp_options)
if ("keyfile" in smtp_options) else
SMTP(smtp_host, smtp_port, timeout = self.timeout, **smtp_options)
)
if (is_tls_connection): _return.starttls(ssl_key_file_path_name, ssl_cert_file_path_name)
return _return
示例13: get_preferred
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def get_preferred(context = None):
"""
Returns a "Link" instance based on the defined preferred URL.
:param context: Context for the preferred link
:return: (object) Link instance
:since: v0.2.00
"""
if (not Settings.is_defined("pas_http_site_preferred_url_base")): Settings.read_file("{0}/settings/pas_http.json".format(Settings.get("path_data")))
url = None
if (context is not None): url = Settings.get("pas_http_site_preferred_url_base_{0}".format(re.sub("\\W+", "_", context)))
if (url is None): url = Settings.get("pas_http_site_preferred_url_base")
if (url is None): raise ValueException("Preferred URL base setting is not defined")
url_elements = urlsplit(url)
return Link(url_elements.scheme, url_elements.hostname, url_elements.port, url_elements.path)
示例14: get_executing_class
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def get_executing_class(is_not_implemented_class_aware = False):
"""
Returns the persistent tasks implementation class responsible for scheduling
and execution based on the configuration set.
:param is_not_implemented_class_aware: True to return
"dNG.runtime.NotImplementedClass" instead of None
:return: (object) Tasks implementation class; None if not available
:since: v0.2.00
"""
if (not Settings.is_defined("pas_tasks_daemon_listener_address")):
Settings.read_file("{0}/settings/pas_tasks_daemon.json".format(Settings.get("path_data")))
#
implementation_class_name = Settings.get("pas_tasks_persistent_implementation", "Database")
_return = NamedLoader.get_class("dNG.data.tasks.{0}".format(implementation_class_name))
if (_return is None and is_not_implemented_class_aware): _return = NotImplementedClass
return _return
示例15: __init__
# 需要导入模块: from dNG.data.settings import Settings [as 别名]
# 或者: from dNG.data.settings.Settings import is_defined [as 别名]
def __init__(self):
"""
Constructor __init__(ControlPoint)
:since: v0.2.00
"""
AbstractTimed.__init__(self)
self.bootid = 0
"""
UPnP bootId value (bootid.upnp.org); nextbootid.upnp.org += 1
"""
self.configid = 0
"""
UPnP configId value (configid.upnp.org)
"""
self.devices = { }
"""
List of devices with its services
"""
self.gena = None
"""
UPnP GENA manager
"""
self.http_host = None
"""
HTTP Accept-Language value
"""
self.http_language = (L10n.get("lang_rfc_region") if (L10n.is_defined("lang_rfc_region")) else None)
"""
HTTP Accept-Language value
"""
self.http_port = None
"""
HTTP Accept-Language value
"""
self.listener_ipv4 = None
"""
Unicast IPv4 listener
"""
self.listener_port = int(Settings.get("pas_upnp_device_port", 1900))
"""
Unicast port in the range 49152-65535 (searchport.upnp.org)
"""
self.listeners_multicast = { }
"""
Multicast listeners
"""
self.listeners_multicast_ipv4 = 0
"""
Number of IPv4 multicast listeners
"""
self.listeners_multicast_ipv6 = 0
"""
Number of IPv6 multicast listeners
"""
self.managed_devices = { }
"""
List of managed devices
"""
self.rootdevices = [ ]
"""
List of UPnP root devices
"""
self.tasks = [ ]
"""
List of tasks (e.g. timed out services) to run
"""
self.upnp_desc = { }
"""
Received UPnP descriptions
"""
self.upnp_desc_unread = { }
"""
Unread UPnP description URLs
"""
self.usns = { }
"""
List of devices with its services
"""
Settings.read_file("{0}/settings/pas_upnp.json".format(Settings.get("path_data")))
self.log_handler = NamedLoader.get_singleton("dNG.data.logging.LogHandler", False)
if (self.http_language is None):
system_language = getlocale()[0]
http_language = (Settings.get("core_lang", "en_US")
if (system_language is None or system_language == "c") else
system_language
)
http_language = http_language.replace("_", "")
http_language = re.sub("\\W", "", http_language)
else: http_language = self.http_language.replace("_", "")
if (Settings.is_defined("core_lang_{0}".format(http_language))): http_language = Settings.get("core_lang_{0}".format(http_language))
elif (Settings.is_defined("core_lang_{0}".format(http_language[:2]))): http_language = Settings.get("core_lang_{0}".format(http_language[:2]))
#.........这里部分代码省略.........