本文整理汇总了Python中markupsafe.escape_silent方法的典型用法代码示例。如果您正苦于以下问题:Python markupsafe.escape_silent方法的具体用法?Python markupsafe.escape_silent怎么用?Python markupsafe.escape_silent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类markupsafe
的用法示例。
在下文中一共展示了markupsafe.escape_silent方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_escape_silent
# 需要导入模块: import markupsafe [as 别名]
# 或者: from markupsafe import escape_silent [as 别名]
def test_escape_silent(self):
assert escape_silent(None) == Markup()
assert escape(None) == Markup(None)
assert escape_silent('<foo>') == Markup(u'<foo>')
示例2: get_header
# 需要导入模块: import markupsafe [as 别名]
# 或者: from markupsafe import escape_silent [as 别名]
def get_header(name):
if (name in request.headers):
return request.headers.get(escape(name))
else:
return None
示例3: index
# 需要导入模块: import markupsafe [as 别名]
# 或者: from markupsafe import escape_silent [as 别名]
def index(self, request):
try:
# patch __log
self.__log = self._GRest__log
__validation_rules__ = {
"skip": fields.Int(required=False,
validate=lambda skip: skip >= 0,
missing=0),
"limit": fields.Int(required=False,
validate=lambda lim: lim >= 1 and lim <= 100,
missing=QUERY_LIMIT),
"order_by": fields.Str(required=False,
missing="?")
}
(primary, secondary) = validate_models(self)
query_data = validate_input(__validation_rules__, request)
skip = query_data.get("skip")
limit = query_data.get("skip") + query_data.get("limit")
order_by = escape(query_data.get("order_by"))
if order_by:
if order_by.startswith("-"):
# select property for descending ordering
order_by_prop = order_by[1:]
else:
# select property for ascending ordering
order_by_prop = order_by
primary_model_props = primary.model.defined_properties().keys()
if all([order_by_prop not in primary_model_props,
order_by_prop != "?"]):
raise HTTPException(msg.INVALID_ORDER_PROPERTY, 404)
total_items = len(primary.model.nodes)
if total_items <= 0:
raise HTTPException(msg.NO_ITEM_EXISTS.format(
model=primary.model_name), 404)
if skip > total_items:
raise HTTPException(msg.VALIDATION_FAILED, 422)
items = primary.model.nodes.order_by(order_by)[skip:limit]
if items:
return serialize({pluralize(primary.model_name):
[item.to_dict() for item in items]})
else:
raise HTTPException(msg.NO_ITEM_EXISTS.format(
model=primary.model_name), 404)
except DoesNotExist as e:
self.__log.exception(e)
raise HTTPException(msg.ITEM_DOES_NOT_EXIST, 404)
示例4: validate_models
# 需要导入模块: import markupsafe [as 别名]
# 或者: from markupsafe import escape_silent [as 别名]
def validate_models(self,
primary_id=None,
secondary_model_name=None,
secondary_id=None):
class Primary:
id = None
model = None
model_name = None
selection_field = None
class Secondary:
id = None
model = None
model_name = None
selection_field = None
if primary_id:
Primary.id = escape(unquote(primary_id))
Primary.model = self.__model__.get("primary")
Primary.model_name = Primary.model.__name__.lower()
Primary.selection_field = self.__selection_field__.get("primary")
if secondary_model_name:
Secondary.model_name = escape(unquote(secondary_model_name))
if secondary_id:
Secondary.id = escape(unquote(secondary_id))
Secondary.model = Secondary.selection_field = None
if "secondary" in self.__model__:
Secondary.model = self.__model__.get(
"secondary").get(Secondary.model_name)
if "secondary" in self.__selection_field__:
Secondary.selection_fields = self.__selection_field__.get(
"secondary")
Secondary.selection_field = Secondary.selection_fields.get(
Secondary.model_name)
if all([Secondary.model_name is not None,
Secondary.model is None]):
raise HTTPException(msg.RELATION_DOES_NOT_EXIST, 404)
return (Primary, Secondary)