本文整理汇总了Python中inflection.dasherize方法的典型用法代码示例。如果您正苦于以下问题:Python inflection.dasherize方法的具体用法?Python inflection.dasherize怎么用?Python inflection.dasherize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inflection
的用法示例。
在下文中一共展示了inflection.dasherize方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_field_names
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def format_field_names(obj, format_type=None):
"""
Takes a dict and returns it with formatted keys as set in `format_type`
or `JSON_API_FORMAT_FIELD_NAMES`
:format_type: Either 'dasherize', 'camelize', 'capitalize' or 'underscore'
"""
if format_type is None:
format_type = json_api_settings.FORMAT_FIELD_NAMES
if isinstance(obj, dict):
formatted = OrderedDict()
for key, value in obj.items():
key = format_value(key, format_type)
formatted[key] = value
return formatted
return obj
示例2: __call__
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def __call__(self, f: Callable[..., None]) -> template:
super().__call__(f)
self.name = dasherize(f.__code__.co_name)
source: List[str]
source, _ = inspect.getsourcelines(f.__code__)
co_start: int = 0
for i, line in enumerate(source):
if re.search(r"\)( -> (.+))?:[\s\n\r]+$", line):
co_start = i + 1
break
self.source = textwrap.dedent("".join(source[co_start:]))
tmpl = template(f)
tmpl.callable = False
tmpl.__closure__ = self.scope
return tmpl
示例3: format_value
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def format_value(value, format_type=None):
if format_type is None:
format_type = json_api_settings.FORMAT_FIELD_NAMES
if format_type == 'dasherize':
# inflection can't dasherize camelCase
value = inflection.underscore(value)
value = inflection.dasherize(value)
elif format_type == 'camelize':
value = inflection.camelize(value, False)
elif format_type == 'capitalize':
value = inflection.camelize(value)
elif format_type == 'underscore':
value = inflection.underscore(value)
return value
示例4: build_style_string
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def build_style_string(style, separator=' '):
"""
Creates key value pairs as a string for the given Style with the given separator
between the paris
:param style:
:param separator: Default ' '
:return:
"""
style_string = separator.join(
map_dict(
lambda key, value: '{key}: {value};'.format(key=dasherize(key), value=map_value(value)),
compact_dict(style)))
return style_string
示例5: __new__
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def __new__(
cls,
name: Union[str, Type["Workflow"]],
bases: Tuple[Type["Workflow"], ...],
props: Dict[str, Any],
**kwargs,
):
workflow_name = dasherize(underscore(name))
props["kind"] = "Workflow"
props["api_version"] = "argoproj.io/v1alpha1"
metadata_dict = dict(name=workflow_name, generate_name=f"{workflow_name}-")
metadata_dict.update(props.get("__metadata__", {}))
# Required fields
props["metadata"]: V1ObjectMeta = V1ObjectMeta(**metadata_dict)
props["spec"] = {
k: props.pop(k) for k in V1alpha1WorkflowSpec.attribute_map if props.get(k)
}
props["status"] = {}
bases = (*bases, cls.__model__)
klass = super().__new__(cls, name, bases, props)
if name == "Workflow":
# No need to initialize any further
return klass
cls.__compile(klass, name, bases, props)
return klass
示例6: __new__
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def __new__(cls, f: Callable[..., T]):
"""Workflow spec for V1alpha1Template."""
self = super().__new__(cls, f)
self.name = dasherize(f.__code__.co_name)
self.template: str = None
self.template_ref: V1alpha1TemplateRef = None
return self
示例7: __new__
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def __new__(cls, f: Callable[..., T]):
"""Workflow spec for V1alpha1Template."""
self = super().__new__(cls, f)
self.name = dasherize(f.__code__.co_name)
return self
示例8: _render_attributes
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def _render_attributes(self, resource):
"""Render the resources's attributes."""
attributes = {}
attrs_to_ignore = set()
for key, relationship in resource.__mapper__.relationships.items():
attrs_to_ignore.update(set(
[column.name for column in relationship.local_columns]).union(
{key}))
if self.dasherize:
mapped_fields = {x: dasherize(underscore(x)) for x in self.fields}
else:
mapped_fields = {x: x for x in self.fields}
for attribute in self.fields:
if attribute == self.primary_key:
continue
# Per json-api spec, we cannot render foreign keys
# or relationsips in attributes.
if attribute in attrs_to_ignore:
raise AttributeError
try:
value = getattr(resource, attribute)
if isinstance(value, datetime.datetime):
attributes[mapped_fields[attribute]] = value.isoformat()
else:
attributes[mapped_fields[attribute]] = value
except AttributeError:
raise
return attributes
示例9: _render_relationships
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def _render_relationships(self, resource):
"""Render the resource's relationships."""
relationships = {}
related_models = resource.__mapper__.relationships.keys()
primary_key_val = getattr(resource, self.primary_key)
if self.dasherize:
mapped_relationships = {
x: dasherize(underscore(x)) for x in related_models}
else:
mapped_relationships = {x: x for x in related_models}
for model in related_models:
relationships[mapped_relationships[model]] = {
'links': {
'self': '/{}/{}/relationships/{}'.format(
resource.__tablename__,
primary_key_val,
mapped_relationships[model]),
'related': '/{}/{}/{}'.format(
resource.__tablename__,
primary_key_val,
mapped_relationships[model])
}
}
return relationships
示例10: _api_type_for_model
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def _api_type_for_model(self, model):
return dasherize(tableize(model.__name__))
示例11: _tableize
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import dasherize [as 别名]
def _tableize(cls):
"""Tableize the model name.
:return:
"""
name = inflection.tableize(cls.__name__)
name = inflection.dasherize(name)
return name