import _test as test
import sys
import gzip

foo = test.Foo()

# Test ostream wrapping based on Ralf W. Grosse-Kunstleve's 
# boost_adaptbx::python::streambuf class
foo.say_hello_streambuf(test.cout) # OK
foo.say_hello_streambuf(test.streambuf(sys.stdout)) # OK
foo.say_hello_streambuf(sys.stdout) # OK

# Test wrapping based on Michele De Stefano's 
# mds_utils::python::oFileObj class
foo.say_hello_fileobj(test.cout) # OK
foo.say_hello_fileobj(test.oFileObj(sys.stdout)) # OK
foo.say_hello_fileobj(sys.stdout) # OK

# But I don't know how to create a wrapper to delegate this constructor
for ctor_arg in (
            test.cout, # OK
            test.streambuf(sys.stdout), # Boost.Python.ArgumentError
            test.oFileObj(sys.stdout), # Boost.Python.ArgumentError
            sys.stdout # Boost.Python.ArgumentError
            ):
    try:
        foo = test.Foo(ctor_arg)
    except:
        print "Argument error with argument %s" % ctor_arg

g = gzip.open('test.gz', 'w')
foo.say_hello_streambuf(g)
# foo.say_hello_fileobj(g) # fails, so use streambuf...
foo2 = test.Foo(g)
g.close()

