Note
For basic information how to use the classes defined in this module – please consult the Data specification class chapter of the tutorial, in particular the Standard n6sdk field classes and Custom field classes sections.
Bases: object
The base class for all data field specification classes.
It has two (overridable/extendable) methods: clean_param_value() and clean_result_value() (see below).
Note that fields can be customized in two ways:
Constructors of all field classes accept the following keyword-only arguments:
If false: multiple query parameter values are allowed.
A dictionary containing arbitrary data (accessible as the custom_info instance attribute).
any keyword arguments whose names are the names of class-level attributes (see the second point in the paragraph above).
The method called by data specification‘s parameter cleaning methods.
The default implementation just passes the value unchanged. This method can be extended (using super()) in subclasses.
Note
Although any subclass of Exception can be used to signalize a cleaning/validation error, if you want to specify a public message, use n6sdk.exceptions.FieldValueError with the public_message constructor keyword argument specified.
The method called by data specification‘s result cleaning methods.
The default implementation just passes the value unchanged. This method can be extended (using super()) in subclasses.
Bases: n6sdk.data_spec.fields.Field
For date-and-time (timestamp) values, automatically normalized to UTC.
The input value should be a str/unicode string, ISO-8601-formatted.
Returns: a datetime.datetime object (a naive one, i.e. not aware of any timezone).
The input value should be a str/unicode string (ISO-8601-formatted) or a datetime.datetime object (timezone-aware or naive).
Returns: a datetime.datetime object (a naive one, i.e. not aware of any timezone).
Bases: n6sdk.data_spec.fields.Field
For arbitrary text data.
Bases: n6sdk.data_spec.fields.UnicodeField
For hexadecimal digests (hashes), such as MD5, SHA256 or any other.
The constructor-arguments-or-subclass-attributes: num_of_characters (the exact number of characters each hex digest consist of) and hash_algo_descr (the digest algorithm label, such as "MD5" or "SHA256") are obligatory.
Bases: n6sdk.data_spec.fields.HexDigestField
For hexadecimal MD5 digests (hashes).
Bases: n6sdk.data_spec.fields.HexDigestField
For hexadecimal SHA1 digests (hashes).
Bases: n6sdk.data_spec.fields.UnicodeField
For text data limited to a finite set of possible values.
The constructor-argument-or-subclass-attribute enum_values (a sequence or set of strings) is obligatory.
Bases: n6sdk.data_spec.fields.UnicodeField
For text data with limited length.
The constructor-argument-or-subclass-attribute max_length (an integer number greater or equal to 1) is obligatory.
Experimental attribute (can be removed in future versions, so do not rely on it, please).
Bases: n6sdk.data_spec.fields.UnicodeField
For text data limited by the specified regular expression.
The constructor-argument-or-subclass-attribute regex (a regular expression specified as a string or a compiled regular expression object) is obligatory.
Bases: n6sdk.data_spec.fields.UnicodeLimitedField, n6sdk.data_spec.fields.UnicodeRegexField
For dot-separated source specifications, such as my-org.type.
Bases: n6sdk.data_spec.fields.UnicodeLimitedField, n6sdk.data_spec.fields.UnicodeRegexField
For IPv4 addresses, such as 127.234.5.17.
(Using decimal dotted-quad notation.)
Bases: n6sdk.data_spec.fields.UnicodeLimitedField, n6sdk.data_spec.fields.UnicodeRegexField
For anonymized IPv4 addresses, such as x.x.5.17.
(Using decimal dotted-quad notation, with the leftmost octet – and possibly any other octets – replaced with “x”.)
Bases: n6sdk.data_spec.fields.UnicodeLimitedField, n6sdk.data_spec.fields.UnicodeRegexField
For IPv4 network specifications (CIDR), such as 127.234.5.0/24.
Bases: n6sdk.data_spec.fields.UnicodeLimitedField, n6sdk.data_spec.fields.UnicodeRegexField
For 2-letter country codes, such as FR or UA.
Bases: n6sdk.data_spec.fields.UnicodeLimitedField
For substrings of URLs (such as xample.com/path?que).
Bases: n6sdk.data_spec.fields.URLSubstringField
For URLs (such as http://xyz.example.com/path?query=foo#fr).
Bases: n6sdk.data_spec.fields.UnicodeLimitedField
For substrings of domain names, automatically IDNA-encoded and lower-cased.
Bases: n6sdk.data_spec.fields.DomainNameSubstringField, n6sdk.data_spec.fields.UnicodeRegexField
For domain names, automatically IDNA-encoded and lower-cased.
Bases: n6sdk.data_spec.fields.Field
For integer numbers (optionally with min./max. limits defined).
Bases: n6sdk.data_spec.fields.IntegerField
For AS numbers, such as 12345, 123456789 or 12345.65432.
Bases: n6sdk.data_spec.fields.IntegerField
For TCP/UDP port numbers, such as 12345.
Bases: n6sdk.data_spec.fields.Field
A mix-in class for fields whose result values are supposed to be a sequence of values and not single values.
Its clean_result_value() checks that its argument is a non-string sequence (list or tuple, or any other collections.Sequence not being str or unicode) and performs result cleaning (as defined in a superclass) for each item of it.
See: AddressField below.
Bases: n6sdk.data_spec.fields.Field
A base class for fields whose result values are supposed to be dictionaries (whose fixed structure is defined by key_to_subfield_factory and required_keys).
The constructor-argument-or-subclass-attribute key_to_subfield_factory (a dictionary that maps subfield names to subfield factories or classes) is obligatory.
Always raises NotImplementedError.
Bases: n6sdk.data_spec.fields.ResultListFieldMixin, n6sdk.data_spec.fields.DictResultField
For lists of dictionaries containing ip and optionally cc and/or asn.