Module: nintendo.nex.common

Provides classes that are used by various nex modules.

class RMCError(Exception)
Raised when the server returns an error code.

class Result
Holds the result of a remote method call.

class Structure
Base class for nex structures. This class should not be subclassed manually. Instead, structures should be defined in a protocol file.

class Data(Structure)
Base class for structures that can be held by a data holder. This class should not be subclassed manually. Instead, data structures should be defined in a protocol file.

class NullData(Data)
The NullData structure. This class does not define any fields.

class StationURL
A station url (nn::nex::StationURL).

class DateTime
A date time object (nn::nex::DateTime).

class ResultRange(Structure)
A result range (nn::nex::ResultRange). This structure limits database queries to a specific range.

RMCError

def __init__(code: str = "Core::Unknown)
Creates a new RMCError from the given error description.

def __init__(code: int = 0x10001)
Creates a new RMCError from the given error code.

def code() -> int
Returns the error code.

def name() -> str
Returns a description of the error. If the error code is unknown, this method returns "unknown error".

def result() -> Result
Returns a result object that represents the error.

Result

@classmethod
def success(code: str = "Core::Unknown") -> Result
Creates a new Result object that indicates success.

@classmethod
def success(code: int = 0x10001) -> Result
Creates a new Result object that indicates success.

@classmethod
def error(code: str = "Core::Unknown") -> Result
Creates a new Result object that indicates an error.

@classmethod
def error(code: int = 0x10001) -> Result
Creates a new Result object that indicates an error.

def is_success() -> bool
Returns True if the result indicates success.

def is_error() -> bool
Returns True if the result indicates an error.

def code() -> int
Returns the error code of the result. Errors are indicated by bit 1 << 31.

def name() -> str
Returns a description of the result. If the result indicates success, this method always returns "success", regardless of the error code. If the error bit is set but the error code is unknown, this method returns "unknown error".

def raise_if_error() -> None
Raises an RMCError if the error bit is set.

StationURL

A station url consists of an url scheme and a bunch of parameters. The following parameters are currently valid:
address, Rsa, port, stream, sid, PID, CID, type, RVCID, natm, natf, upnp, pmp, probeinit, PRID and Rsp.

def __init__(scheme: str = "prudp", **kwargs)
Creates a new station url with the given url scheme. Additional parameters may be provided in kwargs.

def __repr__() -> str
Returns the string representation of the station url.

def __getitem__(name: str) -> object
Returns a specific parameter, either as str or int. Returns a default value if the parameter name is valid but not defined in the station url. Raises KeyError if the parameter name is invalid.

def __setitem__(name: str, value: object) -> None
Changes a specific parameter. The given value is automatically converted to string.

def scheme() -> str
Returns the url scheme.

def address() -> tuple[str, int]
Returns the address of the station url as a tuple: (address, port).

def is_public() -> bool
Returns True if the type field indicates that the station address is public.

def is_behind_nat() -> bool
Returns True if the type field indicates that the station is behind a nat device.

def is_global() -> bool
Returns True if the type field indicates that the station address is global (i.e. public and not behind a nat device).

def copy() -> StationURL
Returns a copy of the station url.

@classmethod
def parse(string: str) -> StationURL
Parses the given station url string. If string is empty, the station url is created with the "prudp" scheme and without parameters.

DateTime

A DateTime object always represents UTC time.

def __init__(value: int)
Creates a new DateTime object from the given value.

def value() -> int
Returns value of the DateTime object, as encoded by nex.

def second() -> int
Returns the seconds (0 - 59)
def minute() -> int
Returns the minutes (0 - 59)
def hour() -> int
Returns the hours (0 - 23)
def day() -> int
Returns the day of the month (1 - 31).
def month() -> int
Returns the month (1 - 12)
def year() -> int
Returns the year.

def standard_datetime() -> datetime.datetime
Converts the DateTime object to a standard datetime.datetime object.

def timestamp() -> int
Returns a posix timestamp.

@classmethod
def make(year: int, month: int = 1, day: int = 1, hour: int = 0, minute: int = 0, second: int = 0) -> DateTime
Creates a new DateTime object for the given date.

@classmethod
def fromtimestamp(timestamp: int) -> DateTime
Creates a new DateTime object from the given posix timestamp.

@classmethod
def now() -> DateTime
Creates a new DateTime object for the current time.

@classmethod
def never() -> DateTime
Creates a special DateTime object that represents 'never'.

@classmethod
def future() -> DateTime
Creates a special DateTime object that represents 'future'.

ResultRange

offset: int
size: int

def __init__(offset: int = 0, size: int = 10)
Creates a new result range.