Smartposter Record¶
The NFC Forum Smart Poster Record Type Definition defines a structure that associates an Internationalized Resource Identifier (or Uniform Resource Identifier) with various types of metadata. For a user this is most noteably the ability to attach descriptive text in different languages as well as image data for icon rendering. For a smartposter application this is a recommendation for processing as well as resource type and size hints to guide a strategy for retrieving the resource.
-
class
SmartposterRecord(resource, title=None, action=None, icon=None, resource_size=None, resource_type=None)¶ Initialize a
SmartposterRecordinstance. The only required argument is the Internationalized Resource Identifier resource, all other arguments are optional metadata.Parameters: - resource (str) – Internationalized Resource Identifier
- title (str or dict) – English title
strordictwith language keys and title values - action (str or int) – assigns a value to the
actionattribute - icon (bytes or dict) – PNG data
bytesordictwith {icon-type: icon_data} items - resource_size (int) – assigns a value to the
resource_sizeattribute - resource_type (str) – assigns a value to the
resource_typeattribute
-
type¶ The Smartposter Record type is
urn:nfc:wkt:Sp.
-
resource¶ Get or set the Smartposter resource identifier. A set value is interpreted as an internationalized resource identifier (so it can be unicode). When reading, the resource attribute returns a
UriRecordwhich can be used to set theUriRecord.iriandUriRecord.uridirectly.
-
title¶ The title string for language code ‘en’ or the first title string that was decoded or set. If no title string is available the value is
None. The attribute can not be set, useset_title().
-
titles¶ A dictionary of all decoded or set titles with language
strkeys and titlestrvalues. The attribute can not be set, useset_title().
-
set_title(title, language='en', encoding='UTF-8')¶ Set the title string for a specific language which defaults to ‘en’. The transfer encoding may be set to either ‘UTF-8’ or ‘UTF-16’, the default is ‘UTF-8’.
-
action¶ Get or set the recommended action for handling the Smartposter resource. A set value may be ‘exec’, ‘save’, ‘edit’ or an index thereof. A read value is either one of above strings or
Noneif no action value was decoded or set.
-
icon¶ The image data
bytesfor an ‘image/png’ type smartposter icon or the first icon decoded or added. If no icon is available the value isNone. The attribute can not be set, useadd_icon().
-
icons¶ A dictionary of icon images with mime-type
strkeys and icon-databytesvalues. The attribute can not be set, useadd_icon().
-
add_icon(icon_type, icon_data)¶ Add a Smartposter icon as icon_data bytes for the image or video mime-type string supplied with icon_type.
-
resource_size¶ Get or set the
intsize hint for the Smartposter resource.Noneif a size hint was not decoded or set.
-
resource_type¶ Get or set the
strtype hint for the Smartposter resource.Noneif a type hint was not decoded or set.
>>> import ndef >>> record = ndef.SmartposterRecord('https://github.com/nfcpy/ndeflib') >>> record.set_title('Python package for parsing and generating NDEF', 'en') >>> record.resource_type = 'text/html' >>> record.resource_size = 1193970 >>> record.action = 'exec' >>> len(b''.join(ndef.message_encoder([record]))) 115