示例#1
0
文件: core.py 项目: vicgc/Uforia
    def serialize_to_str(self, padding=0, **kwargs):
        """
		Serializes an XMPMeta object into a string (8-bit, UTF-8 encoded) as RDF and format.

		:param padding: The number of bytes of padding, useful for modifying embedded XMP in place.
		:param omit_packet_wrapper: Do not include an XML packet wrapper.
		:param read_only_packet: Create a read-only XML packet wapper.
		:param use_compact_format: Use a highly compact RDF syntax and layout.
		:param include_thumbnail_pad: Include typical space for a JPEG thumbnail in the padding if no xmp:Thumbnails property is present.
		:param exact_packet_length: The padding parameter provides the overall packet length.
		:param write_alias_comments: Include XML comments for aliases.
		:param omit_all_formatting: Omit all formatting whitespace.
		:return: XMPMeta object serialized into a string as RDF.
		:rtype: `str` 8-bit string in UTF-8 encoding (ready to e.g. be writtin to a file).
		"""
        res_str = None

        # Ensure padding is an int.
        padding = int(padding)

        # Define options bitmask
        options = options_mask(XMP_SERIAL_OPTIONS, **kwargs)

        # Serialize
        xmpstring = _XMPString()
        res = _exempi.xmp_serialize(self.xmpptr, xmpstring.ptr, options,
                                    padding)
        _check_for_error()

        # Get string
        if res:
            res_str = xmpstring.__str__()

        del xmpstring
        return res_str
示例#2
0
文件: core.py 项目: vicgc/Uforia
    def parse_from_str(self,
                       xmp_packet_str,
                       xmpmeta_wrap=False,
                       input_encoding=None):
        """
		Parses RDF from a string into a XMP object. The input for parsing may be any valid
		Unicode encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged.

		Note RDF string must contain an outermost <x:xmpmeta> object.

		:param xmp_packet_str: String to parse.
		:param xmpmeta_wrap: Optional - If True, the string will be wrapped in an <x:xmpmeta> element.
		:param input_encoding: Optional - If `xmp_packet_str` is a 8-bit string, it will by default be assumed to be UTF-8 encoded.
		:return:  true if :class:`libxmp.core.XMPMeta` object can be written in file.
		:rtype: bool
		"""
        xmp_packet_str = _encode_as_utf8(xmp_packet_str, input_encoding)

        if xmpmeta_wrap:
            xmp_packet_str = "<x:xmpmeta xmlns:x='adobe:ns:meta/'>%s</x:xmpmeta>" % xmp_packet_str

        l = len(xmp_packet_str)
        res = _exempi.xmp_parse(self.xmpptr, xmp_packet_str, l)
        _check_for_error()
        return res
示例#3
0
文件: files.py 项目: JJWTimmer/Uforia
	def open_file(self, file_path, **kwargs):
		"""
		Open a given file and read XMP from file. File must be closed again with
		:func:`close_file`

		:param file_path: Path to file to open.
		:raises XMPError: in case of errors.

		.. todo::
			Change signature into using kwargs to set option flag
		"""
		open_flags = options_mask(XMP_OPEN_OPTIONS, **kwargs) if kwargs else XMP_OPEN_NOOPTION

		if self._file_path != None:
			raise XMPError('A file is already open - close it first.')

		# Ensure file path is UTF-8 encoded (expected by Exempi)
		file_path = _encode_as_utf8(file_path)

		if not os.path.exists(file_path):
			raise XMPError('File does not exists.')

		if _exempi.xmp_files_open(self.xmpfileptr, file_path, open_flags):
			self._file_path = file_path
		else:
			_check_for_error()
示例#4
0
    def open_file(self, file_path, **kwargs):
        """
		Open a given file and read XMP from file. File must be closed again with
		:func:`close_file`
		
		:param file_path: Path to file to open.
		:raises XMPError: in case of errors.
		
		.. todo:: 
			Change signature into using kwargs to set option flag
		"""
        open_flags = options_mask(XMP_OPEN_OPTIONS, **
                                  kwargs) if kwargs else XMP_OPEN_NOOPTION

        if self._file_path != None:
            raise XMPError('A file is already open - close it first.')

        # Ensure file path is UTF-8 encoded (expected by Exempi)
        file_path = _encode_as_utf8(file_path)

        if not os.path.exists(file_path):
            raise XMPError('File does not exists.')

        if _exempi.xmp_files_open(self.xmpfileptr, file_path, open_flags):
            self._file_path = file_path
        else:
            _check_for_error()
示例#5
0
	def serialize_to_str( self, padding = 0, **kwargs ):
		"""
		Serializes an XMPMeta object into a string (8-bit, UTF-8 encoded) as RDF and format. 
		
		:param padding: The number of bytes of padding, useful for modifying embedded XMP in place.
		:param omit_packet_wrapper: Do not include an XML packet wrapper.
		:param read_only_packet: Create a read-only XML packet wapper.
		:param use_compact_format: Use a highly compact RDF syntax and layout.
		:param include_thumbnail_pad: Include typical space for a JPEG thumbnail in the padding if no xmp:Thumbnails property is present.
		:param exact_packet_length: The padding parameter provides the overall packet length.
		:param write_alias_comments: Include XML comments for aliases.
		:param omit_all_formatting: Omit all formatting whitespace.
		:return: XMPMeta object serialized into a string as RDF.
		:rtype: `str` 8-bit string in UTF-8 encoding (ready to e.g. be writtin to a file).
		"""
		res_str = None
		
		# Ensure padding is an int.
		padding = int(padding)		

		# Define options bitmask
		options = options_mask( XMP_SERIAL_OPTIONS, **kwargs )
		
		# Serialize
		xmpstring = _XMPString()
		res = _exempi.xmp_serialize( self.xmpptr, xmpstring.ptr, options, padding )
		_check_for_error()
		
		# Get string
		if res:
			res_str = xmpstring.__str__()
			
		del xmpstring
		return res_str
示例#6
0
文件: core.py 项目: vicgc/Uforia
 def __init__(self, xmp_obj, schema_ns=None, prop_name=None, **kwargs):
     self.options = options_mask(consts.XMP_ITERATOR_OPTIONS, **
                                 kwargs) if kwargs else 0
     self.xmpiteratorptr = _exempi.xmp_iterator_new(xmp_obj.xmpptr,
                                                    schema_ns, prop_name,
                                                    self.options)
     _check_for_error()
     self.schema = schema_ns
     self.prop_name = prop_name
示例#7
0
文件: core.py 项目: vicgc/Uforia
    def __del__(self):
        """
		Ensures memory is deallocated when destroying object.
		"""
        if self.xmpptr != None:
            if not _exempi.xmp_free(self.xmpptr):
                _check_for_error()

        if self.iterator is not None:
            del self.iterator
示例#8
0
	def __del__(self):
		"""
		Ensures memory is deallocated when destroying object.
		"""
		if self.xmpptr != None:
			if not _exempi.xmp_free(self.xmpptr):
				_check_for_error()
		
		if self.iterator is not None:
			del self.iterator
示例#9
0
文件: files.py 项目: JJWTimmer/Uforia
	def put_xmp(self, xmp_obj):
		"""
		Write XMPMeta object to file. See also :func:`can_put_xmp`.

		:param xmp_obj: An :class:`libxmp.core.XMPMeta` object
		"""
		xmpptr = xmp_obj.xmpptr

		if xmpptr != None:
			if not _exempi.xmp_files_put_xmp(self.xmpfileptr, xmpptr):
				_check_for_error()
示例#10
0
    def put_xmp(self, xmp_obj):
        """
		Write XMPMeta object to file. See also :func:`can_put_xmp`.
		
		:param xmp_obj: An :class:`libxmp.core.XMPMeta` object
		"""
        xmpptr = xmp_obj.xmpptr

        if xmpptr != None:
            if not _exempi.xmp_files_put_xmp(self.xmpfileptr, xmpptr):
                _check_for_error()
示例#11
0
	def skip(**kwargs ):
		"""
		skip() skips some portion of the remaining iterations.
		
		:param **kwargs: Optional keyword parameters from XMP_SKIP_OPTIONS to control the iteration
		:returns: None
		:rtype: NoneType
		"""
		options = options_mask(consts.XMP_SKIP_OPTIONS, **kwargs) if kwargs else 0
		_exempi.xmp_iterator_skip( self.xmpiteratorptr, options );
		_check_for_error()
		return None
示例#12
0
文件: core.py 项目: vicgc/Uforia
    def skip(**kwargs):
        """
		skip() skips some portion of the remaining iterations.

		:param **kwargs: Optional keyword parameters from XMP_SKIP_OPTIONS to control the iteration
		:returns: None
		:rtype: NoneType
		"""
        options = options_mask(consts.XMP_SKIP_OPTIONS, **
                               kwargs) if kwargs else 0
        _exempi.xmp_iterator_skip(self.xmpiteratorptr, options)
        _check_for_error()
        return None
示例#13
0
文件: core.py 项目: vicgc/Uforia
    def serialize_and_format(self,
                             padding=0,
                             newlinechr='\n',
                             tabchr='\t',
                             indent=0,
                             **kwargs):
        """
		Serializes an XMPMeta object into a string as RDF. Note, normally it is sufficient to use either
		`serialize_to_str` or `serialize_to_unicode` unless you need high degree of control over the serialization.

		The specified parameters must be logically consistent, an exception is raised if not. You cannot specify
		both `omit_packet_wrapper` along with `read_only_packet`, `include_thumbnail_pad`, or `exact_packet_length`.

		:param padding: The number of bytes of padding, useful for modifying embedded XMP in place.
		:param newlinechr: The new line character to use.
		:param tabchr: The indentation character to use.
		:param indent: The initial indentation level.
		:param omit_packet_wrapper: Do not include an XML packet wrapper.
		:param read_only_packet: Create a read-only XML packet wapper.
		:param use_compact_format: Use a highly compact RDF syntax and layout.
		:param include_thumbnail_pad: Include typical space for a JPEG thumbnail in the padding if no xmp:Thumbnails property is present.
		:param exact_packet_length: The padding parameter provides the overall packet length.
		:param write_alias_comments: Include XML comments for aliases.
		:param omit_all_formatting: Omit all formatting whitespace.
		:return: XMPMeta object serialized into a string as RDF.
		:rtype: `unicode` string.
		"""
        res_str = None

        # Ensure padding is an int.
        padding = int(padding)
        indent = int(indent)
        tabchr = str(tabchr)
        newlinechr = str(newlinechr)

        # Define options bitmask
        options = options_mask(XMP_SERIAL_OPTIONS, **kwargs)

        # Serialize
        xmpstring = _XMPString()
        res = _exempi.xmp_serialize_and_format(self.xmpptr, xmpstring.ptr,
                                               options, padding, newlinechr,
                                               tabchr, indent)
        _check_for_error()

        # Get string
        if res:
            res_str = xmpstring.__str__()

        del xmpstring
        return res_str
示例#14
0
文件: files.py 项目: JJWTimmer/Uforia
	def get_xmp(self):
		"""
		Get XMP from file.

		:return: A new :class:`libxmp.core.XMPMeta` instance.
		:raises XMPError: in case of errors.
		"""
		xmpptr = _exempi.xmp_files_get_new_xmp(self.xmpfileptr)
		_check_for_error()

		if xmpptr:
			return XMPMeta(_xmp_internal_ref=xmpptr)
		else:
			return None
示例#15
0
    def get_xmp(self):
        """ 
		Get XMP from file.
		
		:return: A new :class:`libxmp.core.XMPMeta` instance.
		:raises XMPError: in case of errors.
		"""
        xmpptr = _exempi.xmp_files_get_new_xmp(self.xmpfileptr)
        _check_for_error()

        if xmpptr:
            return XMPMeta(_xmp_internal_ref=xmpptr)
        else:
            return None
示例#16
0
文件: core.py 项目: vicgc/Uforia
    def __init__(self, **kwargs):
        """
		:param xmp_str Optional.
		:param xmp_internal_ref Optional - used for internal purposes.
		"""
        if '_xmp_internal_ref' in kwargs:
            self.xmpptr = kwargs['_xmp_internal_ref']
        else:
            self.xmpptr = _exempi.xmp_new_empty()
            _check_for_error()

            if 'xmp_str' in kwargs:
                self.parse_from_str(kwargs['xmp_str'])

        self.iterator = None
示例#17
0
	def __init__( self, **kwargs ):
		"""
		:param xmp_str Optional.
		:param xmp_internal_ref Optional - used for internal purposes.
		"""
		if '_xmp_internal_ref' in kwargs:
			self.xmpptr = kwargs['_xmp_internal_ref']
		else:
			self.xmpptr = _exempi.xmp_new_empty()
			_check_for_error()
		
			if 'xmp_str' in kwargs:
				self.parse_from_str( kwargs['xmp_str'] )
		
		self.iterator = None
示例#18
0
文件: files.py 项目: JJWTimmer/Uforia
	def close_file(self, close_flags=XMP_CLOSE_NOOPTION):
		"""
		Close file after use. XMP will not be written to file until
		this method has been called.

		:param close_flags: One of the close flags
		:raises XMPError: in case of errors.

		.. todo::
			Change signature into using kwargs to set option flag
		"""
		if not _exempi.xmp_files_close(self.xmpfileptr, close_flags):
			_check_for_error()
		else:
			self._file_path = None
示例#19
0
    def close_file(self, close_flags=XMP_CLOSE_NOOPTION):
        """
		Close file after use. XMP will not be written to file until
		this method has been called.
		
		:param close_flags: One of the close flags
		:raises XMPError: in case of errors.
		
		.. todo:: 
			Change signature into using kwargs to set option flag
		"""
        if not _exempi.xmp_files_close(self.xmpfileptr, close_flags):
            _check_for_error()
        else:
            self._file_path = None
示例#20
0
	def serialize_and_format( self, padding=0, newlinechr='\n', tabchr = '\t', indent=0, **kwargs ):
		"""
		Serializes an XMPMeta object into a string as RDF. Note, normally it is sufficient to use either
		`serialize_to_str` or `serialize_to_unicode` unless you need high degree of control over the serialization.
		
		The specified parameters must be logically consistent, an exception is raised if not. You cannot specify 
		both `omit_packet_wrapper` along with `read_only_packet`, `include_thumbnail_pad`, or `exact_packet_length`.
		
		:param padding: The number of bytes of padding, useful for modifying embedded XMP in place.
		:param newlinechr: The new line character to use.
		:param tabchr: The indentation character to use.
		:param indent: The initial indentation level.
		:param omit_packet_wrapper: Do not include an XML packet wrapper.
		:param read_only_packet: Create a read-only XML packet wapper.
		:param use_compact_format: Use a highly compact RDF syntax and layout.
		:param include_thumbnail_pad: Include typical space for a JPEG thumbnail in the padding if no xmp:Thumbnails property is present.
		:param exact_packet_length: The padding parameter provides the overall packet length.
		:param write_alias_comments: Include XML comments for aliases.
		:param omit_all_formatting: Omit all formatting whitespace.
		:return: XMPMeta object serialized into a string as RDF.
		:rtype: `unicode` string.
		"""
		res_str = None
		
		# Ensure padding is an int.
		padding = int(padding)
		indent = int(indent)	
		tabchr = str(tabchr)	
		newlinechr = str(newlinechr)
		
		# Define options bitmask
		options = options_mask( XMP_SERIAL_OPTIONS, **kwargs )
		
		# Serialize
		xmpstring = _XMPString()
		res = _exempi.xmp_serialize_and_format( self.xmpptr, xmpstring.ptr, options, padding, newlinechr, tabchr, indent )
		_check_for_error()
		
		# Get string
		if res:
			res_str = xmpstring.__str__()
			
		del xmpstring
		return res_str
示例#21
0
	def parse_from_str( self, xmp_packet_str, xmpmeta_wrap = False, input_encoding = None ):
		"""
		Parses RDF from a string into a XMP object. The input for parsing may be any valid 
		Unicode encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged.
		
		Note RDF string must contain an outermost <x:xmpmeta> object.
		
		:param xmp_packet_str: String to parse.
		:param xmpmeta_wrap: Optional - If True, the string will be wrapped in an <x:xmpmeta> element.
		:param input_encoding: Optional - If `xmp_packet_str` is a 8-bit string, it will by default be assumed to be UTF-8 encoded.
		:return:  true if :class:`libxmp.core.XMPMeta` object can be written in file.
		:rtype: bool
		"""
		xmp_packet_str = _encode_as_utf8( xmp_packet_str, input_encoding )
		
		if xmpmeta_wrap:
			xmp_packet_str = "<x:xmpmeta xmlns:x='adobe:ns:meta/'>%s</x:xmpmeta>" % xmp_packet_str
		
		l = len(xmp_packet_str)
		res = _exempi.xmp_parse(self.xmpptr, xmp_packet_str, l )
		_check_for_error()
		return res		
示例#22
0
文件: core.py 项目: vicgc/Uforia
 def __del__(self):
     _check_for_error()
示例#23
0
	def __init__( self, xmp_obj, schema_ns=None, prop_name=None, **kwargs ):
		self.options = options_mask(consts.XMP_ITERATOR_OPTIONS, **kwargs) if kwargs else 0
		self.xmpiteratorptr = _exempi.xmp_iterator_new( xmp_obj.xmpptr, schema_ns, prop_name, self.options)
		_check_for_error()
		self.schema = schema_ns
		self.prop_name = prop_name
示例#24
0
	def __del__(self):
		_check_for_error()