本文整理汇总了Python中inflection.camelize方法的典型用法代码示例。如果您正苦于以下问题:Python inflection.camelize方法的具体用法?Python inflection.camelize怎么用?Python inflection.camelize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inflection
的用法示例。
在下文中一共展示了inflection.camelize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: format_field_names
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [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: get_context
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def get_context(version, name, model, plural_name):
name = inflection.underscore(inflection.singularize(name))
model = model or name
model_class_name = inflection.camelize(model)
class_name = inflection.camelize(name)
serializer_class_name = class_name + 'Serializer'
viewset_class_name = class_name + 'ViewSet'
plural_name = plural_name or inflection.pluralize(name)
return {
'version': version,
'serializer_class_name': serializer_class_name,
'viewset_class_name': viewset_class_name,
'model_class_name': model_class_name,
'name': name,
'plural_name': plural_name
}
示例3: __init__
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def __init__(self, model_dict=None, **kwargs):
"""All attributes are CamelCased"""
if isinstance(model_dict, dict):
try:
assert not kwargs
except AssertionError:
raise AssertionError(
'When using a dict to instantiate {0}, no other keywords should be supplied'.format(
self.__class__))
else:
kws = model_dict
elif model_dict is None:
kws = kwargs
else:
raise TypeError("Invalid arguments supplied")
for key, value in kws.items():
setattr(self, camelize(key.lower()),
value) # Maybe just strip all non-required fields?
self._validate_fields()
示例4: _normalize_parameters
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def _normalize_parameters(
params: Dict[str, str], normalizers: Dict[str, str]
) -> Dict[str, str]:
normalized = params.copy()
for key, value in params.items():
normalized.pop(key)
if not value:
continue
key_inflected = camelize(underscore(key), uppercase_first_letter=True)
# Only include parameters found in normalizers
key_overrider = normalizers.get(key_inflected.lower())
if key_overrider:
normalized[key_overrider] = value
return normalized
示例5: get_mod
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def get_mod(mod_name):
"""Imports a mod from its name using `importlib`.
Args:
mod_name: The name of the mod (snake_case of CamelCase are accepted).
Returns:
The python class which corresponds to the modification.
Raises:
ImportError: The class was not found or it is not a subclass of `Mod`.
Examples:
>>> get_mod("DropOne")
<class 'fragscapy.modifications.drop_one.DropOne'>
>>> get_mod("drop_one")
<class 'fragscapy.modifications.drop_one.DropOne'>
"""
pkg_name = "{}.{}".format(MOD_PACKAGE, inflection.underscore(mod_name))
mod_name = inflection.camelize(mod_name)
pkg = importlib.import_module(pkg_name)
try:
mod = getattr(pkg, mod_name)
except AttributeError: # There is no class named correctly
raise ImportError(
"No class named {} in module {}"
.format(mod_name, pkg_name)
)
if not issubclass(mod, Mod):
raise ImportError(
"{}.{} is not a subclass of `fragscapy.modifications.mod.Mod`"
.format(pkg_name, mod_name)
)
return mod
示例6: flatten_key
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def flatten_key(k, parent_key, sep):
full_key = parent_key + [k]
inflected_key = [inflect_column_name(n) for n in full_key]
reducer_index = 0
while len(sep.join(inflected_key)) >= 63 and reducer_index < len(inflected_key):
reduced_key = re.sub(r'[a-z]', '', inflection.camelize(inflected_key[reducer_index]))
inflected_key[reducer_index] = \
(reduced_key if len(reduced_key) > 1 else inflected_key[reducer_index][0:3]).lower()
reducer_index += 1
return sep.join(inflected_key)
示例7: function_definition_name
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def function_definition_name(header_name):
return camelize(header_name.replace(".h", "")).replace(" ", "")
示例8: generate_main_loader
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def generate_main_loader(modules):
modules = list(sorted(modules))
s = [common_includes]
a = s.append
for module in modules:
a("void define%sClasses(py::module &);" % camelize(module))
a("")
a("void defineClasses(py::module &m) {")
for module in modules:
a("%sdefine%sClasses(m);" % (INDENT, camelize(module)))
a("}")
return "\n".join(s)
示例9: generate_instantiation_function
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def generate_instantiation_function(self, global_indent="", has_functions=False):
"""
void define...Classes(py::module &m) { ... }
"""
s = []
a = s.append
i = INDENT
a("{ind}void define{sub}{name}Classes(py::module &{base}) {ob}")
for var in self.variables:
a("{ind}{i}%s" % define_variable(var))
for enum in self.enums:
enum = Enum(enum)
a("{ind}{i}%s;" % enum.to_str(prefix=enum.cppenum["namespace"], class_var_name=BASE_SUB_MODULE_NAME))
for line in self.generate_templated_class_calls():
a("{ind}{i}%s;" % line)
if has_functions:
a("{ind}{i}define{sub}{name}Functions({base});")
a("{ind}{cb}")
data = {
"ind": global_indent,
"i": i,
"base": BASE_SUB_MODULE_NAME,
"name": function_definition_name(self.header_name),
"sub": camelize(self.module),
"ob": "{",
"cb": "}"
}
return "\n".join([line.format(**data) for line in s])
示例10: generate_templated_class_calls
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def generate_templated_class_calls(self):
s = []
for c in self.sorted_classes:
template_types = []
if c.get("template"):
template_info = re.findall(r"<(.+)>", str(c["template"].replace("\n", "")))
if template_info:
template_types = filter_template_types(template_info[0])
if template_types:
sub_module_name = self.sub_module_name(c["name"])
types_list = self.classes_point_types.get(c["name"], [])
if types_list:
s.append(self.repr_sub_module(c["name"]))
for types in types_list:
type_names = "_".join(map(format_class_name, types))
define = 'define{sub}{name}<{types}>({sub_module_name}, "{types_names}")'
add_pcl = lambda t: ("pcl::" + t) if t not in KEEP_ASIS_TYPES else t
types_str = ", ".join([add_pcl(t) for t in types])
define = define.format(sub=camelize(self.module),
name=c["name"],
sub_module_name=sub_module_name,
types=types_str,
types_names=type_names)
s.append(define)
else:
define = 'define{sub}{name}({sub_name})'
define = define.format(sub=camelize(self.module), name=c["name"], sub_name=BASE_SUB_MODULE_NAME)
s.append(define)
return s
示例11: generate_loader
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def generate_loader(module, headers):
lines = [common_includes]
a = lines.append
a(cpp_header)
for header in headers:
inc_name = '%s/%s' % (module, header) if module != "base" else header
include_expression = '#include "%spp"' % (inc_name,)
a(include_expression)
a("\n")
a("void define%sClasses(py::module &m) {" % camelize(module))
# add submodule
submodule_object_name = ("m_%s" % module) if module != "base" else "m"
module_python = module if module != "2d" else "module_2d"
if submodule_object_name != "m":
module_creation = '{i}py::module {obj_name} = m.def_submodule("{module_python}", "Submodule {sub}");'
a(module_creation.format(obj_name=submodule_object_name, module_python=module_python, sub=module, i=INDENT))
# add function calls
sub = camelize(module) if module != "base" else ""
for header in headers:
name = function_definition_name(header_name=header)
function_call = "{i}define{sub}{name}Classes({sub_name});".format(i=INDENT,
name=name,
sub_name=submodule_object_name,
sub=sub)
a(function_call)
a("}")
return "\n".join(lines)
示例12: format_value
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [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
示例13: __new__
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def __new__(meta, name, bases, attrs):
for name, attr in six.iteritems(attrs):
if isinstance(attr, types.BaseType):
camelized = inflection.camelize(name, uppercase_first_letter=False)
attr.serialized_name = attr.serialized_name or camelized
attr.deserialize_from = attr.deserialize_from or camelized
return super(BetfairModelMeta, meta).__new__(meta, name, bases, attrs)
示例14: camel
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def camel(self, data, many=None):
items = []
if many:
for i in data:
items.append(
{
camelize(key, uppercase_first_letter=False): value
for key, value in i.items()
}
)
return items
return {
camelize(key, uppercase_first_letter=False): value
for key, value in data.items()
}
示例15: format_errors
# 需要导入模块: import inflection [as 别名]
# 或者: from inflection import camelize [as 别名]
def format_errors(messages):
errors = {}
for k, v in messages.items():
key = camelize(k, uppercase_first_letter=False)
if isinstance(v, dict):
errors[key] = format_errors(v)
elif isinstance(v, list):
errors[key] = v[0]
return errors