<commit_before>#!/usr/bin/python

import os
from lxml import etree

from pyovf import ovf
from xobj import xobj

class OvfDocument(xobj.Document):

    nameSpaceMap = { 'ovf' : 'http://schemas.dmtf.org/ovf/envelope/1'}
                     # None : 'http://schemas.dmtf.org/ovf/envelope/1' }
    schemaFile = os.path.join(os.path.dirname(__file__),
                              "schemas/ovf-envelope.xsd")
    ovf_Envelope = ovf.Ovf

    def __init__(self, *args, **kwargs):
        schemaObj = etree.XMLSchema(file = self.schemaFile)
        xobj.Document.__init__(self, *args, **kwargs)

class NewOvf(ovf.Ovf):
    """
    Class factory to yield a new Ovf object.
    """
    def __init__(self):
        doc = OvfDocument()
        doc.ovf_Envelope = self

        self._doc = doc

        self.ovf_References = ovf.ReferencesSection()
        self.ovf_DiskSection = ovf.DiskSection()
        self.ovf_NetworkSection = ovf.NetworkSection()
        # self.ovf_VirtualSystem = [ { 'ovf_VirtualSystem' : ovf.VirtualSystem,
                                     # 'ovf_VirtualSystemCollection' : object } ]
        self.ovf_VirtualSystem = []

def OvfFile(f):
    schemaPath = os.path.join(os.path.dirname(__file__),
                              "schemas/ovf-envelope.xsd")
    doc = xobj.parsef(f, documentClass=OvfDocument, schemaf=schemaPath)
    ovf = doc.ovf_Envelope
    ovf._doc = doc
    return ovf
<commit_msg>Be sure to pass a schema parameter to xobj.Document.__init__ so that validation is done.<commit_after>#!/usr/bin/python

import os
from lxml import etree

from pyovf import ovf
from xobj import xobj

class OvfDocument(xobj.Document):

    nameSpaceMap = { 'ovf' : 'http://schemas.dmtf.org/ovf/envelope/1'}
                     # None : 'http://schemas.dmtf.org/ovf/envelope/1' }
    schemaFile = os.path.join(os.path.dirname(__file__),
                              "schemas/ovf-envelope.xsd")
    ovf_Envelope = ovf.Ovf

    def __init__(self, *args, **kwargs):
        schemaObj = etree.XMLSchema(file = self.schemaFile)
        kwargs['schema'] = schemaObj
        xobj.Document.__init__(self, *args, **kwargs)

class NewOvf(ovf.Ovf):
    """
    Class factory to yield a new Ovf object.
    """
    def __init__(self):
        doc = OvfDocument()
        doc.ovf_Envelope = self

        self._doc = doc

        self.ovf_References = ovf.ReferencesSection()
        self.ovf_DiskSection = ovf.DiskSection()
        self.ovf_NetworkSection = ovf.NetworkSection()
        # self.ovf_VirtualSystem = [ { 'ovf_VirtualSystem' : ovf.VirtualSystem,
                                     # 'ovf_VirtualSystemCollection' : object } ]
        self.ovf_VirtualSystem = []

def OvfFile(f):
    schemaPath = os.path.join(os.path.dirname(__file__),
                              "schemas/ovf-envelope.xsd")
    doc = xobj.parsef(f, documentClass=OvfDocument, schemaf=schemaPath)
    ovf = doc.ovf_Envelope
    ovf._doc = doc
    return ovf

{'fraction_non_alphanumeric': 0.11601085481682497, 'fraction_numerical': 0.0013568521031207597, 'mean_word_length': 2.3435374149659864, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6151342', 'n_tokens_mistral': 991, 'n_tokens_neox': 960, 'n_words': 179}