本文整理汇总了Python中dNG.data.text.l10n.L10n.get方法的典型用法代码示例。如果您正苦于以下问题:Python L10n.get方法的具体用法?Python L10n.get怎么用?Python L10n.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dNG.data.text.l10n.L10n
的用法示例。
在下文中一共展示了L10n.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _prepare_error_response
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _prepare_error_response(self):
"""
Prepares an error response.
:since: v1.0.0
"""
errors = self.errors
self.reset()
if (not self.are_headers_sent):
self.init(False, True)
header = self.get_header("HTTP", True)
if (header is None): self.set_header("HTTP", "HTTP/2.0 500 Internal Server Error", True)
#
self.result = ({ "error": { "title": L10n.get("core_title_error"),
"message": (L10n.get("errors_core_unknown_error")
if (header is None) else
header
)
}
}
if (errors is None) else
{ "error": ({ "messages": errors }
if (len(errors) > 1) else
errors[0]
)
}
)
示例2: _prepare_error_response
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _prepare_error_response(self):
"""
Prepares an error response.
:since: v1.0.0
"""
errors = self.errors
self.reset()
if (not self.are_headers_sent):
self.init(False, True)
header = self.get_header("HTTP", True)
if (header is None): self.set_header("HTTP", "HTTP/2.0 500 Internal Server Error", True)
#
self.content = ""
if (errors is None):
error = { "title": L10n.get("core_title_error"),
"message": (L10n.get("errors_core_unknown_error") if (header is None) else header)
}
self.page_title = error['title']
self.add_oset_content("core.error", error)
else:
for error in errors:
if (self.page_title is None): self.page_title = error['title']
self.add_oset_content("core.error", error)
示例3: execute_delete
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def execute_delete(self):
"""
Action for "delete"
:since: v0.2.00
"""
cid = InputFilter.filter_file_path(self.request.get_dsd("mcid", ""))
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 (source_iline == ""): source_iline = "m=mp;a=list_root_containers"
if (target_iline == ""): target_iline = source_iline
L10n.init("mp_core")
session = (self.request.get_session() if (self.request.is_supported("session")) else None)
user_profile = (None if (session is None) else session.get_user_profile())
if (user_profile is None
or (not user_profile.is_type("ad"))
): raise TranslatableError("core_access_denied", 403)
try: mp_entry = MpEntry.load_id(cid)
except NothingMatchedException as handled_exception: raise TranslatableError("mp_core_cid_invalid", 404, _exception = handled_exception)
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 DatabaseTasks.is_available()): raise TranslatableException("pas_core_tasks_daemon_not_available")
mp_entry.delete()
database_tasks = DatabaseTasks.get_instance()
database_tasks.add("dNG.pas.upnp.Resource.onDeleted.{0}".format(cid), "dNG.pas.upnp.Resource.onDeleted", 1, container_id = cid)
database_tasks.add("dNG.pas.upnp.Resource.onRootContainerDeleted.{0}".format(cid), "dNG.pas.upnp.Resource.onRootContainerDeleted", 1, container_id = cid)
target_iline = re.sub("\\_\\w+\\_\\_", "", target_iline)
NotificationStore.get_instance().add_completed_info(L10n.get("mp_core_done_root_container_delete"))
Link.clear_store("servicemenu")
redirect_request = PredefinedHttpRequest()
redirect_request.set_iline(target_iline)
self.request.redirect(redirect_request)
示例4: handle_error
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def handle_error(self, message):
"""
"handle_error()" is called to send a error message.
:param message: Message (will be translated if possible)
:since: v1.0.0
"""
message = L10n.get("errors_{0}".format(message), message)
if (self.errors is None): self.errors = [ { "title": L10n.get("core_title_error"), "message": message } ]
else: self.errors.append({ "title": L10n.get("core_title_error"), "message": message })
示例5: execute_logout
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [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)
示例6: execute_subscribe
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def execute_subscribe(self):
#
"""
Action for "subscribe"
:since: v0.1.00
"""
_id = InputFilter.filter_file_path(self.request.get_dsd("oid", ""))
source_iline = InputFilter.filter_control_chars(self.request.get_dsd("source", "")).strip()
L10n.init("pas_http_datalinker")
L10n.init("pas_http_subscription")
if (self.response.is_supported("html_css_files")): self.response.add_theme_css_file("mini_default_sprite.min.css")
if (len(source_iline) > 0):
#
Link.set_store("servicemenu",
Link.TYPE_RELATIVE_URL,
L10n.get("core_back"),
{ "__query__": re.sub("\\_\\_\\w+\\_\\_", "", source_iline) },
icon = "mini-default-back",
priority = 7
)
#
session = (self.request.get_session() if (self.request.is_supported("session")) else None)
subscription_handler = self._get_subscription_handler(_id)
if (subscription_handler is None): NotificationStore.get_instance().add_error(L10n.get("errors_pas_http_subscription_not_subscribable"))
elif (not subscription_handler.is_subscribable_for_session_user(session)): NotificationStore.get_instance().add_error(L10n.get("errors_pas_http_subscription_not_subscribable"))
else:
#
subscription_handler.set_session(session)
if (not subscription_handler.is_subscribed()): subscription_handler.subscribe()
NotificationStore.get_instance().add_completed_info(L10n.get("pas_http_subscription_done_subscribe"))
#
source_iline = re.sub("\\_\\_\\w+\\_\\_", "", source_iline)
Link.clear_store("servicemenu")
redirect_request = PredefinedHttpRequest()
redirect_request.set_iline(source_iline)
self.request.redirect(redirect_request)
示例7: render_rewrite_date_time_xhtml
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def render_rewrite_date_time_xhtml(self, source, key, _type):
"""
Renders a date and time XHTML 5 tag based on the given presentation type.
:param source: Source for rewrite
:param key: Key in source for rewrite
:param _type: Presentation type
:return: (str) Rewritten statement if successful
:since: v1.0.0
"""
if (self._log_handler is not None): self._log_handler.debug("#echo(__FILEPATH__)# -{0!r}.render_rewrite_date_time_xhtml({1}, {2})- (#echo(__LINE__)#)", self, key, _type, context = "pas_tag_parser")
_return = L10n.get("core_unknown")
timestamp = self.get_source_value(source, key)
if (timestamp is not None):
time_attributes = { "tag": "time", "attributes": { "datetime": "{0}+00:00".format(RfcBasics.get_iso8601_datetime(timestamp)) } }
_return = "{0}{1}</time>".format(XmlParser().dict_to_xml_item_encoder(time_attributes, False),
self.render_rewrite_date_time(source, key, _type)
)
#
return _return
示例8: handle_result
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def handle_result(self, urn, action, result):
"""
Returns a UPNP response for the given URN and SOAP action.
:param urn: UPnP URN called
:param action: SOAP action called
:param result: UPnP result arguments
:since: v0.2.00
"""
if (isinstance(result, Exception)):
if (isinstance(result, UpnpException)): self.send_error(result.get_upnp_code(), "{0:l10n_message}".format(result))
else: self.send_error(501, L10n.get("errors_core_unknown_error"))
else:
xml_resource = XmlResource(node_type = OrderedDict)
client_settings = self.get_client_settings()
if (not client_settings.get("upnp_xml_cdata_encoded", False)): xml_resource.set_cdata_encoding(False)
xml_resource.add_node("s:Envelope", attributes = { "xmlns:s": "http://schemas.xmlsoap.org/soap/envelope/", "s:encodingStyle": "http://schemas.xmlsoap.org/soap/encoding/" })
xml_base_path = "s:Envelope s:Body u:{0}Response".format(action)
xml_resource.add_node(xml_base_path, attributes = { "xmlns:u": urn })
xml_resource.set_cached_node(xml_base_path)
for result_value in result: xml_resource.add_node("{0} {1}".format(xml_base_path, result_value['name']), result_value['value'])
self.data = Binary.utf8_bytes("<?xml version='1.0' encoding='UTF-8' ?>{0}".format(xml_resource.export_cache(True)))
示例9: init_cds_id
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def init_cds_id(self, _id, client_user_agent = None, deleted = False):
"""
Initialize a UPnP resource by CDS ID.
:param _id: UPnP CDS ID
:param client_user_agent: Client user agent
:param update_id: UPnP UpdateID value
:param deleted: True to include deleted resources
:return: (bool) Returns true if initialization was successful.
:since: v0.2.00
"""
if (self.log_handler is not None): self.log_handler.debug("#echo(__FILEPATH__)# -{0!r}.init_cds_id({1})- (#echo(__LINE__)#)", self, _id, context = "pas_upnp")
_return = Abstract.init_cds_id(self, _id, client_user_agent, deleted)
if (_id == "0"):
self.name = L10n.get("pas_upnp_container_root")
self.type = RootContainer.TYPE_CDS_CONTAINER
search_segments = Hook.call("dNG.pas.upnp.Resource.getSearchSegments", id = _id)
self.searchable = (type(search_segments) is list and len(search_segments) > 0)
else: _return = True
return _return
示例10: _apply_form
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _apply_form(self, form, document = None):
"""
Applies document form fields to given form instance.
:param form: Form instance
:param document: Document to get default data values from
:since: v0.2.00
"""
document_data = ({ "title": None, "tag": None, "content": None, "description": None }
if (document is None) else
document.get_data_attributes("title", "tag", "content", "description")
)
field = TextField("ctitle")
field.set_title(L10n.get("pas_http_contentor_document_title"))
field.set_value(document_data['title'])
field.set_required()
field.set_size(TextField.SIZE_LARGE)
field.set_limits(int(Settings.get("pas_http_contentor_document_title_min", 3)))
form.add(field)
field = TextField("ctag")
field.set_title(L10n.get("pas_http_contentor_document_tag"))
field.set_value(document_data['tag'])
field.set_size(TextField.SIZE_SMALL)
field.set_limits(_max = 255)
field.set_validators([ self._check_tag_unique ])
form.add(field)
field = FormTagsTextareaField("cdescription")
field.set_title(L10n.get("pas_http_contentor_document_description"))
field.set_value(document_data['description'])
field.set_size(FormTagsTextareaField.SIZE_SMALL)
field.set_limits(_max = 255)
form.add(field)
field = FormTagsTextareaField("ccontent")
field.set_title(L10n.get("pas_http_contentor_document_content"))
field.set_value(document_data['content'])
field.set_required()
field.set_size(FormTagsTextareaField.SIZE_LARGE)
field.set_limits(int(Settings.get("pas_http_contentor_document_content_min", 6)))
form.add(field)
示例11: _get_form_action_new_title
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _get_form_action_new_title(self):
#
"""
Returns the title used for the new action of an form field entry.
:return: (str) Title used for the new action of an form field entry
:since: v0.1.00
"""
return L10n.get("pas_http_core_form_element_entry_new")
示例12: _render_root_container
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _render_root_container(self, root_container):
"""
Renders the UPnP root container.
:return: (str) Post XHTML
:since: v0.2.00
"""
root_container_data = root_container.get_data_attributes("id",
"title",
"resource"
)
content = { "id": root_container_data['id'],
"title": root_container_data['title'],
"resource": root_container_data['resource']
}
options = [ { "title": L10n.get("mp_core_root_container_edit"),
"type": (Link.TYPE_RELATIVE_URL | Link.TYPE_JS_REQUIRED),
"parameters": { "m": "mp",
"s": "root_container",
"a": "edit",
"dsd": { "mcid": root_container_data['id'] }
}
},
{ "title": L10n.get("mp_core_root_container_delete"),
"type": Link.TYPE_RELATIVE_URL,
"parameters": { "m": "mp",
"s": "root_container",
"a": "delete",
"dsd": { "mcid": root_container_data['id'] }
}
}
]
content['options'] = { "entries": options }
parser = FileParser()
parser.set_oset(self.response.get_oset())
_return = parser.render("mp.list_container", content)
return _return
示例13: _get_empty_view_content
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _get_empty_view_content(self):
#
"""
Returns content for an empty dynamic field.
:return: (str) Valid XHTML form field content for an empty dynamic field
:since: v0.1.00
"""
status_attributes = ({ "tag": "div",
"attributes": { "class": "pageform_error" },
"value": L10n.get("pas_http_core_form_error_required_element")
}
if (self.request.get_dsd("oform_field_required") == "1") else
{ "tag": "div",
"value": L10n.get("pas_http_core_form_element_entry_empty")
}
)
return XmlParser().dict_to_xml_item_encoder(status_attributes)
示例14: _check_tos_accepted
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def _check_tos_accepted(self, field, validator_context):
"""
Form validator that checks if the TOS have been accepted.
:param field: Form field
:param validator_context: Form validator context
:return: (str) Error message; None on success
:since: v0.2.00
"""
return (None if (field.get_value() == "accepted") else L10n.get("pas_http_user_form_error_tos_required"))
示例15: redirect
# 需要导入模块: from dNG.data.text.l10n import L10n [as 别名]
# 或者: from dNG.data.text.l10n.L10n import get [as 别名]
def redirect(self, url):
"""
Redirect the requesting client to the given URL.
:param url: Target URL
:since: v1.0.0
"""
AbstractHttpResponse.redirect(self, url)
if (self.page_title is None): self.page_title = L10n.get("pas_http_core_loading_additional_data")
self.add_oset_content("core.redirection", { "url": url })