Ejemplo n.º 1
0
def condenseCodepoints(codepoints):
    ranges = []
    codepoints = list(codepoints)
    codepoints.sort()
    range_min = None
    for ri in xrange(len(codepoints)):
        codepoint = codepoints[ri]
        if not isinstance(codepoint, tuple):
            if range_min is None:
                range_last = range_min = codepoint
                range_next = range_last + 1
                continue
            if codepoint == range_next:
                range_last = codepoint
                range_next += 1
                continue
        if range_min is not None:
            ranges.append((range_min, range_last))
        if isinstance(codepoint, tuple):
            range_min = None
            ranges.append(codepoint)
        else:
            range_last = range_min = codepoints[ri]
            range_next = range_last + 1
    if range_min is not None:
        ranges.append((range_min, range_last))
    return ranges
Ejemplo n.º 2
0
    def testK2010b (self):
        def makeInstance (num_m, num_reps):
            s = []
            while 0 < num_reps:
                num_reps -= 1
                s.append('t')
                s.append('m' * num_m)
            return ''.join(s)

        m = NumericalConstraint(Symbol('m'), 2, 12)
        ex = NumericalConstraint(Sequence(Symbol('t'), m), 0, 65535)
        cfg = Configuration(ex.buildAutomaton())
        self.assertTrue(cfg.isAccepting())
        cfg = cfg.step('t')
        self.assertFalse(cfg.isAccepting())
        cfg = cfg.step('m')
        self.assertFalse(cfg.isAccepting())
        cfg = cfg.step('m')
        self.assertTrue(cfg.isAccepting())
        cfg = cfg.step('t')
        self.assertFalse(cfg.isAccepting())
        for _ in xrange(12):
            cfg = cfg.step('m')
        self.assertTrue(cfg.isAccepting())
        self.assertRaises(UnrecognizedSymbolError, cfg.step, 'm')
Ejemplo n.º 3
0
def condenseCodepoints (codepoints):
    ranges = []
    codepoints = list(codepoints)
    codepoints.sort()
    range_min = None
    for ri in xrange(len(codepoints)):
        codepoint = codepoints[ri]
        if not isinstance(codepoint, tuple):
            if range_min is None:
                range_last = range_min = codepoint
                range_next = range_last + 1
                continue
            if codepoint == range_next:
                range_last = codepoint
                range_next += 1
                continue
        if range_min is not None:
            ranges.append( (range_min, range_last) )
        if isinstance(codepoint, tuple):
            range_min = None
            ranges.append(codepoint)
        else:
            range_last = range_min = codepoints[ri]
            range_next = range_last + 1
    if range_min is not None:
        ranges.append( (range_min, range_last) )
    return ranges
Ejemplo n.º 4
0
 def testBasic(self):
     s = eST(1)
     self.assertEqual(s, 1)
     c = eCT(2)
     self.assertEqual(c.value(), 2)
     instance = eSTs(1, 2, 3, 4)
     self.assertEqual(4, len(instance.eST))
     self.assertTrue(
         functools.reduce(
             operator.iand,
             map(lambda _i: operator.eq(1 + _i, instance.eST[_i]),
                 xrange(len(instance.eST))), True))
     instance = eCTs(1, 2, 3, 4)
     self.assertEqual(4, len(instance.eCT))
     self.assertTrue(
         functools.reduce(
             operator.iand,
             map(lambda _i: operator.eq(1 + _i, instance.eCT[_i].value()),
                 xrange(len(instance.eCT))), True))
Ejemplo n.º 5
0
    def asTuples(self):
        """Return the codepoints as tuples denoting the ranges that are in
        the set.

        Each tuple C{(s, e)} indicates that the code points from C{s}
        (inclusive) to C{e}) (inclusive) are in the set."""

        rv = []
        start = None
        for ri in xrange(len(self.__codepoints)):
            if start is not None:
                rv.append((start, self.__codepoints[ri] - 1))
                start = None
            else:
                start = self.__codepoints[ri]
        if (start is not None) and (start <= self.MaxCodePoint):
            rv.append((start, self.MaxCodePoint))
        return rv
Ejemplo n.º 6
0
    def asTuples (self):
        """Return the codepoints as tuples denoting the ranges that are in
        the set.

        Each tuple C{(s, e)} indicates that the code points from C{s}
        (inclusive) to C{e}) (inclusive) are in the set."""

        rv = []
        start = None
        for ri in xrange(len(self.__codepoints)):
            if start is not None:
                rv.append( (start, self.__codepoints[ri]-1) )
                start = None
            else:
                start = self.__codepoints[ri]
        if (start is not None) and (start <= self.MaxCodePoint):
            rv.append( (start, self.MaxCodePoint) )
        return rv
Ejemplo n.º 7
0
 def _deepClone (self, node, docnode):
     if node.ELEMENT_NODE == node.nodeType:
         (ns_uri, node_name) = self._makeURINodeNamePair(node)
         clone_node = docnode.createElementNS(ns_uri, node_name)
         attrs = node.attributes
         for ai in xrange(attrs.length):
             clone_node.setAttributeNodeNS(self._deepClone(attrs.item(ai), docnode))
         for child in node.childNodes:
             clone_node.appendChild(self._deepClone(child, docnode))
         return clone_node
     if node.TEXT_NODE == node.nodeType:
         return docnode.createTextNode(node.data)
     if node.ATTRIBUTE_NODE == node.nodeType:
         (ns_uri, node_name) = self._makeURINodeNamePair(node)
         clone_node = docnode.createAttributeNS(ns_uri, node_name)
         clone_node.value = node.value
         return clone_node
     if node.COMMENT_NODE == node.nodeType:
         return docnode.createComment(node.data)
     raise ValueError('DOM node not supported in clone', node)
Ejemplo n.º 8
0
 def _deepClone (self, node, docnode):
     if node.ELEMENT_NODE == node.nodeType:
         (ns_uri, node_name) = self._makeURINodeNamePair(node)
         clone_node = docnode.createElementNS(ns_uri, node_name)
         attrs = node.attributes
         for ai in xrange(attrs.length):
             clone_node.setAttributeNodeNS(self._deepClone(attrs.item(ai), docnode))
         for child in node.childNodes:
             clone_node.appendChild(self._deepClone(child, docnode))
         return clone_node
     if node.TEXT_NODE == node.nodeType:
         return docnode.createTextNode(node.data)
     if node.ATTRIBUTE_NODE == node.nodeType:
         (ns_uri, node_name) = self._makeURINodeNamePair(node)
         clone_node = docnode.createAttributeNS(ns_uri, node_name)
         clone_node.value = node.value
         return clone_node
     if node.COMMENT_NODE == node.nodeType:
         return docnode.createComment(node.data)
     raise ValueError('DOM node not supported in clone', node)
Ejemplo n.º 9
0
def buildTest (num_reps, constraint='minOccurs="0" maxOccurs="1"'):
    edefs = []
    cdefs = []
    duse = []
    for r in xrange(num_reps):
        edefs.append('<xs:element name="rep%d" type="xs:string"/>' % (r,))
        cdefs.append('<xs:element ref="rep%d" %s/>' % (r, constraint))
        duse.append('<rep%d>text_%d</rep%d>' % (r, r, r))

    schema = ''.join([ '''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">''',
                   "\n".join(edefs),
                   '''<xs:element name="collection">
<xs:complexType><xs:sequence>''',
                   "\n".join(cdefs),
                   '''</xs:sequence></xs:complexType>
</xs:element>
</xs:schema>''' ])

    xmls = '<collection>' + ''.join(duse) + '</collection>'

    return (schema, xmls)
Ejemplo n.º 10
0
 def testBasic (self):
     s = eST(1)
     self.assertEqual(s, 1)
     c = eCT(2)
     self.assertEqual(c.value(), 2)
     instance = eSTs(1,2,3,4)
     self.assertEqual(4, len(instance.eST))
     self.assertTrue(functools.reduce(operator.iand, map(lambda _i: operator.eq(1+_i, instance.eST[_i]), xrange(len(instance.eST))), True))
     instance = eCTs(1,2,3,4)
     self.assertEqual(4, len(instance.eCT))
     self.assertTrue(functools.reduce(operator.iand, map(lambda _i: operator.eq(1+_i, instance.eCT[_i].value()), xrange(len(instance.eCT))), True))
Ejemplo n.º 11
0
    schema = ''.join([ '''<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">''',
                   "\n".join(edefs),
                   '''<xs:element name="collection">
<xs:complexType><xs:sequence>''',
                   "\n".join(cdefs),
                   '''</xs:sequence></xs:complexType>
</xs:element>
</xs:schema>''' ])

    xmls = '<collection>' + ''.join(duse) + '</collection>'

    return (schema, xmls)

for size in xrange(1, max_reps):
    (schema, xmls) = buildTest(size)

    t0 = time.time()
    code = pyxb.binding.generate.GeneratePython(schema_text=schema)
    t1 = time.time()
    rv = compile(code, 'test', 'exec')
    t2 = time.time()
    eval(rv)
    t3 = time.time()
    #open('code.py', 'w').write(code)
    #print xmls
    ct0 = time.time()
    doc = CreateFromDocument(xmls)
    ct1 = time.time()