Ejemplo n.º 1
0
    def bytes( self, *args, **kwargs ):
        """
        Write the bytes-like object values to the current TAG_Byte_Array.

        This method may only be called between calls to the .startByteArray() and .endByteArray() methods.
        """
        raise NBTFormatError( "Attempted to write bytes, but current tag is not a TAG_Byte_Array." )
Ejemplo n.º 2
0
    def end( self, *args, **kwargs ):
        """
        Finish writing the root TAG_Compound.

        This method may only be called in tandem with a prior call to .start().
        """
        raise NBTFormatError( "Attempted to end the root TAG_Compound, but the current tag is not the root TAG_Compound!" )
Ejemplo n.º 3
0
    def long( self, *args, **kwargs ):
        """
        Write a TAG_Long with the given value.

        value is expected to be a number in the range [-9223372036854775808, 9223372036854775807].
        """
        raise NBTFormatError( "A TAG_Long cannot be created here." )
Ejemplo n.º 4
0
    def double( self, *args, **kwargs ):
        """
        Write a TAG_Double with the given value.

        value is expected to be a float.
        """
        raise NBTFormatError( "A TAG_Double cannot be created here." )
Ejemplo n.º 5
0
    def int( self, *args, **kwargs ):
        """
        Write a TAG_Int with the given value.

        value is expected to be a number in the range [-2147483648, 2147483647].
        """
        raise NBTFormatError( "A TAG_Int cannot be created here." )
Ejemplo n.º 6
0
    def short( self, *args, **kwargs ):
        """
        Write a TAG_Short with the given value.

        value is expected to be an int in the range [-32768, 32767].
        """
        raise NBTFormatError( "A TAG_Short cannot be created here." )
Ejemplo n.º 7
0
    def byte( self, *args, **kwargs ):
        """
        Write a TAG_Byte with the given value.

        value is expected to be an int in the range [-128, 127]. 
        """
        raise NBTFormatError( "A TAG_Byte cannot be created here." )
Ejemplo n.º 8
0
    def start( self, *args, **kwargs ):
        """
        Start the root TAG_Compound.

        After calling .start() and writing tags, the .end() method must be called to finish writing the root TAG_Compound.
        """
        raise NBTFormatError( "The root TAG_Compound cannot be created here." )
Ejemplo n.º 9
0
    def string( self, *args, **kwargs ):
        """
        Write a TAG_String.

        value is expected to be a UTF-8 str.
        len( value ) is expected to be in the range [0, 32767].
        """
        raise NBTFormatError( "A TAG_String cannot be created here." )
Ejemplo n.º 10
0
    def bytearray( self, *args, **kwargs ):
        """
        Write a TAG_Byte_Array consisting of the given bytes-like object, values.

        values is expected to be a bytes-like object containing integers in the range [0,255].
        len(values) is expected to be in the range [0, 2147483647].
        """
        raise NBTFormatError( "A TAG_Byte_Array cannot be created here." )
Ejemplo n.º 11
0
    def longs( self, *args, **kwargs ):
        """
        Write the given values to the current TAG_Long_Array.

        values is expected to be a sequence (tuple, list, etc) of ints in the range [-9223372036854775808, 9223372036854775807].

        This method may only be called between calls to the .startLongArray() and .endLongArray() methods.
        """
        raise NBTFormatError( "Attempted to write ints, but the current tag is not a TAG_Long_Array." )
Ejemplo n.º 12
0
 def bytes( self, values ):
     #if safe
     a = self._a + len( values )
     b = self._b
     if a > b:
         raise NBTFormatError( "More than {:d} bytes were written.".format( b ) )
     self._a = a
     #end
     self._o.write( values )
Ejemplo n.º 13
0
 def longs( self, values ):
     #if safe
     a = self._a + len( values )
     b = self._b
     if a > b:
         raise NBTFormatError( "More than {:d} longs were written.".format( b ) )
     self._a = a
     #end
     _wls( _ccrla( values ), self._o )
Ejemplo n.º 14
0
 def endLongArray( self ):
     #if safe
     a = self._a
     b = self._b
     if a != b:
         raise NBTFormatError( "Expected {:d} longs, but only {:d} longs were written.".format( b, a ) )
     self.__class__, self._a, self._b = self._s.pop()
     #else
     self.__class__ = self._s.pop()
Ejemplo n.º 15
0
    def ints( self, *args, **kwargs ):
        """
        Write the given values to the current TAG_Int_Array.

        values is expected to be a sequence (tuple, list, etc) of ints in the range [-2147483648, 2147483647].

        This method may only be called between calls to the .startIntArray() and .endIntArray() methods.
        """
        raise NBTFormatError( "Attempted to write ints, but the current tag is not a TAG_Int_Array." )
Ejemplo n.º 16
0
 def start( self, name="" ):
     #if safe
     if self._r is True:
         raise NBTFormatError( "The root TAG_Compound has already been created." )
     self._r = True
     #end
     _wtn( TAG_COMPOUND, name, self._o )
     self.__class__ = _NBTWriterRootCompound
     #if safe
     self._c = set()
     #end
Ejemplo n.º 17
0
 def _al( self, tagType ):
     """
     Asserts that the tagType of the element matches the list's tagType.
     Adds 1 to the count of tags written so far and asserts that the list length hasn't been exceeded.
     """
     c = self._c
     if tagType != c:
         raise WrongTagError( c, tagType )
     a = self._a + 1
     b = self._b
     if a > b:
         raise NBTFormatError( "More than {:d} tags were written.".format( b ) )
     self._a = a
Ejemplo n.º 18
0
    def list( self, *args, **kwargs ):
        """
        Write a TAG_List containing the values stored in values.

        tagType is expected to be a valid numerical tag type (e.g. jnbt.TAG_FLOAT, jnbt.TAG_BYTE_ARRAY) identifying the tags that will be written to the list.
        len(values) is expected to be in the range [0, 2147483647].
        All values in values are expected to be the python type corresponding to tagType (e.g. if tagType is jnbt.TAG_DOUBLE, we expect each value to be a float).
        If values is empty, tagType should preferably be jnbt.TAG_END.
        Otherwise, tagType can be any type except for jnbt.TAG_LIST or jnbt.TAG_COMPOUND.
        Automatically writing these types would require inferring the types of the tags they store, which is not possible in our implementation because several
        tags map to the same python type (e.g. TAG_Float, TAG_Double -> float).
        In other words, it would be ambiguous. To write a list containing these types, use startList()/endList() instead.
        """
        raise NBTFormatError( "A TAG_List cannot be created here." )
Ejemplo n.º 19
0
    def startByteArray( self, *args, **kwargs ):
        """
        Start writing a TAG_Byte_Array that will contain length elements.

        length is expected to be an int in the range [0, 2147483647].

        After calling the .startByteArray( length ) method, a total of length bytes must be written via calls to the .bytes() method.
        Finally, the .endByteArray() method must be called to finish writing the byte array.

        Example:
            writer.startByteArray( "mybytes", 16 )
            writer.bytes( b"\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" )
            writer.bytes( b"\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" )
            writer.endByteArray()
        """
        raise NBTFormatError( "A TAG_Byte_Array cannot be created here." )
Ejemplo n.º 20
0
    def startLongArray( self, *args, **kwargs ):
        """
        Start writing a TAG_Long_Array that will contain length elements.

        length is expected to be an int in the range [0, 2147483647].

        After calling the .startLongArray( length ) method, a total of length longs must be written via calls to the .longs() method.
        Finally, the .endLongArray() method must be called to finish writing the long array.

        Example:
            writer.startLongArray( "my_longs", 16 )
            writer.longs( ( 0, 1,  2,  3,  4,  5,  6,  7 ) )
            writer.longs( ( 8, 9, 10, 11, 12, 13, 14, 15 ) )
            writer.endLongArray()
        """
        raise NBTFormatError( "A TAG_Long_Array cannot be created here." )
Ejemplo n.º 21
0
 def endByteArray( self, *args, **kwargs ):
     """
     Finish writing a TAG_Byte_Array.
     This method may only be called in tandem with a prior call to .startByteArray().
     """
     raise NBTFormatError( "Attempted to end a TAG_Byte_Array, but the current tag is not a TAG_Byte_Array." )
Ejemplo n.º 22
0
 def endCompound( self ):
     raise NBTFormatError( "You must call .end() instead of .endCompound() to end the root TAG_Compound." )
Ejemplo n.º 23
0
 def endList( self ):
     a = self._a
     b = self._b
     if a != b:
         raise NBTFormatError( "Expected {:d} tags, but only {:d} tags were written.".format( b, a ) )
     self.__class__, self._a, self._b, self._c = self._s.pop()
Ejemplo n.º 24
0
 def endIntArray( self ):
     a = self._a
     b = self._b
     if a != b:
         raise NBTFormatError( "Expected {:d} ints, but only {:d} ints were written.".format( b, a ) )
     self.__class__, self._a, self._b = self._s.pop()