This module defines the Blob class which holds an immutable byte array. We use an immutable buffer so that it is OK to pass the object into methods because the new or old owner can’t change the bytes. Note that the pointer to the buffer can be None.
Bases: object
Create a new Blob which holds an immutable array of bytes.
Parameters: |
|
---|
Return the byte array which you must treat as immutable and not modify the contents. Note: For compatibility with Python versions before 3.3, if you need an object which implements the buffer protocol (e.g. for writing to a socket) then call toBuffer() instead.
Returns: | An array which you should not modify, or None if isNull(). |
---|---|
Return type: | An array type with int elements, such as bytearray. |
Compare this to the other Blob using byte-by-byte comparison. If this and other are both isNull(), then this returns 0. If this isNull() and the other is not, return -1. If this is not isNull() and the other is, return 1. We compare explicitly because a Blob uses a memoryview which doesn’t have built-in comparison operators.
Parameters: | other (Blob) – The other Blob to compare with. |
---|---|
Returns: | 0 If they compare equal, -1 if self is less than other, or 1 if self is greater than other. If both are equal up to the shortest, then return -1 if self is shorter than other, or 1 of self is longer than other. |
Return type: | int |
Check if this is byte-wise equal to the other Blob. If this and other are both isNull(), then this returns True. We compare explicitly because a Blob uses a memoryview which doesn’t have built-in comparison operators.
Parameters: | other (Blob) – The other Blob to compare with. |
---|---|
Returns: | True if the blobs are equal, otherwise False. |
Return type: | bool |
Convert rawStr to a Blob. This does not do any character decoding such as UTF-8. If you want decode the string such as UTF-8, then just pass the string to the Blob constructor.
Parameters: | rawStr (str) – The raw string to convert to a Blob. |
---|---|
Returns: | A new Blob created from rawStr. |
Return type: | Blob |
Return True if the array is None, otherwise False.
Returns: | True if the array is None. |
---|---|
Return type: | bool |
Return the length of the immutable byte array.
Returns: | The length of the array. |
---|---|
Return type: | int |
Return an array which implements the buffer protocol (but for Python versions before 3.3 it doesn’t have int elements). This method is only needed by Python versions before 3.3 to check if buf() would return a _memoryviewWrapper and to return its internal memoryview instead. However, if this is a Python version (3.3 or greater) whose memoryview already uses int, then toBuffer() is the same as buf().
Returns: | The array which implements the buffer protocol, or None if isNull(). |
---|---|
Return type: | an array which implements the buffer protocol |
Return an object which is the same as the bytes() operator. In Python 2, this simply calls self.toRawStr() because bytes is the same as str. In Python 3, this converts the byte array to a bytes type. This method is necessary because the bytes type is different in Python 2 and 3. This does not do any character encoding such as UTF-8.
Returns: | The array as a bytes type, or None if isNull(). |
---|---|
Return type: | bytes (str in Python 2) |
Bases: object
Add the contents of the file or input string to the root BoostInfoTree. There are two forms: read(fileName) reads fileName from the file system. read(input, inputName) reads from the input, in which case inputName is used only for log messages, etc.
Parameters: |
|
---|
Bases: object
Insert a BoostInfoTree as a sub-tree with the given name. :param str treeName: The name of the new sub-tree. :param BoostInfoTree newTree: The sub-tree to add.
Similar to shlex.split, split s into an array of strings which are separated by whitespace, treating a string within quotes as a single entity regardless of whitespace between the quotes. Also allow a backslash to escape the next character.
Parameters: | s (str) – The input string to split. |
---|---|
Returns: | An array of strings. |
Return type: | list of str |
This module defines the ChangeCounter class which keeps a target object whose change count is tracked by a local change count. You can set to a new target which updates the local change count, and you can call checkChanged to check if the target (or one of the target’s targets) has been changed. The target object must have a method getChangeCount.
Bases: object
Create a new ChangeCounter to track the given target. If target is not None, this sets the local change counter to target.getChangeCount().
Parameters: | target (An type with method getChangeCount()) – The target to track. |
---|
If the target’s change count is different than the local change count, then update the local change count and return True. Otherwise return False, meaning that the target has not changed. Also, if the target is None, simply return false. This is useful since the target (or one of the target’s targets) may be changed and you need to find out.
Returns: | True if the change count has been updated, false if not. |
---|---|
Return type: | bool |
This module defines the CommandInterestGenerator class which keeps track of a timestamp and generates command interests according to the NFD Signed Command Interests protocol: http://redmine.named-data.net/projects/nfd/wiki/Command_Interests
Bases: object
Create a new CommandInterestGenerator and initialize the timestamp to now.
Append a timestamp component and a random value component to interest’s name. This ensures that the timestamp is greater than the timestamp used in the previous call. Then use keyChain to sign the interest which appends a SignatureInfo component and a component with the signature bits. If the interest lifetime is not set, this sets it.
Parameters: |
|
---|
This module defines the Common class which has static utility functions.
Bases: object
Return bytesIO.getvalue(), making sure the result is a str. This is necessary because getvalue() returns a bytes object in Python 3.
Get the current time in milliseconds.
Returns: | The current time in milliseconds since 1/1/1970, including fractions of a millisecond. |
---|---|
Return type: | float |
If the input has type str (in Python 3) or unicode (in Python 2), then encode it as UTF8 and return an array of integers. If the input is str (in Python 2) then treat it as a “raw” string and just convert each element to int. Otherwise, if the input is not str or unicode, just return the input. This is necessary because in Python 3 doesn’t have the unicode type and the elements in a string a Unicode characters. But in Python 2 only the unicode type has Unicode characters, and str elements are bytes with value 0 to 255 (and often used to carry binary data).
Check if obj has type str or (in Python 2) unicode. This is necessary because Python 2 has two string types, str and unicode, but Python 3 doesn’t have type unicode so we have to be carefor to check for type(obj) is unicode.
Parameters: | obj (any) – The object to check if it is str or unicode. |
---|---|
Returns: | True if obj is str or unicode, otherwise false |
Return type: | bool |
This module defines the DynamicByteArray class which holds a bytearray which can be expanded as needed.
Bases: object
Create a new DynamicByteArray with an initial bytearray.
Parameters: | length (int) – (optional) The initial length of the bytearray. If omitted, use a default value. |
---|
First call ensureLength to make sure the bytearray has offset + len(value) bytes, then copy value into the bytearray starting at offset.
Parameters: |
|
---|
First call ensureLengthFromBack to make sure the bytearray has offsetFromBack bytes, then copy value into the bytearray starting offsetFromBack bytes from the back of the array.
Parameters: |
|
---|
Ensure length. If necessary, reallocate the bytearray and copy existing data to the front of the new array.
Parameters: | length (int) – The minimum length for the bytearray. |
---|
This module defines the MemoryContentCache class which holds a set of Data packets and answers an Interest to return the correct Data packet. The cache is periodically cleaned up to remove each stale Data packet based on its FreshnessPeriod (if it has one). Note: This class is an experimental feature. See the API docs for more detail at http://named-data.net/doc/ndn-ccl-api/memory-content-cache.html .
Bases: object
Create a new MemoryContentCache to use the given Face.
Parameters: |
|
---|
Add the Data packet to the cache so that it is available to use to answer interests. If data.getMetaInfo().getFreshnessPeriod() is not None, set the staleness time to now plus data.getMetaInfo().getFreshnessPeriod(), which is checked during cleanup to remove stale content. This also checks if cleanupIntervalMilliseconds milliseconds have passed and removes stale content from the cache. After removing stale content, remove timed-out pending interests from storePendingInterest(), then if the added Data packet satisfies any interest, send it through the face and remove the interest from the pending interest table.
Parameters: | data (Data) – The Data packet object to put in the cache. This copies the fields from the object. |
---|
Return a callback to use for onDataNotFound in registerPrefix which simply calls storePendingInterest() to store the interest that doesn’t match a Data packet. add(data) will check if the added Data packet satisfies any pending interest and send it.
Returns: | A callback to use for onDataNotFound in registerPrefix(). |
---|---|
Return type: | function object |
Call registerPrefix on the Face given to the constructor so that this MemoryContentCache will answer interests whose name has the prefix.
Parameters: |
|
---|
Store an interest from an OnInterest callback in the internal pending interest table (normally because there is no Data packet available yet to satisfy the interest). add(data) will check if the added Data packet satisfies any pending interest and send it through the face.
Parameters: |
|
---|
Call Face.removeRegisteredPrefix for all the prefixes given to the registerPrefix method on this MemoryContentCache object so that it will not receive interests any more. You can call this if you want to “shut down” this MemoryContentCache while your application is still running.
This module defines the SegmentFetcher class which is a utility class to fetch the latest version of segmented data.
SegmentFetcher assumes that the data is named /<prefix>/<version>/<segment>, where:
The following logic is implemented in SegmentFetcher:
Express the first Interest to discover the version:
>> Interest: /<prefix>?ChildSelector=1&MustBeFresh=true
Infer the latest version of the Data: <version> = Data.getName().get(-2)
If the segment number in the retrieved packet == 0, go to step 5.
Send an Interest for segment 0:
>> Interest: /<prefix>/<version>/<segment=0>
Keep sending Interests for the next segment while the retrieved Data does not have a FinalBlockId or the FinalBlockId != Data.getName().get(-1).
>> Interest: /<prefix>/<version>/<segment=(N+1))>
Call the onComplete callback with a Blob that concatenates the content from all the segmented objects.
If an error occurs during the fetching process, the onError callback is called with a proper error code. The following errors are possible:
In order to validate individual segments, a verifySegment callback needs to be specified. If the callback returns False, the fetching process is aborted with SEGMENT_VERIFICATION_FAILED. If data validation is not required, the provided DontVerifySegment object can be used.
interest = Interest(Name(“/data/prefix”)) interest.setInterestLifetimeMilliseconds(1000)
Bases: object
A private constructor to create a new SegmentFetcher to use the Face. An application should use SegmentFetcher.fetch.
Parameters: |
|
---|
DontVerifySegment may be used in fetch to skip validation of Data packets.
Bases: object
An ErrorCode value is passed in the onError callback.
Initiate segment fetching. For more details, see the documentation for the module.
Parameters: |
|
---|
This module defines the SignedBlob class which extends Blob to keep the offsets of a signed portion (e.g., the bytes of Data packet).
Bases: pyndn.util.blob.Blob
Create a new SignedBlob using the given Blob and offsets.
Parameters: |
|
---|
Return the signed portion of the byte array which you must treat as immutable and not modify the contents.
Returns: | An array which you should not modify, or None if isNull(). |
---|---|
Return type: | An array type with int elements, such as bytearray. |
Get the length of the signed portion of the immutable byte buffer.
Returns: | The length of the signed portion, or 0 if isNull(). |
---|---|
Return type: | int |
Return an array of the signed portion which implements the buffer protocol (but for Python versions before 3.3 it doesn’t have int elements). This method is only needed by Python versions before 3.3 to check if signedBuf() would return a _memoryviewWrapper and to return its internal memoryview instead. However, if this is a Python version (3.3 or greater) whose memoryview already uses int, then toSignedBuffer() is the same as signedBuf().