예제 #1
0
 def StartElementHandler(self, name, attrs):
     self.out.append('Start element: ' + repr(name) + ' ' +
                     sortdict(attrs))
예제 #2
0
 def StartElementHandler(self, name, attrs):
     self.out.append('Start element: ' + repr(name) + ' ' +
                     sortdict(attrs))
예제 #3
0
 def StartElementHandler(self, name, attrs):
     print 'Start element:\n\t', repr(name), sortdict(attrs)
예제 #4
0
 def StartElementHandler(self, name, attrs):
     self.out.append("Start element: " + repr(name) + " " + sortdict(attrs))
예제 #5
0
 def StartElementHandler(self, name, attrs):
     print 'Start element:\n\t', repr(name), sortdict(attrs)
예제 #6
0
def f(*a, **k):
    print a, sortdict(k)
예제 #7
0
try:
    print cre.group('one')
except regex.error:
    print 'caught expected exception'
else:
    print 'expected regex.error not raised'

print 'matching with group names and symcomp()'
cre = regex.symcomp(re)
print cre.match('801 999')
print cre.group(0)
print cre.group('one')
print cre.group(1, 2)
print cre.group('one', 'two')
print 'realpat:', cre.realpat
print 'groupindex:', sortdict(cre.groupindex)

re = 'world'
cre = regex.compile(re)
print 'not case folded search:', cre.search('HELLO WORLD')
cre = regex.compile(re, regex.casefold)
print 'case folded search:', cre.search('HELLO WORLD')

print '__members__:', cre.__members__
print 'regs:', cre.regs
print 'last:', cre.last
print 'translate:', len(cre.translate)
print 'givenpat:', cre.givenpat

print 'match with pos:', cre.match('hello world', 7)
print 'search with pos:', cre.search('hello world there world', 7)
예제 #8
0
def g(x, *y, **z):
    print x, y, sortdict(z)
예제 #9
0
    def next(self):
        if self.c == 4:
            raise StopIteration
        c = self.c
        self.c += 1
        return c


g(*Nothing())

# make sure the function call doesn't stomp on the dictionary?
d = {'a': 1, 'b': 2, 'c': 3}
d2 = d.copy()
verify(d == d2)
g(1, d=4, **d)
print sortdict(d)
print sortdict(d2)
verify(d == d2, "function call modified dictionary")


# what about willful misconduct?
def saboteur(**kw):
    kw['x'] = locals()  # yields a cyclic kw
    return kw


d = {}
kw = saboteur(a=1, **d)
verify(d == {})
# break the cycle
del kw['x']
예제 #10
0
def g(x, *y, **z):
    print x, y, sortdict(z)
예제 #11
0
def f(*a, **k):
    print a, sortdict(k)
예제 #12
0
class Nothing:
    def __len__(self):
        return 5
    def __getitem__(self, i):
        if i < 3:
            return i
        else:
            raise IndexError, i
g(*Nothing())

# make sure the function call doesn't stomp on the dictionary?
d = {'a': 1, 'b': 2, 'c': 3}
d2 = d.copy()
verify(d == d2)
g(1, d=4, **d)
print sortdict(d)
print sortdict(d2)
verify(d == d2, "function call modified dictionary")

# what about willful misconduct?
def saboteur(**kw):
    kw['x'] = locals() # yields a cyclic kw
    return kw
d = {}
kw = saboteur(a=1, **d)
verify(d == {})
# break the cycle
del kw['x']

try:
    g(1, 2, 3, **{'x':4, 'y':5})