]> code.communitydata.science - rises_declines_wikia_code.git/blob - mediawiki_dump_tools/Mediawiki-Utilities/mw/lib/title/functions.py
add copy of the GPL
[rises_declines_wikia_code.git] / mediawiki_dump_tools / Mediawiki-Utilities / mw / lib / title / functions.py
1 def normalize(title):
2     """
3     Normalizes a page title to the database format.  E.g. spaces are converted
4     to underscores and the first character in the title is converted to
5     upper-case.
6
7     :Parameters:
8         title : str
9             A page title
10     :Returns:
11         The normalized title.
12     :Example:
13         >>> from mw.lib import title
14         >>>
15         >>> title.normalize("foo bar")
16         'Foo_bar'
17
18     """
19     if title is None:
20         return title
21     else:
22         if len(title) > 0:
23             return (title[0].upper() + title[1:]).replace(" ", "_")
24         else:
25             return ""

Community Data Science Collective || Want to submit a patch?