本文整理汇总了Python中dNG.data.settings.Settings类的典型用法代码示例。如果您正苦于以下问题:Python Settings类的具体用法?Python Settings怎么用?Python Settings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Settings类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _is_file_access_allowed
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
示例2: __init__
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")))
示例3: get_user_agent_identifiers
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
示例4: _configure
def _configure(self):
"""
Configures the server
:since: v1.0.0
"""
listener_host = Settings.get("pas_http_twisted_server_host", self.socket_hostname)
self.port = int(Settings.get("pas_http_twisted_server_port", 8080))
self.reactor = reactor
self.reactor.addSystemEventTrigger('before', 'shutdown', self.stop)
server_description = "tcp:{0:d}".format(self.port)
if (listener_host == ""): self.host = Settings.get("pas_http_server_preferred_hostname", self.socket_hostname)
else:
self.host = listener_host
server_description += ":interface={0}".format(self.host)
#
self.thread_pool = ThreadPool()
self.thread_pool.start()
if (self._log_handler is not None): self._log_handler.info("pas.http.core Twisted server starts at '{0}:{1:d}'", listener_host, self.port, context = "pas_http_core")
server = serverFromString(self.reactor, server_description)
server.listen(Site(WSGIResource(reactor, self.thread_pool, HttpWsgi1Request)))
"""
Configure common paths and settings
"""
AbstractServer._configure(self)
示例5: theme
def theme(self, theme):
"""
Sets the theme to use.
:param theme: Output theme
:since: v1.0.0
"""
theme = Binary.str(theme)
"""
Set theme or reset to None to use the default one configured
"""
if (theme is None): self._theme = None
else:
theme_path = InputFilter.filter_file_path(theme).replace(".", path.sep)
file_path_name = path.join(self.path, theme_path, "site.tsc")
if (os.access(file_path_name, os.R_OK)): self._theme = theme
else: self._theme = None
#
"""
Read corresponding theme configuration
"""
if (self._theme is None): file_path_name = path.join(self.path, self.theme.replace(".", path.sep), "site.tsc")
file_path_name = file_path_name[:-3] + "json"
Settings.read_file(file_path_name)
示例6: __init__
def __init__(self):
"""
Constructor __init__(GstVideo)
:since: v0.2.00
"""
AbstractVideo.__init__(self)
Gstreamer.__init__(self)
self.playback_control_timeout = 5
"""
Playback control command timeout.
"""
self.thumbnail_position_percentage = 0.05
"""
Position in percent where to generate a thumbnail from.
"""
playback_control_timeout = float(Settings.get("pas_gapi_gstreamer_playback_control_timeout", 0))
if (playback_control_timeout > 0): self.playback_control_timeout = playback_control_timeout
self.supported_features['thumbnail'] = True
thumbnail_position_percentage = Settings.get("pas_gapi_gstreamer_thumbnail_position_percentage", 0)
if (thumbnail_position_percentage > 0
and thumbnail_position_percentage <= 100
): self.thumbnail_position_percentage = (thumbnail_position_percentage / 100)
示例7: __init__
def __init__(self):
"""
Constructor __init__(Module)
:since: v0.2.00
"""
AbstractHttpController.__init__(self)
Settings.read_file("{0}/settings/pas_http_user.json".format(Settings.get("path_data")))
示例8: get_user_agent_settings
def get_user_agent_settings(user_agent):
"""
Returns the user agent specific client settings dictionary.
:param user_agent: User agent
:return: (dict) User agent specific client settings; None on error
:since: v0.2.00
"""
_return = { }
settings = None
user_agent = Binary.str(user_agent)
if (type(user_agent) is str):
settings = Hook.call("dNG.pas.upnp.Client.getUserAgentSettings", user_agent = user_agent)
if (not isinstance(settings, dict)):
identifier = ClientSettings.get_user_agent_identifiers(user_agent)
settings_file_name = "{0}.json".format(identifier)
settings = JsonFileContent.read(path.join(Settings.get("path_data"),
"upnp",
"user_agents",
settings_file_name
)
)
if (settings is None):
log_line = "pas.upnp.ClientSettings reporting: No client settings found for user agent '{0}' with identifier '{1}'"
if (Settings.get("pas_upnp_log_missing_user_agent", False)): LogLine.warning(log_line, user_agent, identifier, context = "pas_upnp")
else: LogLine.debug(log_line, user_agent, identifier, context = "pas_upnp")
#
#
#
if (settings is not None):
if ("client_file" in settings):
base_settings = JsonFileContent.read(path.join(Settings.get("path_data"),
"upnp",
"user_agents",
InputFilter.filter_file_path(settings['client_file'])
)
)
if (type(base_settings) is dict): _return.update(base_settings)
del(settings['client_file'])
#
_return.update(settings)
#
return _return
示例9: oset
def oset(self, oset):
"""
Sets the OSet to use.
:param oset: OSet name
:since: v1.0.0
"""
self._oset = oset
Settings.set("x_pas_http_oset", self._oset)
示例10: send
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
示例11: is_available
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")
示例12: execute_logout
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)
示例13: _get_implementation_class_name
def _get_implementation_class_name():
"""
Returns the media implementation class name based on the configuration set.
:return: (str) Media implementation class name
:since: v0.2.00
"""
Settings.read_file("{0}/settings/pas_media.json".format(Settings.get("path_data")))
_return = Settings.get("pas_media_video_implementation", "")
if (_return == ""): LogLine.warning("Media video implementation class is not configured")
return _return
示例14: __init__
def __init__(self, _type, control_point = None):
"""
Constructor __init__(ControlPointEvent)
:param _type: Event to be delivered
:param control_point: Control point scheduling delivery
:since: v0.2.00
"""
AbstractEvent.__init__(self, _type)
self.announcement_divider = None
"""
Divider for the announcements interval to set how many announcements will be within the interval
"""
self.announcement_interval = None
"""
Announcement interval
"""
self.configid = None
"""
UPnP configId value (configid.upnp.org)
"""
self.location = None
"""
UPnP HTTP location URL
"""
self.search_target = None
"""
M-SEARCH ST value
"""
self.target_host = None
"""
M-SEARCH response target host
"""
self.target_port = None
"""
M-SEARCH response target port
"""
self.usn = None
"""
UPnP USN
"""
Settings.read_file("{0}/settings/pas_upnp.json".format(Settings.get("path_data")))
self.announcement_divider = int(Settings.get("pas_upnp_announcement_divider", 3))
self.announcement_interval = int(Settings.get("pas_upnp_announcement_interval", 3600))
self.control_point = control_point
示例15: get_view
def get_view(self):
"""
Action for "view"
:since: v1.0.0
"""
cid = InputFilter.filter_file_path(self.request.get_parameter("cid", ""))
source_iline = InputFilter.filter_control_chars(self.request.get_parameter("source", "")).strip()
L10n.init("pas_http_core_contentfile")
Settings.read_file("{0}/settings/pas_http_contentfiles.json".format(Settings.get("path_data")))
contentfiles = Settings.get("pas_http_contentfiles_list", { })
if (type(contentfiles) is not dict): raise TranslatableError("pas_http_core_contentfile_cid_invalid", 404)
if (source_iline != ""):
if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("mini_default_sprite.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 (cid not in contentfiles
or "title" not in contentfiles[cid]
or "filepath" not in contentfiles[cid]
): raise TranslatableError("pas_http_core_contentfile_cid_invalid", 404)
file_content = FileContent.read(contentfiles[cid]['filepath'])
if (file_content is None): raise TranslatableError("pas_http_core_contentfile_cid_invalid", 404)
if (path.splitext(contentfiles[cid]['filepath'])[1].lower() == ".ftg"): file_content = FormTags.render(file_content)
content = { "title": contentfiles[cid]['title'],
"content": file_content
}
self.response.init()
self.response.page_title = contentfiles[cid]['title']
self.response.add_oset_content("core.simple_content", content)