some source code about twisted

This commit is contained in:
JamesonHuang
2015-06-15 22:20:58 +08:00
parent 8791e644e5
commit dff86defdb
1113 changed files with 407155 additions and 0 deletions

View File

@ -0,0 +1,40 @@
# This code illustrates a few aspects of Failures.
# Generally, Twisted makes Failures for us.
from twisted.python.failure import Failure
class RhymeSchemeViolation(Exception): pass
print 'Just making an exception:'
print
e = RhymeSchemeViolation()
failure = Failure(e)
# Note this failure doesn't include any traceback info
print failure
print
print
print 'Catching an exception:'
print
def analyze_poem(poem):
raise RhymeSchemeViolation()
try:
analyze_poem("""\
Roses are red.
Violets are violet.
That's why they're called Violets.
Duh.
""")
except:
failure = Failure()
# This failure saved both the exception and the traceback
print failure