本文整理匯總了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)