diff --git a/rattail/batch/labels.py b/rattail/batch/labels.py index fa734eecaee90e52aa14d50e59f84317a578afd4..39d534710307922335cc107b94cb451009a92c4c 100644 --- a/rattail/batch/labels.py +++ b/rattail/batch/labels.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2016 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -29,6 +29,7 @@ from __future__ import unicode_literals, absolute_import import csv import logging +import six import sqlalchemy as sa from sqlalchemy import orm @@ -160,7 +161,7 @@ class LabelBatchHandler(BatchHandler): return product = row.product - row.brand_name = unicode(product.brand or '') + row.brand_name = six.text_type(product.brand or '') row.description = product.description row.size = product.size department = product.department diff --git a/rattail/batch/pricing.py b/rattail/batch/pricing.py index 61cae8cc4c5a86175eb3a529a6809bc0d02e582e..7b570c30d1ed9ffdfd1dac64375f72fd73f7cec1 100644 --- a/rattail/batch/pricing.py +++ b/rattail/batch/pricing.py @@ -1,4 +1,4 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework @@ -26,6 +26,7 @@ Handler for pricing batches from __future__ import unicode_literals, absolute_import +import six from sqlalchemy import orm from rattail.db import model @@ -64,7 +65,7 @@ class PricingBatchHandler(BatchHandler): product = row.product assert product - row.brand_name = unicode(product.brand or '') + row.brand_name = six.text_type(product.brand or '') row.description = product.description row.size = product.size department = product.department diff --git a/rattail/batch/purchase.py b/rattail/batch/purchase.py index cd62eae293c2e40c0dcf98779b0895d886c053bd..ab05a2644e810a7aed66bf21b997ac299aea35af 100644 --- a/rattail/batch/purchase.py +++ b/rattail/batch/purchase.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2016 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -26,6 +26,7 @@ Handler for purchase order batches from __future__ import unicode_literals, absolute_import +import six from sqlalchemy import orm from rattail.db import model, api @@ -100,7 +101,7 @@ class PurchaseBatchHandler(BatchHandler): cost = row.product.cost_for_vendor(batch.vendor) or row.product.cost row.upc = product.upc row.item_id = product.item_id - row.brand_name = unicode(product.brand or '') + row.brand_name = six.text_type(product.brand or '') row.description = product.description row.size = product.size if product.department: diff --git a/rattail/bouncer/handler.py b/rattail/bouncer/handler.py index e496612262c7b07e53911ff6cef70040eb93a6a9..685e29cc5e2b4a1a50ca0226bb9ee9c4bc6e0e4d 100644 --- a/rattail/bouncer/handler.py +++ b/rattail/bouncer/handler.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -24,12 +24,13 @@ Email Bounce Handlers """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import import os import datetime from email.utils import parsedate_tz, mktime_tz +import six from sqlalchemy import orm from flufl.bounce import all_failures @@ -136,12 +137,12 @@ class BounceHandler(object): emails = session.query(model.CustomerEmailAddress).filter_by(address=recipient) for email in emails: yield self.make_link(type="Rattail Customer", - title=unicode(email.customer), + title=six.text_type(email.customer), url=url.format(uuid=email.parent_uuid)) url = self.config.require('tailbone', 'url.person') emails = session.query(model.PersonEmailAddress).filter_by(address=recipient) for email in emails: yield self.make_link(type="Rattail Person", - title=unicode(email.person), + title=six.text_type(email.person), url=url.format(uuid=email.parent_uuid)) diff --git a/rattail/data/new-batch/webview.py b/rattail/data/new-batch/webview.py index a048a10cb2a128def2e3254948e05708f101f07b..640af80cc6279ca52ec4bde611c2c3ba2b21860a 100644 --- a/rattail/data/new-batch/webview.py +++ b/rattail/data/new-batch/webview.py @@ -6,6 +6,8 @@ Views for ${model_title} batches from __future__ import unicode_literals, absolute_import +import six + from rattail.db import model from tailbone.views.batch import FileBatchMasterView @@ -26,7 +28,7 @@ class ${model_name}View(FileBatchMasterView): url_prefix = '/batch/${table_name.replace('_', '-')}' def get_instance_title(self, batch): - return unicode(batch.vendor) + return six.text_type(batch.vendor) def configure_grid(self, g): g.joiners['vendor'] = lambda q: q.join(model.Vendor) diff --git a/rattail/importing/handlers.py b/rattail/importing/handlers.py index 9db0c067b488938c5f32df0218af72b0b11a31e7..104ad3b14da6f92c7bca603876053f85e017ecec 100644 --- a/rattail/importing/handlers.py +++ b/rattail/importing/handlers.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2016 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -29,6 +29,7 @@ from __future__ import unicode_literals, absolute_import import sys import logging +import six import humanize from rattail.time import make_utc @@ -374,7 +375,7 @@ class RecordRenderer(object): return label(record) def label(self, record): - return unicode(record) + return six.text_type(record) def get_url(self, record): """ diff --git a/rattail/importing/postgresql.py b/rattail/importing/postgresql.py index ee43af0dc5c5fca3f00cd4b71973bd21c9f19f1b..d89546d723a88bc06ab614ee2248c407163ab876 100644 --- a/rattail/importing/postgresql.py +++ b/rattail/importing/postgresql.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2016 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -30,6 +30,8 @@ import os import datetime import logging +import six + from rattail.importing import BulkImporter, ToSQLAlchemy from rattail.time import make_utc @@ -81,7 +83,7 @@ class BulkToPostgreSQL(BulkImporter, ToSQLAlchemy): value = value.replace('\n', '\\n') value = value.replace('\t', '\\t') # TODO: add test for this - return unicode(value) + return six.text_type(value) def flush_create_update(self): pass diff --git a/rattail/mail.py b/rattail/mail.py index 77303b7a4f2167b23cbb59f9d49b789e0e86aa87..ecc388085cc453cdc0371a63dc5b1517d9b8fa7d 100644 --- a/rattail/mail.py +++ b/rattail/mail.py @@ -179,7 +179,7 @@ class Email(object): """ Returns the value for the message's ``From:`` header. - :rtype: unicode + :rtype: str """ sender = self.config.get('rattail.mail', '{0}.from'.format(self.key)) if not sender: @@ -221,7 +221,7 @@ class Email(object): """ Returns a string to be used as the subject prefix for the message. - :rtype: unicode + :rtype: str """ prefix = self.config.get('rattail.mail', '{0}.prefix'.format(self.key)) if not prefix: @@ -236,7 +236,7 @@ class Email(object): Returns the base value for the message's subject header, i.e. minus prefix. - :rtype: unicode + :rtype: str """ subject = self.config.get('rattail.mail', '{0}.subject'.format(self.key), default=self.default_subject) @@ -253,7 +253,7 @@ class Email(object): complete subject also, in which case the prefix and base subject are not considered. - :rtype: unicode + :rtype: str """ return "{} {}".format(self.get_prefix(data), self.get_subject(data, render=render)) diff --git a/rattail/tests/importing/test_rattail.py b/rattail/tests/importing/test_rattail.py index aaa5a5b8de490eff8dae744231b16be976df95ad..1d2f485d8bc6032c2d5539a3f49d2f0ffbd0460e 100644 --- a/rattail/tests/importing/test_rattail.py +++ b/rattail/tests/importing/test_rattail.py @@ -1,9 +1,10 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- from __future__ import unicode_literals, absolute_import from unittest import TestCase +import six import sqlalchemy as sa from mock import patch from fixture import TempIO @@ -24,7 +25,7 @@ class DualRattailMixin(RattailMixin): self.host_engine = self.config.rattail_engines['host'] self.config.setdefault('rattail.db', 'keys', 'default, host') - self.config.setdefault('rattail.db', 'host.url', unicode(self.host_engine.url)) + self.config.setdefault('rattail.db', 'host.url', six.text_type(self.host_engine.url)) model = self.get_rattail_model() model.Base.metadata.create_all(bind=self.host_engine) self.host_session = Session(bind=self.host_engine) diff --git a/rattail/tests/importing/test_sqlalchemy.py b/rattail/tests/importing/test_sqlalchemy.py index b76a846d8a5b11a485a065908702539ca0335ada..ea230dad1831ab3c1e5b402ee04e017aa5b9bbb1 100644 --- a/rattail/tests/importing/test_sqlalchemy.py +++ b/rattail/tests/importing/test_sqlalchemy.py @@ -1,9 +1,10 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- from __future__ import unicode_literals, absolute_import from unittest import TestCase +import six from mock import patch import sqlalchemy as sa @@ -38,7 +39,7 @@ class TestFromSQLAlchemy(TestCase): session = Session() importer = saimport.FromSQLAlchemy(host_session=session, host_model_class=Widget) - self.assertEqual(unicode(importer.query()), + self.assertEqual(six.text_type(importer.query()), "SELECT widgets.id AS widgets_id, widgets.description AS widgets_description \n" "FROM widgets") diff --git a/rattail/vendors/catalogs.py b/rattail/vendors/catalogs.py index 51fd5da5d4bc7a1261378735693bc9d14c8a5824..1558881d96ff8f488097baede2b60ea15788af59 100644 --- a/rattail/vendors/catalogs.py +++ b/rattail/vendors/catalogs.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -24,10 +24,12 @@ Vendor Catalogs """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import from decimal import Decimal +import six + from rattail.exceptions import RattailError from rattail.util import load_entry_points @@ -89,6 +91,7 @@ class CatalogParser(object): return int(value) +@six.python_2_unicode_compatible class CatalogParserNotFound(RattailError): """ Exception raised when a vendor catalog parser is required, but cannot be @@ -98,8 +101,8 @@ class CatalogParserNotFound(RattailError): def __init__(self, key): self.key = key - def __unicode__(self): - return "Vendor catalog parser with key {0} cannot be located.".format(self.key) + def __str__(self): + return "Vendor catalog parser with key {} cannot be located.".format(self.key) def get_catalog_parsers(): diff --git a/rattail/vendors/invoices.py b/rattail/vendors/invoices.py index 4fcbaa093efbe098e75b87c372e74cfa8ba3f062..9b44b35bdc655cd3c7fafd2966b6af5c04d4feb7 100644 --- a/rattail/vendors/invoices.py +++ b/rattail/vendors/invoices.py @@ -1,8 +1,8 @@ -# -*- coding: utf-8 -*- +# -*- coding: utf-8; -*- ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2015 Lance Edgar +# Copyright © 2010-2017 Lance Edgar # # This file is part of Rattail. # @@ -24,10 +24,12 @@ Vendor Invoices """ -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import from decimal import Decimal +import six + from rattail.exceptions import RattailError from rattail.util import load_entry_points @@ -87,6 +89,7 @@ class InvoiceParser(object): return int(value) +@six.python_2_unicode_compatible class InvoiceParserNotFound(RattailError): """ Exception raised when a vendor invoice parser is required, but cannot be @@ -96,8 +99,8 @@ class InvoiceParserNotFound(RattailError): def __init__(self, key): self.key = key - def __unicode__(self): - return "Vendor invoice parser with key {0} cannot be located.".format(self.key) + def __str__(self): + return "Vendor invoice parser with key {} cannot be located.".format(self.key) def get_invoice_parsers():