diff options
author | Javier Santacruz <javier.santacruz.lc@gmail.com> | 2013-10-17 17:24:28 +0200 |
---|---|---|
committer | Javier Santacruz <javier.santacruz.lc@gmail.com> | 2013-10-17 17:24:28 +0200 |
commit | 227f1404a4012c52f75b270f237c6c6bc0579cc3 (patch) | |
tree | 7a936083c8b84b97c0690e049d6da97076761f18 /alembic/migration.py | |
parent | c84e3f1fd76a9fa7d8ee6221a21b7ed9188ba2f3 (diff) | |
download | alembic-227f1404a4012c52f75b270f237c6c6bc0579cc3.tar.gz |
Fixes stdout --sql output in python2
When output_encoding is set, wraps the output buffer into a io.TextIOWrapper class
This means that the output_buffer has to be a io.IOBase instance
in order to work along with the TextIOWrapper
Handles wrapping when the buffer is Python2 stdtout, which has 'file' type
Adds test for this situation
Diffstat (limited to 'alembic/migration.py')
-rw-r--r-- | alembic/migration.py | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/alembic/migration.py b/alembic/migration.py index 2b47c91..657e60d 100644 --- a/alembic/migration.py +++ b/alembic/migration.py @@ -6,7 +6,7 @@ from sqlalchemy import MetaData, Table, Column, String, literal_column from sqlalchemy import create_engine from sqlalchemy.engine import url as sqla_url -from .compat import callable +from .compat import callable, writable_buffer from . import ddl, util log = logging.getLogger(__name__) @@ -71,13 +71,14 @@ class MigrationContext(object): self.connection = connection self._migrations_fn = opts.get('fn') self.as_sql = as_sql + self.output_buffer = opts.get("output_buffer", sys.stdout) - if opts.get('output_encoding'): + if "output_encoding" in opts: self.output_buffer = io.TextIOWrapper( - self.output_buffer, - opts['output_encoding'] - ) + opts.get("output_buffer") or writable_buffer(sys.stdout), + opts.get('output_encoding') + ) self._user_compare_type = opts.get('compare_type', False) self._user_compare_server_default = opts.get( |