def test_casers(): text = u"What is Love? Baby Don't Hurt Me" assert snake_case(text) == "what_is_love?_baby_don't_hurt_me" assert kebab_case(text) == "what-is-love?-baby-don't-hurt-me" assert camel_case(text) == "WhatIsLove?BabyDon'THurtMe" assert identifierify(snake_case(text)) == "what_is_love_baby_dont_hurt_me" assert identifierify(kebab_case(text), "-") == "what-is-love-baby-dont-hurt-me" assert identifierify(camel_case(text)) == "WhatIsLoveBabyDonTHurtMe" assert space_case("some_identifier") == "some identifier"
def __new__(cls, name, bases, namespace): variables = [] bindings = [] for key in list(namespace.keys()): value = namespace[key] if isinstance(value, Binding): dest_list = bindings elif isinstance(value, Variable): dest_list = variables else: dest_list = None if dest_list is not None: dest_list.append((key, value)) del namespace[key] namespace.setdefault("variables", {}).update(variables) namespace.setdefault("bindings", {}).update(bindings) # Figure out some sane defaults if "identifier" not in namespace: namespace["identifier"] = snake_case(camel_case_to_spaces(name)) if namespace.get("identifier") and not namespace.get("name"): namespace["name"] = space_case(namespace["identifier"]).title() return type.__new__(cls, name, bases, namespace)
def dispatch(self): data = json.loads(self.request.body.decode("UTF-8")) command = data.pop("command") func_name = "handle_%s" % snake_case(camel_case_to_spaces(command)) func = getattr(self, func_name, None) if not callable(func): return JsonResponse({"error": "No handler: %s" % func_name}) return func(data)