Normalizes a page title to the database format. E.g. spaces are converted to underscores and the first character in the title is converted to upper-case.
Parameters: |
|
---|---|
Returns: | The normalized title. |
Example: | >>> from mw.lib import title
>>>
>>> title.normalize("foo bar")
'Foo_bar'
|
Constructs a page name parser from a set of mw.Namespace. Such a parser can be used to convert a full page name (namespace included with a colon; e.g, "Talk:Foo") into a namespace ID and mw.lib.title.normalize()‘d page title (e.g., (1, "Foo")).
Parameters: | namespaces : set( mw.Namespace ) |
---|---|
Example: | >>> from mw import Namespace
>>> from mw.lib import title
>>>
>>> parser = title.Parser(
... [
... Namespace(0, "", case="first-letter"),
... Namespace(1, "Discussão", canonical="Talk", case="first-letter"),
... Namespace(2, "Usuário(a)", canonical="User", aliases={"U"}, case="first-letter")
... ]
... )
>>>
>>> parser.parse("Discussão:Foo") # Using the standard name
(1, 'Foo')
>>> parser.parse("Talk:Foo bar") # Using the cannonical name
(1, 'Foo_bar')
>>> parser.parse("U:Foo bar") # Using an alias
(2, 'Foo_bar')
>>> parser.parse("Herpderp:Foo bar") # Psuedo namespace
(0, 'Herpderp:Foo_bar')
|
Parses a page name to extract the namespace.
Parameters: |
|
---|---|
Returns: | A tuple of (namespace : int, title : str) |
Adds a namespace to the parser.
Parameters: |
|
---|
Gets a namespace from the parser. Throws a KeyError if a namespace cannot be found.
Parameters: |
|
---|---|
Returns: | A mw.Namespace. |
Constructs a parser from the result of a mw.api.SiteInfo.query().
Parameters: |
|
---|---|
Returns: | An initialized mw.lib.title.Parser |
Constructs a parser from a mw.api.Session
Parameters: |
|
---|---|
Returns: | An initialized mw.lib.title.Parser |
Constructs a parser from a mw.xml_dump.Iterator. Note that XML database dumps do not include namespace aliases or cannonical names so the parser that will be constructed will only work in common cases.
Parameters: |
|
---|---|
Returns: | An initialized mw.lib.title.Parser |