<commit_before>#! /bin/env python

import sys

import numpy as np
import xml.dom.minidom
from landlab.io.vtk.encoders import encode
from landlab.io.vtk.vtktypes import SYS_TO_VTK_ENDIAN, NUMPY_TO_VTK_TYPE


class VtkExtent(object):
    def __init__(self, shape):
        assert(len(shape) <= 3)

        self._shape = tuple(shape)

        self._extent = []
        for dim_length in shape:
            self._extent.append((0, dim_length - 1))

        for _ in xrange(3 - len(shape)):
            self._extent.append((0, 0))

        self._extent_str = ' '.join (['%d %d' % x for x in self._extent])
        
    def __str__(self):
        return self._extent_str

    def __repr__(self):
        return 'VtkExtent(%s)' % self._shape
        
        
class VtkOrigin(object):
    def __init__(self, origin, spacing):
        assert(len(spacing) <= 3)
        assert(len(spacing) == len(origin))

        self._spacing = spacing
        self._cell_origin = []
        for (dx, x0) in zip(spacing, origin):
            self._cell_origin.append(x0 - dx * .5)

        for _ in xrange(3 - len(origin)):
            self._cell_origin.append(0.)

        self._origin_str = ' '.join (['%f' % x for x in self._cell_origin])
        
    def __str__ (self):
        return self._origin_str

    def __repr__(self):
        return 'VtkOrigin(%s, %s)' % (self._cell_origin, self._spacing)


class VtkSpacing(object):
    def __init__(self, spacing):
        assert(len(spacing) <= 3)

        self._spacing = spacing

        self._padded_spacing = []
        for dx in spacing:
            self._padded_spacing.append(dx)

        for _ in xrange(3 - len(spacing)):
            self._padded_spacing.append(0.)

        self._spacing_str = ' '.join (['%f' % x for x in self._padded_spacing])
        
    def __str__(self):
        return self._spacing_str
    
    def __repr__(self):
        return 'VtkSpacing(%s)' % self._spacing
    
    
class VtkElement(object, xml.dom.minidom.Element):
    def __init__ (self, name, **kwargs):
        xml.dom.minidom.Element.__init__(self, str(name), namespaceURI='VTK')
        self.setAttributes(**kwargs)

    def setAttributes(self, **kwargs):
        for (attr, value) in kwargs.items():
            self.setAttribute(attr, str(value))

    def getAttributes(self, names=None):
        attrs = {}

        if names is None:
            for index in xrange(self.attributes.length):
                attr = self.attributes.item(index)
                attrs[attr.localName] = attr.value
        else:
            for index in xrange(self.attributes.length):
                attr = self.attributes.item(index)
                if attr.localName in names:
                    attrs[attr.localName] = attr.value

        return attrs


class VtkTextElement(xml.dom.minidom.Text):
    def __init__(self, text):
        self.replaceWholeText(text)

<commit_msg>Changed VtkElement to not inherit from object.<commit_after>#! /bin/env python

import sys

import numpy as np
import xml.dom.minidom
from landlab.io.vtk.encoders import encode
from landlab.io.vtk.vtktypes import SYS_TO_VTK_ENDIAN, NUMPY_TO_VTK_TYPE


class VtkExtent(object):
    def __init__(self, shape):
        assert(len(shape) <= 3)

        self._shape = tuple(shape)

        self._extent = []
        for dim_length in shape:
            self._extent.append((0, dim_length - 1))

        for _ in xrange(3 - len(shape)):
            self._extent.append((0, 0))

        self._extent_str = ' '.join (['%d %d' % x for x in self._extent])
        
    def __str__(self):
        return self._extent_str

    def __repr__(self):
        return 'VtkExtent(%s)' % self._shape
        
        
class VtkOrigin(object):
    def __init__(self, origin, spacing):
        assert(len(spacing) <= 3)
        assert(len(spacing) == len(origin))

        self._spacing = spacing
        self._cell_origin = []
        for (dx, x0) in zip(spacing, origin):
            self._cell_origin.append(x0 - dx * .5)

        for _ in xrange(3 - len(origin)):
            self._cell_origin.append(0.)

        self._origin_str = ' '.join (['%f' % x for x in self._cell_origin])
        
    def __str__ (self):
        return self._origin_str

    def __repr__(self):
        return 'VtkOrigin(%s, %s)' % (self._cell_origin, self._spacing)


class VtkSpacing(object):
    def __init__(self, spacing):
        assert(len(spacing) <= 3)

        self._spacing = spacing

        self._padded_spacing = []
        for dx in spacing:
            self._padded_spacing.append(dx)

        for _ in xrange(3 - len(spacing)):
            self._padded_spacing.append(0.)

        self._spacing_str = ' '.join (['%f' % x for x in self._padded_spacing])
        
    def __str__(self):
        return self._spacing_str
    
    def __repr__(self):
        return 'VtkSpacing(%s)' % self._spacing
    
    
#class VtkElement(object, xml.dom.minidom.Element):
class VtkElement(xml.dom.minidom.Element):
    def __init__ (self, name, **kwargs):
        xml.dom.minidom.Element.__init__(self, str(name), namespaceURI='VTK')
        self.setAttributes(**kwargs)

    def setAttributes(self, **kwargs):
        for (attr, value) in kwargs.items():
            self.setAttribute(attr, str(value))

    def getAttributes(self, names=None):
        attrs = {}

        if names is None:
            for index in xrange(self.attributes.length):
                attr = self.attributes.item(index)
                attrs[attr.localName] = attr.value
        else:
            for index in xrange(self.attributes.length):
                attr = self.attributes.item(index)
                if attr.localName in names:
                    attrs[attr.localName] = attr.value

        return attrs


class VtkTextElement(xml.dom.minidom.Text):
    def __init__(self, text):
        self.replaceWholeText(text)


{'fraction_non_alphanumeric': 0.11879160266257041, 'fraction_numerical': 0.005120327700972862, 'mean_word_length': 2.1727125067677315, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 9}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5866704', 'n_tokens_mistral': 1926, 'n_tokens_neox': 1822, 'n_words': 416}