]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix code examples in automap's documentation
authorYuri Baida <yuri.baida@gmail.com>
Fri, 26 Jun 2015 17:45:48 +0000 (10:45 -0700)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 26 Jun 2015 18:45:41 +0000 (14:45 -0400)
Fix camelize_classname and pluralize_collection functions as they didn't work as expected.
(cherry picked from commit 5717186122d5538e53205268846beb7143a3d4cc)

lib/sqlalchemy/ext/automap.py

index 23f54851811476102a93055c642e151fb7381477..b1f17eb4de3bb103537f2c7bf799790601514914 100644 (file)
@@ -188,7 +188,7 @@ scheme for class names and a "pluralizer" for collection names using the
         "'words_and_underscores' -> 'WordsAndUnderscores'"
 
         return str(tablename[0].upper() + \\
-                re.sub(r'_(\w)', lambda m: m.group(1).upper(), tablename[1:]))
+                re.sub(r'_([a-z])', lambda m: m.group(1).upper(), tablename[1:]))
 
     _pluralizer = inflect.engine()
     def pluralize_collection(base, local_cls, referred_cls, constraint):
@@ -196,10 +196,9 @@ scheme for class names and a "pluralizer" for collection names using the
         "'SomeTerm' -> 'some_terms'"
 
         referred_name = referred_cls.__name__
-        uncamelized = referred_name[0].lower() + \\
-                        re.sub(r'\W',
-                                lambda m: "_%s" % m.group(0).lower(),
-                                referred_name[1:])
+        uncamelized = re.sub(r'[A-Z]',
+                             lambda m: "_%s" % m.group(0).lower(),
+                             referred_name)[1:]
         pluralized = _pluralizer.plural(uncamelized)
         return pluralized