ns
Classes and methods for handling namespaces on a Wiki
NS
Bases: IntEnum
Default namespace IDs, for convenience
NSManager
Manages the pairings (id -> name) and (name -> id) of the namespaces on a Wiki. Also contains methods for performing lexical operations with namespaces
__init__(r)
Creates a new NSManager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
r |
dict
|
The response from the server. This should be the json object directly under the |
required |
batch_convert_ns(titles, ns, replace_underscores=False)
Convenience method, converts an Iterable of titles to another namespace. PRECONDITION: titles in titles
are well-formed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
titles |
Iterable[str]
|
The titles to convert |
required |
ns |
Union[str, NS]
|
The namespace to convert the titles to |
required |
replace_underscores |
bool
|
Set |
False
|
Returns:
Type | Description |
---|---|
list[str]
|
list[str]: The titles converted to namespace |
canonical_prefix(ns)
Gets the canonical prefix for the specified namespace. This adds a :
suffix to ns
, or returns the empty string if ns
is the Main namespace.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns |
Union[NS, str]
|
The namespace to get the canonical prefix for. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The canonical prefix for the specified namepsace. |
create_filter(nsl)
Convenience method, creates a pipe-fenced namespace filter for sending with queries.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
nsl |
Union[list[Union[NS, str]], NS, str]
|
The namespace or namespaces to create a filter out of |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If there is an invalid namespace in |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The pipe-fenced namespace filter for sending with queries |
intify(ns)
Convienence method, converts the specified namespace to its int
id if possible. This is a lexical operation and does not check if the id actually exists on the server.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns |
Union[int, NS, str]
|
The namespace to get the |
required |
Returns:
Name | Type | Description |
---|---|---|
int |
int
|
The int id of |
nss(title)
Strips the namespace prefix from a title.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
title |
str
|
The title to remove the namespace from. |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
|
stringify(ns)
Convienence method, returns the name of a namespace as a str
. Does not perform any namespace validation whatsoever.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ns |
Union[int, NS, str]
|
The namespace to get the name of. If this is a |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The name of |