pytoshop.util¶
Miscellaneous utilities.
-
pytoshop.util.
assert_is_list_of
(value, cls, min=None, max=None)[source]¶ If value is not a list of cls instances, raises TypeError.
-
pytoshop.util.
decode_unicode_string
(data)[source]¶ Decode Photoshop’s definition of a Unicode String.
-
pytoshop.util.
encode_unicode_string
(s)[source]¶ Encode Photoshop’s definition of a Unicode String.
-
pytoshop.util.
ensure_bigendian
(arr)[source]¶ Ensure that a Numpy array is in big-endian order.
Returns a copy if the endianness needed to be changed.
-
pytoshop.util.
ensure_native_endian
(arr)[source]¶ Ensure that a Numpy array is in native-endian order.
Returns a copy if the endianness needed to be changed.
-
pytoshop.util.
pascal_string_length
(value, padding=1)[source]¶ Calculates the total length of writing a UTF-8-encoded Pascal string to disk.
Parameters: value (str) – A unicode string value. Returns: length – The length, in bytes. Return type: int
-
pytoshop.util.
read_pascal_string
(fd, padding=1)[source]¶ Read a UTF-8-encoded Pascal string from a file.
Parameters: - fd (file-like object) – Must be opened for reading, seekable and in binary mode.
- padding (int, optional) – If provided, additional pad bytes will be read until the total amount read is a multiple of padding.
Returns: value – The unicode value of the string.
Return type:
-
pytoshop.util.
read_unicode_string
(fd)[source]¶ Read a UTF-16-BE-encoded Unicode string (with length) from a file.
Parameters: fd (file-like object) – Must be opened for reading, seekable and in binary mode. Returns: value – The unicode value of the string. Return type: str
-
pytoshop.util.
read_value
(fd, fmt, endian='>')[source]¶ Read a values from a file-like object.
Parameters: - fd (file-like object) – Must be opened for reading, in binary mode.
- fmt (str) – A
struct
module format character string. - endian (str) – The endianness. Must be
>
or<
. Default:>
.
Returns: value – The value(s) read from the file.
If a single value, it is returned alone. If multiple values, a tuple is returned.
Return type: any
-
pytoshop.util.
trace_read
(func)[source]¶ Prints debugging information from a read or write method.
For internal use only.
-
pytoshop.util.
trace_write
(func)¶ Prints debugging information from a read or write method.
For internal use only.
-
pytoshop.util.
unicode_string_length
(value)[source]¶ Calculates the total length of writing a UTF-16-BE-encoded Unicode string (with length) to a file.
Parameters: value (str) – A unicode string value. Returns: length – The length, in bytes. Return type: int
-
pytoshop.util.
write_pascal_string
(fd, value, padding=1)[source]¶ Write a UTF-8-encoded Pascal string to a file.
Parameters:
-
pytoshop.util.
write_unicode_string
(fd, value)[source]¶ Write a UTF-16-BE-encoded Unicode string (with length) to a file.
Parameters: - fd (file-like object) – Must be opened for writing and in binary mode.
- value (str) – A unicode string value.
-
pytoshop.util.
write_value
(fd, fmt, *value, **kwargs)[source]¶ Write a single binary value to a file-like object.
Parameters: - fd (file-like object) – Must be opened for writing, in binary mode.
- fmt (str) – A
struct
module format character string. - value (any) – The value to encode and write to the file.
- endian (str) – The endianness. Must be
>
or<
. Default:>
.