Commit e1ba120c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #364 from toshok/fix-fasta

don't let AttributeError exceptions bubble out of softspace.  fixes fasta.py
parents c7821ec6 2f6fc405
......@@ -973,7 +973,7 @@ extern "C" int PyFile_SoftSpace(PyObject* f, int newflag) noexcept {
try {
return softspace(f, newflag);
} catch (ExcInfo e) {
abort();
return 0;
}
}
......
......@@ -167,6 +167,9 @@ extern "C" Box* deopt(AST_expr* expr, Box* value) {
extern "C" bool softspace(Box* b, bool newval) {
assert(b);
// TODO do we also need to wrap the isSubclass in the try{}? it
// can throw exceptions which would bubble up from print
// statements.
if (isSubclass(b->cls, file_cls)) {
int& ss = static_cast<BoxedFile*>(b)->f_softspace;
int r = ss;
......@@ -176,13 +179,18 @@ extern "C" bool softspace(Box* b, bool newval) {
}
bool r;
Box* gotten = getattrInternal(b, "softspace", NULL);
if (!gotten) {
try {
Box* gotten = getattrInternal(b, "softspace", NULL);
if (!gotten) {
r = 0;
} else {
r = nonzero(gotten);
}
setattrInternal(b, "softspace", boxInt(newval), NULL);
} catch (ExcInfo e) {
r = 0;
} else {
r = nonzero(gotten);
}
setattrInternal(b, "softspace", boxInt(newval), NULL);
return r;
}
......
import sys
import hashlib
class HashOutput:
def __init__(self):
self.m = hashlib.md5()
def write(self, string):
self.m.update(string)
def md5hash(self):
return self.m.hexdigest()
hash_output = HashOutput()
old_stdout = sys.stdout
sys.stdout = hash_output
print "Hello World!"
sys.stdout = old_stdout
print hash_output.md5hash()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment