1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938
|
Description: Adds support for python 3.2
Upstream source is using u'' strings which are incompatible with Python 3.2.
This patch replaces that with six.u() using the "six" python module.
Author: Thomas Goirand <zigo@debian.org>
Forwarded: no
Last-Update: 2014-02-12
--- a/scripts/import_cldr.py
+++ b/scripts/import_cldr.py
@@ -16,6 +16,7 @@ from optparse import OptionParser
import os
import re
import sys
+import six
try:
from xml.etree import cElementTree as ElementTree
except ImportError:
@@ -39,7 +40,7 @@ def _text(elem):
for child in elem:
buf.append(_text(child))
buf.append(elem.tail or '')
- return u''.join(filter(None, buf)).strip()
+ return six.u('').join(filter(None, buf)).strip()
NAME_RE = re.compile(r"^\w+$")
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -14,6 +14,7 @@
import doctest
import unittest
import pytest
+import six
from babel import core, Locale
from babel.core import default_locale, Locale
@@ -21,8 +22,8 @@ from babel.core import default_locale, L
def test_locale_provides_access_to_cldr_locale_data():
locale = Locale('en', 'US')
- assert u'English (United States)' == locale.display_name
- assert u'.' == locale.number_symbols['decimal']
+ assert six.u('English (United States)') == locale.display_name
+ assert six.u('.') == locale.number_symbols['decimal']
def test_locale_repr():
assert ("Locale('de', territory='DE')" == repr(Locale('de', 'DE')))
@@ -153,7 +154,7 @@ class TestLocaleClass:
def test_currency_formats_property(self):
assert (Locale('en', 'US').currency_formats[None].pattern ==
- u'\xa4#,##0.00')
+ six.u('\xa4#,##0.00'))
def test_percent_formats_property(self):
assert Locale('en', 'US').percent_formats[None].pattern == '#,##0%'
@@ -181,7 +182,7 @@ class TestLocaleClass:
time_zones = Locale('en', 'US').time_zones
assert (time_zones['Europe/London']['long']['daylight'] ==
'British Summer Time')
- assert time_zones['America/St_Johns']['city'] == u'St. John\u2019s'
+ assert time_zones['America/St_Johns']['city'] == six.u('St. John\u2019s')
def test_meta_zones_property(self):
meta_zones = Locale('en', 'US').meta_zones
@@ -190,7 +191,7 @@ class TestLocaleClass:
def test_zone_formats_property(self):
assert Locale('en', 'US').zone_formats['fallback'] == '%(1)s (%(0)s)'
- assert Locale('pt', 'BR').zone_formats['region'] == u'Hor\xe1rio %s'
+ assert Locale('pt', 'BR').zone_formats['region'] == six.u('Hor\xe1rio %s')
def test_first_week_day_property(self):
assert Locale('de', 'DE').first_week_day == 0
@@ -214,8 +215,8 @@ class TestLocaleClass:
assert Locale('fr', 'FR').time_formats['long'].pattern == 'HH:mm:ss z'
def test_datetime_formats_property(self):
- assert Locale('en').datetime_formats['full'] == u"{1} 'at' {0}"
- assert Locale('th').datetime_formats['medium'] == u'{1}, {0}'
+ assert Locale('en').datetime_formats['full'] == six.u("{1} 'at' {0}")
+ assert Locale('th').datetime_formats['medium'] == six.u('{1}, {0}')
def test_plural_form_property(self):
assert Locale('en').plural_form(1) == 'one'
--- a/tests/test_support.py
+++ b/tests/test_support.py
@@ -18,6 +18,7 @@ import tempfile
import unittest
import pytest
from datetime import date, datetime, timedelta
+import six
from babel import support
from babel.messages import Catalog
@@ -70,8 +71,8 @@ class TranslationsTestCase(unittest.Test
'foo'))
def test_upgettext(self):
- self.assertEqualTypeToo(u'Voh', self.translations.ugettext('foo'))
- self.assertEqualTypeToo(u'VohCTX', self.translations.upgettext('foo',
+ self.assertEqualTypeToo(six.u('Voh'), self.translations.ugettext('foo'))
+ self.assertEqualTypeToo(six.u('VohCTX'), self.translations.upgettext('foo',
'foo'))
def test_lpgettext(self):
@@ -92,14 +93,14 @@ class TranslationsTestCase(unittest.Test
'foos1', 2))
def test_unpgettext(self):
- self.assertEqualTypeToo(u'Voh1',
+ self.assertEqualTypeToo(six.u('Voh1'),
self.translations.ungettext('foo1', 'foos1', 1))
- self.assertEqualTypeToo(u'Vohs1',
+ self.assertEqualTypeToo(six.u('Vohs1'),
self.translations.ungettext('foo1', 'foos1', 2))
- self.assertEqualTypeToo(u'VohCTX1',
+ self.assertEqualTypeToo(six.u('VohCTX1'),
self.translations.unpgettext('foo', 'foo1',
'foos1', 1))
- self.assertEqualTypeToo(u'VohsCTX1',
+ self.assertEqualTypeToo(six.u('VohsCTX1'),
self.translations.unpgettext('foo', 'foo1',
'foos1', 2))
@@ -123,9 +124,9 @@ class TranslationsTestCase(unittest.Test
def test_dupgettext(self):
self.assertEqualTypeToo(
- u'VohD', self.translations.dugettext('messages1', 'foo'))
+ six.u('VohD'), self.translations.dugettext('messages1', 'foo'))
self.assertEqualTypeToo(
- u'VohCTXD', self.translations.dupgettext('messages1', 'foo', 'foo'))
+ six.u('VohCTXD'), self.translations.dupgettext('messages1', 'foo', 'foo'))
def test_ldpgettext(self):
self.assertEqualTypeToo(
@@ -147,14 +148,14 @@ class TranslationsTestCase(unittest.Test
def test_dunpgettext(self):
self.assertEqualTypeToo(
- u'VohD1', self.translations.dungettext('messages1', 'foo1', 'foos1', 1))
+ six.u('VohD1'), self.translations.dungettext('messages1', 'foo1', 'foos1', 1))
self.assertEqualTypeToo(
- u'VohsD1', self.translations.dungettext('messages1', 'foo1', 'foos1', 2))
+ six.u('VohsD1'), self.translations.dungettext('messages1', 'foo1', 'foos1', 2))
self.assertEqualTypeToo(
- u'VohCTXD1', self.translations.dunpgettext('messages1', 'foo', 'foo1',
+ six.u('VohCTXD1'), self.translations.dunpgettext('messages1', 'foo', 'foo1',
'foos1', 1))
self.assertEqualTypeToo(
- u'VohsCTXD1', self.translations.dunpgettext('messages1', 'foo', 'foo1',
+ six.u('VohsCTXD1'), self.translations.dunpgettext('messages1', 'foo', 'foo1',
'foos1', 2))
def test_ldnpgettext(self):
@@ -211,9 +212,9 @@ class NullTranslationsTestCase(unittest.
def test_same_return_values(self):
data = {
- 'message': u'foo', 'domain': u'domain', 'context': 'tests',
- 'singular': u'bar', 'plural': u'baz', 'num': 1,
- 'msgid1': u'bar', 'msgid2': u'baz', 'n': 1,
+ 'message': six.u('foo'), 'domain': six.u('domain'), 'context': 'tests',
+ 'singular': six.u('bar'), 'plural': six.u('baz'), 'num': 1,
+ 'msgid1': six.u('bar'), 'msgid2': six.u('baz'), 'n': 1,
}
for name in self.method_names():
method = getattr(self.translations, name)
@@ -284,11 +285,11 @@ def test_format_percent():
def test_lazy_proxy():
def greeting(name='world'):
- return u'Hello, %s!' % name
+ return six.u('Hello, %s!') % name
lazy_greeting = support.LazyProxy(greeting, name='Joe')
- assert str(lazy_greeting) == u"Hello, Joe!"
- assert u' ' + lazy_greeting == u' Hello, Joe!'
- assert u'(%s)' % lazy_greeting == u'(Hello, Joe!)'
+ assert str(lazy_greeting) == six.u("Hello, Joe!")
+ assert six.u(' ') + lazy_greeting == six.u(' Hello, Joe!')
+ assert six.u('(%s)') % lazy_greeting == six.u('(Hello, Joe!)')
greetings = [
support.LazyProxy(greeting, 'world'),
@@ -297,7 +298,7 @@ def test_lazy_proxy():
]
greetings.sort()
assert [str(g) for g in greetings] == [
- u"Hello, Joe!",
- u"Hello, universe!",
- u"Hello, world!",
+ six.u("Hello, Joe!"),
+ six.u("Hello, universe!"),
+ six.u("Hello, world!"),
]
--- a/tests/test_numbers.py
+++ b/tests/test_numbers.py
@@ -14,6 +14,7 @@
from decimal import Decimal
import unittest
import pytest
+import six
from babel import numbers
@@ -31,7 +32,7 @@ class FormatDecimalTestCase(unittest.Tes
# regression test for #183, fraction digits were not correctly cutted
# if the input was a float value and the value had more than 7
# significant digits
- self.assertEqual(u'12,345,678.05',
+ self.assertEqual(six.u('12,345,678.05'),
numbers.format_decimal(12345678.051, '#,##0.00',
locale='en_US'))
@@ -173,77 +174,77 @@ class NumberParsingTestCase(unittest.Tes
def test_get_currency_name():
- assert numbers.get_currency_name('USD', locale='en_US') == u'US Dollar'
- assert numbers.get_currency_name('USD', count=2, locale='en_US') == u'US dollars'
+ assert numbers.get_currency_name('USD', locale='en_US') == six.u('US Dollar')
+ assert numbers.get_currency_name('USD', count=2, locale='en_US') == six.u('US dollars')
def test_get_currency_symbol():
- assert numbers.get_currency_symbol('USD', 'en_US') == u'$'
+ assert numbers.get_currency_symbol('USD', 'en_US') == six.u('$')
def test_get_decimal_symbol():
- assert numbers.get_decimal_symbol('en_US') == u'.'
+ assert numbers.get_decimal_symbol('en_US') == six.u('.')
def test_get_plus_sign_symbol():
- assert numbers.get_plus_sign_symbol('en_US') == u'+'
+ assert numbers.get_plus_sign_symbol('en_US') == six.u('+')
def test_get_minus_sign_symbol():
- assert numbers.get_minus_sign_symbol('en_US') == u'-'
+ assert numbers.get_minus_sign_symbol('en_US') == six.u('-')
def test_get_exponential_symbol():
- assert numbers.get_exponential_symbol('en_US') == u'E'
+ assert numbers.get_exponential_symbol('en_US') == six.u('E')
def test_get_group_symbol():
- assert numbers.get_group_symbol('en_US') == u','
+ assert numbers.get_group_symbol('en_US') == six.u(',')
def test_format_number():
- assert numbers.format_number(1099, locale='en_US') == u'1,099'
- assert numbers.format_number(1099, locale='de_DE') == u'1.099'
+ assert numbers.format_number(1099, locale='en_US') == six.u('1,099')
+ assert numbers.format_number(1099, locale='de_DE') == six.u('1.099')
def test_format_decimal():
- assert numbers.format_decimal(1.2345, locale='en_US') == u'1.234'
- assert numbers.format_decimal(1.2346, locale='en_US') == u'1.235'
- assert numbers.format_decimal(-1.2346, locale='en_US') == u'-1.235'
- assert numbers.format_decimal(1.2345, locale='sv_SE') == u'1,234'
- assert numbers.format_decimal(1.2345, locale='de') == u'1,234'
- assert numbers.format_decimal(12345.5, locale='en_US') == u'12,345.5'
+ assert numbers.format_decimal(1.2345, locale='en_US') == six.u('1.234')
+ assert numbers.format_decimal(1.2346, locale='en_US') == six.u('1.235')
+ assert numbers.format_decimal(-1.2346, locale='en_US') == six.u('-1.235')
+ assert numbers.format_decimal(1.2345, locale='sv_SE') == six.u('1,234')
+ assert numbers.format_decimal(1.2345, locale='de') == six.u('1,234')
+ assert numbers.format_decimal(12345.5, locale='en_US') == six.u('12,345.5')
def test_format_currency():
assert (numbers.format_currency(1099.98, 'USD', locale='en_US')
- == u'$1,099.98')
+ == six.u('$1,099.98'))
assert (numbers.format_currency(1099.98, 'USD', locale='es_CO')
- == u'1.099,98\xa0US$')
+ == six.u('1.099,98\xa0US$'))
assert (numbers.format_currency(1099.98, 'EUR', locale='de_DE')
- == u'1.099,98\xa0\u20ac')
- assert (numbers.format_currency(1099.98, 'EUR', u'\xa4\xa4 #,##0.00',
+ == six.u('1.099,98\xa0\u20ac'))
+ assert (numbers.format_currency(1099.98, 'EUR', six.u('\xa4\xa4 #,##0.00'),
locale='en_US')
- == u'EUR 1,099.98')
+ == six.u('EUR 1,099.98'))
def test_format_percent():
- assert numbers.format_percent(0.34, locale='en_US') == u'34%'
- assert numbers.format_percent(25.1234, locale='en_US') == u'2,512%'
+ assert numbers.format_percent(0.34, locale='en_US') == six.u('34%')
+ assert numbers.format_percent(25.1234, locale='en_US') == six.u('2,512%')
assert (numbers.format_percent(25.1234, locale='sv_SE')
- == u'2\xa0512\xa0%')
- assert (numbers.format_percent(25.1234, u'#,##0\u2030', locale='en_US')
- == u'25,123\u2030')
+ == six.u('2\xa0512\xa0%'))
+ assert (numbers.format_percent(25.1234, six.u('#,##0\u2030'), locale='en_US')
+ == six.u('25,123\u2030'))
def test_scientific_exponent_displayed_as_integer():
- assert numbers.format_scientific(100000, locale='en_US') == u'1E5'
+ assert numbers.format_scientific(100000, locale='en_US') == six.u('1E5')
def test_format_scientific():
- assert numbers.format_scientific(10000, locale='en_US') == u'1E4'
- assert (numbers.format_scientific(1234567, u'##0E00', locale='en_US')
- == u'1.23E06')
+ assert numbers.format_scientific(10000, locale='en_US') == six.u('1E4')
+ assert (numbers.format_scientific(1234567, six.u('##0E00'), locale='en_US')
+ == six.u('1.23E06'))
def test_parse_number():
--- a/tests/test_dates.py
+++ b/tests/test_dates.py
@@ -15,6 +15,7 @@ import calendar
from datetime import date, datetime, time, timedelta
import types
import unittest
+import six
from pytz import timezone
@@ -36,14 +37,14 @@ class DateTimeFormatTestCase(unittest.Te
def test_month_context(self):
d = date(2006, 2, 8)
fmt = dates.DateTimeFormat(d, locale='cs_CZ')
- self.assertEqual(u'2', fmt['MMMMM']) # narrow format
+ self.assertEqual(six.u('2'), fmt['MMMMM']) # narrow format
fmt = dates.DateTimeFormat(d, locale='cs_CZ')
- self.assertEqual(u'ú', fmt['LLLLL']) # narrow standalone
+ self.assertEqual(six.u('\xfa'), fmt['LLLLL']) # narrow standalone
def test_abbreviated_month_alias(self):
d = date(2006, 3, 8)
fmt = dates.DateTimeFormat(d, locale='de_DE')
- self.assertEqual(u'Mär', fmt['LLL'])
+ self.assertEqual(six.u('M\xe4r'), fmt['LLL'])
def test_week_of_year_first(self):
d = date(2006, 1, 8)
@@ -209,7 +210,7 @@ class DateTimeFormatTestCase(unittest.Te
tz = timezone('Europe/Paris')
t = time(15, 30, tzinfo=tz)
fmt = dates.DateTimeFormat(t, locale='fr_FR')
- self.assertEqual(u'heure de l\u2019Europe centrale', fmt['vvvv'])
+ self.assertEqual(six.u('heure de l\u2019Europe centrale'), fmt['vvvv'])
def test_hour_formatting(self):
l = 'en_US'
@@ -248,7 +249,7 @@ class FormatDatetimeTestCase(unittest.Te
d = datetime(2012, 4, 1, 15, 30, 29, tzinfo=timezone('UTC'))
epoch = float(calendar.timegm(d.timetuple()))
formatted_string = dates.format_datetime(epoch, format='long', locale='en_US')
- self.assertEqual(u'April 1, 2012 at 3:30:29 PM +0000', formatted_string)
+ self.assertEqual(six.u('April 1, 2012 at 3:30:29 PM +0000'), formatted_string)
class FormatTimeTestCase(unittest.TestCase):
@@ -263,7 +264,7 @@ class FormatTimeTestCase(unittest.TestCa
d = datetime(2012, 4, 1, 15, 30, 29, tzinfo=timezone('UTC'))
epoch = float(calendar.timegm(d.timetuple()))
formatted_time = dates.format_time(epoch, format='long', locale='en_US')
- self.assertEqual(u'3:30:29 PM +0000', formatted_time)
+ self.assertEqual(six.u('3:30:29 PM +0000'), formatted_time)
def test_with_date_fields_in_pattern(self):
@@ -331,174 +332,174 @@ class TimeZoneAdjustTestCase(unittest.Te
def test_get_period_names():
- assert dates.get_period_names(locale='en_US')['am'] == u'AM'
+ assert dates.get_period_names(locale='en_US')['am'] == six.u('AM')
def test_get_day_names():
- assert dates.get_day_names('wide', locale='en_US')[1] == u'Tuesday'
- assert dates.get_day_names('abbreviated', locale='es')[1] == u'mar'
+ assert dates.get_day_names('wide', locale='en_US')[1] == six.u('Tuesday')
+ assert dates.get_day_names('abbreviated', locale='es')[1] == six.u('mar')
de = dates.get_day_names('narrow', context='stand-alone', locale='de_DE')
- assert de[1] == u'D'
+ assert de[1] == six.u('D')
def test_get_month_names():
- assert dates.get_month_names('wide', locale='en_US')[1] == u'January'
- assert dates.get_month_names('abbreviated', locale='es')[1] == u'ene'
+ assert dates.get_month_names('wide', locale='en_US')[1] == six.u('January')
+ assert dates.get_month_names('abbreviated', locale='es')[1] == six.u('ene')
de = dates.get_month_names('narrow', context='stand-alone', locale='de_DE')
- assert de[1] == u'J'
+ assert de[1] == six.u('J')
def test_get_quarter_names():
- assert dates.get_quarter_names('wide', locale='en_US')[1] == u'1st quarter'
- assert dates.get_quarter_names('abbreviated', locale='de_DE')[1] == u'Q1'
+ assert dates.get_quarter_names('wide', locale='en_US')[1] == six.u('1st quarter')
+ assert dates.get_quarter_names('abbreviated', locale='de_DE')[1] == six.u('Q1')
def test_get_era_names():
- assert dates.get_era_names('wide', locale='en_US')[1] == u'Anno Domini'
- assert dates.get_era_names('abbreviated', locale='de_DE')[1] == u'n. Chr.'
+ assert dates.get_era_names('wide', locale='en_US')[1] == six.u('Anno Domini')
+ assert dates.get_era_names('abbreviated', locale='de_DE')[1] == six.u('n. Chr.')
def test_get_date_format():
us = dates.get_date_format(locale='en_US')
- assert us.pattern == u'MMM d, y'
+ assert us.pattern == six.u('MMM d, y')
de = dates.get_date_format('full', locale='de_DE')
- assert de.pattern == u'EEEE, d. MMMM y'
+ assert de.pattern == six.u('EEEE, d. MMMM y')
def test_get_datetime_format():
- assert dates.get_datetime_format(locale='en_US') == u'{1}, {0}'
+ assert dates.get_datetime_format(locale='en_US') == six.u('{1}, {0}')
def test_get_time_format():
- assert dates.get_time_format(locale='en_US').pattern == u'h:mm:ss a'
+ assert dates.get_time_format(locale='en_US').pattern == six.u('h:mm:ss a')
assert (dates.get_time_format('full', locale='de_DE').pattern ==
- u'HH:mm:ss zzzz')
+ six.u('HH:mm:ss zzzz'))
def test_get_timezone_gmt():
dt = datetime(2007, 4, 1, 15, 30)
- assert dates.get_timezone_gmt(dt, locale='en') == u'GMT+00:00'
+ assert dates.get_timezone_gmt(dt, locale='en') == six.u('GMT+00:00')
tz = timezone('America/Los_Angeles')
dt = datetime(2007, 4, 1, 15, 30, tzinfo=tz)
- assert dates.get_timezone_gmt(dt, locale='en') == u'GMT-08:00'
- assert dates.get_timezone_gmt(dt, 'short', locale='en') == u'-0800'
+ assert dates.get_timezone_gmt(dt, locale='en') == six.u('GMT-08:00')
+ assert dates.get_timezone_gmt(dt, 'short', locale='en') == six.u('-0800')
- assert dates.get_timezone_gmt(dt, 'long', locale='fr_FR') == u'UTC-08:00'
+ assert dates.get_timezone_gmt(dt, 'long', locale='fr_FR') == six.u('UTC-08:00')
def test_get_timezone_location():
tz = timezone('America/St_Johns')
assert (dates.get_timezone_location(tz, locale='de_DE') ==
- u"Kanada (St. John's) Zeit")
+ six.u("Kanada (St. John's) Zeit"))
tz = timezone('America/Mexico_City')
assert (dates.get_timezone_location(tz, locale='de_DE') ==
- u'Mexiko (Mexiko-Stadt) Zeit')
+ six.u('Mexiko (Mexiko-Stadt) Zeit'))
tz = timezone('Europe/Berlin')
assert (dates.get_timezone_name(tz, locale='de_DE') ==
- u'Mitteleurop\xe4ische Zeit')
+ six.u('Mitteleurop\xe4ische Zeit'))
def test_get_timezone_name():
dt = time(15, 30, tzinfo=timezone('America/Los_Angeles'))
assert (dates.get_timezone_name(dt, locale='en_US') ==
- u'Pacific Standard Time')
- assert dates.get_timezone_name(dt, width='short', locale='en_US') == u'PST'
+ six.u('Pacific Standard Time'))
+ assert dates.get_timezone_name(dt, width='short', locale='en_US') == six.u('PST')
tz = timezone('America/Los_Angeles')
- assert dates.get_timezone_name(tz, locale='en_US') == u'Pacific Time'
- assert dates.get_timezone_name(tz, 'short', locale='en_US') == u'PT'
+ assert dates.get_timezone_name(tz, locale='en_US') == six.u('Pacific Time')
+ assert dates.get_timezone_name(tz, 'short', locale='en_US') == six.u('PT')
tz = timezone('Europe/Berlin')
assert (dates.get_timezone_name(tz, locale='de_DE') ==
- u'Mitteleurop\xe4ische Zeit')
+ six.u('Mitteleurop\xe4ische Zeit'))
assert (dates.get_timezone_name(tz, locale='pt_BR') ==
- u'Hor\xe1rio da Europa Central')
+ six.u('Hor\xe1rio da Europa Central'))
tz = timezone('America/St_Johns')
- assert dates.get_timezone_name(tz, locale='de_DE') == u'Neufundland-Zeit'
+ assert dates.get_timezone_name(tz, locale='de_DE') == six.u('Neufundland-Zeit')
tz = timezone('America/Los_Angeles')
assert dates.get_timezone_name(tz, locale='en', width='short',
- zone_variant='generic') == u'PT'
+ zone_variant='generic') == six.u('PT')
assert dates.get_timezone_name(tz, locale='en', width='short',
- zone_variant='standard') == u'PST'
+ zone_variant='standard') == six.u('PST')
assert dates.get_timezone_name(tz, locale='en', width='short',
- zone_variant='daylight') == u'PDT'
+ zone_variant='daylight') == six.u('PDT')
assert dates.get_timezone_name(tz, locale='en', width='long',
- zone_variant='generic') == u'Pacific Time'
+ zone_variant='generic') == six.u('Pacific Time')
assert dates.get_timezone_name(tz, locale='en', width='long',
- zone_variant='standard') == u'Pacific Standard Time'
+ zone_variant='standard') == six.u('Pacific Standard Time')
assert dates.get_timezone_name(tz, locale='en', width='long',
- zone_variant='daylight') == u'Pacific Daylight Time'
+ zone_variant='daylight') == six.u('Pacific Daylight Time')
def test_format_date():
d = date(2007, 4, 1)
- assert dates.format_date(d, locale='en_US') == u'Apr 1, 2007'
+ assert dates.format_date(d, locale='en_US') == six.u('Apr 1, 2007')
assert (dates.format_date(d, format='full', locale='de_DE') ==
- u'Sonntag, 1. April 2007')
+ six.u('Sonntag, 1. April 2007'))
assert (dates.format_date(d, "EEE, MMM d, ''yy", locale='en') ==
- u"Sun, Apr 1, '07")
+ six.u("Sun, Apr 1, '07"))
def test_format_datetime():
dt = datetime(2007, 4, 1, 15, 30)
assert (dates.format_datetime(dt, locale='en_US') ==
- u'Apr 1, 2007, 3:30:00 PM')
+ six.u('Apr 1, 2007, 3:30:00 PM'))
full = dates.format_datetime(dt, 'full', tzinfo=timezone('Europe/Paris'),
locale='fr_FR')
- assert full == (u'dimanche 1 avril 2007 17:30:00 heure '
- u'avanc\xe9e d\u2019Europe centrale')
+ assert full == (six.u('dimanche 1 avril 2007 17:30:00 heure '
+ 'avanc\xe9e d\u2019Europe centrale'))
custom = dates.format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz",
tzinfo=timezone('US/Eastern'), locale='en')
- assert custom == u'2007.04.01 AD at 11:30:00 EDT'
+ assert custom == six.u('2007.04.01 AD at 11:30:00 EDT')
def test_format_time():
t = time(15, 30)
- assert dates.format_time(t, locale='en_US') == u'3:30:00 PM'
- assert dates.format_time(t, format='short', locale='de_DE') == u'15:30'
+ assert dates.format_time(t, locale='en_US') == six.u('3:30:00 PM')
+ assert dates.format_time(t, format='short', locale='de_DE') == six.u('15:30')
assert (dates.format_time(t, "hh 'o''clock' a", locale='en') ==
- u"03 o'clock PM")
+ six.u("03 o'clock PM"))
t = datetime(2007, 4, 1, 15, 30)
tzinfo = timezone('Europe/Paris')
t = tzinfo.localize(t)
fr = dates.format_time(t, format='full', tzinfo=tzinfo, locale='fr_FR')
- assert fr == u'15:30:00 heure avanc\xe9e d\u2019Europe centrale'
+ assert fr == six.u('15:30:00 heure avanc\xe9e d\u2019Europe centrale')
custom = dates.format_time(t, "hh 'o''clock' a, zzzz",
tzinfo=timezone('US/Eastern'), locale='en')
- assert custom == u"09 o'clock AM, Eastern Daylight Time"
+ assert custom == six.u("09 o'clock AM, Eastern Daylight Time")
t = time(15, 30)
paris = dates.format_time(t, format='full',
tzinfo=timezone('Europe/Paris'), locale='fr_FR')
- assert paris == u'15:30:00 heure normale de l\u2019Europe centrale'
+ assert paris == six.u('15:30:00 heure normale de l\u2019Europe centrale')
us_east = dates.format_time(t, format='full',
tzinfo=timezone('US/Eastern'), locale='en_US')
- assert us_east == u'3:30:00 PM Eastern Standard Time'
+ assert us_east == six.u('3:30:00 PM Eastern Standard Time')
def test_format_timedelta():
assert (dates.format_timedelta(timedelta(weeks=12), locale='en_US')
- == u'3 months')
+ == six.u('3 months'))
assert (dates.format_timedelta(timedelta(seconds=1), locale='es')
- == u'1 segundo')
+ == six.u('1 segundo'))
assert (dates.format_timedelta(timedelta(hours=3), granularity='day',
locale='en_US')
- == u'1 day')
+ == six.u('1 day'))
assert (dates.format_timedelta(timedelta(hours=23), threshold=0.9,
locale='en_US')
- == u'1 day')
+ == six.u('1 day'))
assert (dates.format_timedelta(timedelta(hours=23), threshold=1.1,
locale='en_US')
- == u'23 hours')
+ == six.u('23 hours'))
def test_parse_date():
@@ -519,9 +520,9 @@ def test_datetime_format_get_week_number
def test_parse_pattern():
- assert dates.parse_pattern("MMMMd").format == u'%(MMMM)s%(d)s'
+ assert dates.parse_pattern("MMMMd").format == six.u('%(MMMM)s%(d)s')
assert (dates.parse_pattern("MMM d, yyyy").format ==
- u'%(MMM)s %(d)s, %(yyyy)s')
+ six.u('%(MMM)s %(d)s, %(yyyy)s'))
assert (dates.parse_pattern("H:mm' Uhr 'z").format ==
- u'%(H)s:%(mm)s Uhr %(z)s')
- assert dates.parse_pattern("hh' o''clock'").format == u"%(hh)s o'clock"
+ six.u('%(H)s:%(mm)s Uhr %(z)s'))
+ assert dates.parse_pattern("hh' o''clock'").format == six.u("%(hh)s o'clock")
--- a/tests/messages/test_extract.py
+++ b/tests/messages/test_extract.py
@@ -14,6 +14,7 @@
import codecs
import sys
import unittest
+import six
from babel.messages import extract
from babel._compat import BytesIO, StringIO
@@ -40,14 +41,14 @@ msg10 = dngettext(getDomain(), 'Page', '
self.assertEqual([
(1, '_', None, []),
(2, 'ungettext', (None, None, None), []),
- (3, 'ungettext', (u'Babel', None, None), []),
- (4, 'ungettext', (None, u'Babels', None), []),
- (5, 'ungettext', (u'bunny', u'bunnies', None), []),
- (6, 'ungettext', (None, u'bunnies', None), []),
+ (3, 'ungettext', (six.u('Babel'), None, None), []),
+ (4, 'ungettext', (None, six.u('Babels'), None), []),
+ (5, 'ungettext', (six.u('bunny'), six.u('bunnies'), None), []),
+ (6, 'ungettext', (None, six.u('bunnies'), None), []),
(7, '_', None, []),
- (8, 'gettext', u'Rabbit', []),
- (9, 'dgettext', (u'wiki', None), []),
- (10, 'dngettext', (None, u'Page', u'Pages', None), [])],
+ (8, 'gettext', six.u('Rabbit'), []),
+ (9, 'dgettext', (six.u('wiki'), None), []),
+ (10, 'dngettext', (None, six.u('Page'), six.u('Pages'), None), [])],
messages)
def test_nested_comments(self):
@@ -58,7 +59,7 @@ msg = ngettext('pylon', # TRANSLATORS:
""")
messages = list(extract.extract_python(buf, ('ngettext',),
['TRANSLATORS:'], {}))
- self.assertEqual([(1, 'ngettext', (u'pylon', u'pylons', None), [])],
+ self.assertEqual([(1, 'ngettext', (six.u('pylon'), six.u('pylons'), None), [])],
messages)
def test_comments_with_calls_that_spawn_multiple_lines(self):
@@ -83,21 +84,21 @@ add_notice(req, ngettext("Bar deleted.",
{'strip_comment_tags':False}))
self.assertEqual((6, '_', 'Locale deleted.',
- [u'NOTE: This Comment SHOULD Be Extracted']),
+ [six.u('NOTE: This Comment SHOULD Be Extracted')]),
messages[1])
- self.assertEqual((10, 'ngettext', (u'Foo deleted.', u'Foos deleted.',
+ self.assertEqual((10, 'ngettext', (six.u('Foo deleted.'), six.u('Foos deleted.'),
None),
- [u'NOTE: This Comment SHOULD Be Extracted']),
+ [six.u('NOTE: This Comment SHOULD Be Extracted')]),
messages[2])
self.assertEqual((3, 'ngettext',
- (u'Catalog deleted.',
- u'Catalogs deleted.', None),
- [u'NOTE: This Comment SHOULD Be Extracted']),
+ (six.u('Catalog deleted.'),
+ six.u('Catalogs deleted.'), None),
+ [six.u('NOTE: This Comment SHOULD Be Extracted')]),
messages[0])
- self.assertEqual((15, 'ngettext', (u'Bar deleted.', u'Bars deleted.',
+ self.assertEqual((15, 'ngettext', (six.u('Bar deleted.'), six.u('Bars deleted.'),
None),
- [u'NOTE: This Comment SHOULD Be Extracted',
- u'NOTE: And This One Too']),
+ [six.u('NOTE: This Comment SHOULD Be Extracted'),
+ six.u('NOTE: And This One Too')]),
messages[3])
def test_declarations(self):
@@ -114,9 +115,9 @@ class Meta:
messages = list(extract.extract_python(buf,
extract.DEFAULT_KEYWORDS.keys(),
[], {}))
- self.assertEqual([(3, '_', u'Page arg 1', []),
- (3, '_', u'Page arg 2', []),
- (8, '_', u'log entry', [])],
+ self.assertEqual([(3, '_', six.u('Page arg 1'), []),
+ (3, '_', six.u('Page arg 2'), []),
+ (8, '_', six.u('log entry'), [])],
messages)
def test_multiline(self):
@@ -128,8 +129,8 @@ msg2 = ngettext('elvis',
count)
""")
messages = list(extract.extract_python(buf, ('ngettext',), [], {}))
- self.assertEqual([(1, 'ngettext', (u'pylon', u'pylons', None), []),
- (3, 'ngettext', (u'elvis', u'elvises', None), [])],
+ self.assertEqual([(1, 'ngettext', (six.u('pylon'), six.u('pylons'), None), []),
+ (3, 'ngettext', (six.u('elvis'), six.u('elvises'), None), [])],
messages)
def test_triple_quoted_strings(self):
@@ -141,9 +142,9 @@ msg2 = ngettext(\"\"\"elvis\"\"\", 'elvi
messages = list(extract.extract_python(buf,
extract.DEFAULT_KEYWORDS.keys(),
[], {}))
- self.assertEqual([(1, '_', (u'pylons'), []),
- (2, 'ngettext', (u'elvis', u'elvises', None), []),
- (3, 'ngettext', (u'elvis', u'elvises', None), [])],
+ self.assertEqual([(1, '_', (six.u('pylons')), []),
+ (2, 'ngettext', (six.u('elvis'), six.u('elvises'), None), []),
+ (3, 'ngettext', (six.u('elvis'), six.u('elvises'), None), [])],
messages)
def test_multiline_strings(self):
@@ -157,9 +158,9 @@ gettext message catalog library.''')
[], {}))
self.assertEqual(
[(1, '_',
- u'This module provides internationalization and localization\n'
+ six.u('This module provides internationalization and localization\n'
'support for your Python programs by providing an interface to '
- 'the GNU\ngettext message catalog library.', [])],
+ 'the GNU\ngettext message catalog library.'), [])],
messages)
def test_concatenated_strings(self):
@@ -169,12 +170,12 @@ foobar = _('foo' 'bar')
messages = list(extract.extract_python(buf,
extract.DEFAULT_KEYWORDS.keys(),
[], {}))
- self.assertEqual(u'foobar', messages[0][2])
+ self.assertEqual(six.u('foobar'), messages[0][2])
def test_unicode_string_arg(self):
buf = BytesIO(b"msg = _(u'Foo Bar')")
messages = list(extract.extract_python(buf, ('_',), [], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
def test_comment_tag(self):
buf = BytesIO(b"""
@@ -182,8 +183,8 @@ foobar = _('foo' 'bar')
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
- self.assertEqual([u'NOTE: A translation comment'], messages[0][3])
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
+ self.assertEqual([six.u('NOTE: A translation comment')], messages[0][3])
def test_comment_tag_multiline(self):
buf = BytesIO(b"""
@@ -192,8 +193,8 @@ msg = _(u'Foo Bar')
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
- self.assertEqual([u'NOTE: A translation comment', u'with a second line'],
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
+ self.assertEqual([six.u('NOTE: A translation comment'), six.u('with a second line')],
messages[0][3])
def test_translator_comments_with_previous_non_translator_comments(self):
@@ -205,8 +206,8 @@ msg = _(u'Foo Bar')
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
- self.assertEqual([u'NOTE: A translation comment', u'with a second line'],
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
+ self.assertEqual([six.u('NOTE: A translation comment'), six.u('with a second line')],
messages[0][3])
def test_comment_tags_not_on_start_of_comment(self):
@@ -218,8 +219,8 @@ msg = _(u'Foo Bar')
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
- self.assertEqual([u'NOTE: This one will be'], messages[0][3])
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
+ self.assertEqual([six.u('NOTE: This one will be')], messages[0][3])
def test_multiple_comment_tags(self):
buf = BytesIO(b"""
@@ -232,11 +233,11 @@ msg = _(u'Foo Bar2')
""")
messages = list(extract.extract_python(buf, ('_',),
['NOTE1:', 'NOTE2:'], {}))
- self.assertEqual(u'Foo Bar1', messages[0][2])
- self.assertEqual([u'NOTE1: A translation comment for tag1',
- u'with a second line'], messages[0][3])
- self.assertEqual(u'Foo Bar2', messages[1][2])
- self.assertEqual([u'NOTE2: A translation comment for tag2'], messages[1][3])
+ self.assertEqual(six.u('Foo Bar1'), messages[0][2])
+ self.assertEqual([six.u('NOTE1: A translation comment for tag1'),
+ six.u('with a second line')], messages[0][3])
+ self.assertEqual(six.u('Foo Bar2'), messages[1][2])
+ self.assertEqual([six.u('NOTE2: A translation comment for tag2')], messages[1][3])
def test_two_succeeding_comments(self):
buf = BytesIO(b"""
@@ -245,8 +246,8 @@ msg = _(u'Foo Bar2')
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
- self.assertEqual([u'NOTE: one', u'NOTE: two'], messages[0][3])
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
+ self.assertEqual([six.u('NOTE: one'), six.u('NOTE: two')], messages[0][3])
def test_invalid_translator_comments(self):
buf = BytesIO(b"""
@@ -256,7 +257,7 @@ hello = 'there'
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
self.assertEqual([], messages[0][3])
def test_invalid_translator_comments2(self):
@@ -271,9 +272,9 @@ rows = [[v for v in range(0,10)] for row
hello = _('Hello')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Hi there!', messages[0][2])
- self.assertEqual([u'NOTE: Hi!'], messages[0][3])
- self.assertEqual(u'Hello', messages[1][2])
+ self.assertEqual(six.u('Hi there!'), messages[0][2])
+ self.assertEqual([six.u('NOTE: Hi!')], messages[0][3])
+ self.assertEqual(six.u('Hello'), messages[1][2])
self.assertEqual([], messages[1][3])
def test_invalid_translator_comments3(self):
@@ -284,7 +285,7 @@ hello = _('Hello')
hithere = _('Hi there!')
""")
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Hi there!', messages[0][2])
+ self.assertEqual(six.u('Hi there!'), messages[0][2])
self.assertEqual([], messages[0][3])
def test_comment_tag_with_leading_space(self):
@@ -294,8 +295,8 @@ hithere = _('Hi there!')
msg = _(u'Foo Bar')
""")
messages = list(extract.extract_python(buf, ('_',), [':'], {}))
- self.assertEqual(u'Foo Bar', messages[0][2])
- self.assertEqual([u': A translation comment', u': with leading spaces'],
+ self.assertEqual(six.u('Foo Bar'), messages[0][2])
+ self.assertEqual([six.u(': A translation comment'), six.u(': with leading spaces')],
messages[0][3])
def test_different_signatures(self):
@@ -308,48 +309,48 @@ n = ngettext()
n = ngettext('foo')
""")
messages = list(extract.extract_python(buf, ('_', 'ngettext'), [], {}))
- self.assertEqual((u'foo', u'bar'), messages[0][2])
- self.assertEqual((u'hello', u'there', None), messages[1][2])
- self.assertEqual((None, u'hello', u'there'), messages[2][2])
+ self.assertEqual((six.u('foo'), six.u('bar')), messages[0][2])
+ self.assertEqual((six.u('hello'), six.u('there'), None), messages[1][2])
+ self.assertEqual((None, six.u('hello'), six.u('there')), messages[2][2])
self.assertEqual((None, None), messages[3][2])
self.assertEqual(None, messages[4][2])
self.assertEqual(('foo'), messages[5][2])
def test_utf8_message(self):
- buf = BytesIO(u"""
+ buf = BytesIO(six.u("""
# NOTE: hello
msg = _('Bonjour à tous')
-""".encode('utf-8'))
+""").encode('utf-8'))
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'],
{'encoding': 'utf-8'}))
- self.assertEqual(u'Bonjour à tous', messages[0][2])
- self.assertEqual([u'NOTE: hello'], messages[0][3])
+ self.assertEqual(six.u('Bonjour à tous'), messages[0][2])
+ self.assertEqual([six.u('NOTE: hello')], messages[0][3])
def test_utf8_message_with_magic_comment(self):
- buf = BytesIO(u"""# -*- coding: utf-8 -*-
+ buf = BytesIO(six.u("""# -*- coding: utf-8 -*-
# NOTE: hello
msg = _('Bonjour à tous')
-""".encode('utf-8'))
+""").encode('utf-8'))
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Bonjour à tous', messages[0][2])
- self.assertEqual([u'NOTE: hello'], messages[0][3])
+ self.assertEqual(six.u('Bonjour à tous'), messages[0][2])
+ self.assertEqual([six.u('NOTE: hello')], messages[0][3])
def test_utf8_message_with_utf8_bom(self):
- buf = BytesIO(codecs.BOM_UTF8 + u"""
+ buf = BytesIO(codecs.BOM_UTF8 + six.u("""
# NOTE: hello
msg = _('Bonjour à tous')
-""".encode('utf-8'))
+""").encode('utf-8'))
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Bonjour à tous', messages[0][2])
- self.assertEqual([u'NOTE: hello'], messages[0][3])
+ self.assertEqual(six.u('Bonjour à tous'), messages[0][2])
+ self.assertEqual([six.u('NOTE: hello')], messages[0][3])
def test_utf8_raw_strings_match_unicode_strings(self):
- buf = BytesIO(codecs.BOM_UTF8 + u"""
+ buf = BytesIO(codecs.BOM_UTF8 + six.u("""
msg = _('Bonjour à tous')
msgu = _(u'Bonjour à tous')
-""".encode('utf-8'))
+""").encode('utf-8'))
messages = list(extract.extract_python(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Bonjour à tous', messages[0][2])
+ self.assertEqual(six.u('Bonjour à tous'), messages[0][2])
self.assertEqual(messages[0][2], messages[1][2])
def test_extract_strip_comment_tags(self):
@@ -363,12 +364,12 @@ _('Servus')
_('Babatschi')""")
messages = list(extract.extract('python', buf, comment_tags=['NOTE:', ':'],
strip_comment_tags=True))
- self.assertEqual(u'Servus', messages[0][1])
- self.assertEqual([u'This is a comment with a very simple',
- u'prefix specified'], messages[0][2])
- self.assertEqual(u'Babatschi', messages[1][1])
- self.assertEqual([u'This is a multiline comment with',
- u'a prefix too'], messages[1][2])
+ self.assertEqual(six.u('Servus'), messages[0][1])
+ self.assertEqual([six.u('This is a comment with a very simple'),
+ six.u('prefix specified')], messages[0][2])
+ self.assertEqual(six.u('Babatschi'), messages[1][1])
+ self.assertEqual([six.u('This is a multiline comment with'),
+ six.u('a prefix too')], messages[1][2])
class ExtractJavaScriptTestCase(unittest.TestCase):
@@ -403,29 +404,29 @@ msg10 = dngettext(domain, 'Page', 'Pages
messages = \
list(extract.extract('javascript', buf, extract.DEFAULT_KEYWORDS, [],
{}))
- self.assertEqual([(5, (u'bunny', u'bunnies'), [], None),
- (8, u'Rabbit', [], None),
- (10, (u'Page', u'Pages'), [], None)], messages)
+ self.assertEqual([(5, (six.u('bunny'), six.u('bunnies')), [], None),
+ (8, six.u('Rabbit'), [], None),
+ (10, (six.u('Page'), six.u('Pages')), [], None)], messages)
def test_message_with_line_comment(self):
- buf = BytesIO(u"""\
+ buf = BytesIO(six.u("""\
// NOTE: hello
msg = _('Bonjour à tous')
-""".encode('utf-8'))
+""").encode('utf-8'))
messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Bonjour à tous', messages[0][2])
- self.assertEqual([u'NOTE: hello'], messages[0][3])
+ self.assertEqual(six.u('Bonjour à tous'), messages[0][2])
+ self.assertEqual([six.u('NOTE: hello')], messages[0][3])
def test_message_with_multiline_comment(self):
- buf = BytesIO(u"""\
+ buf = BytesIO(six.u("""\
/* NOTE: hello
and bonjour
and servus */
msg = _('Bonjour à tous')
-""".encode('utf-8'))
+""").encode('utf-8'))
messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Bonjour à tous', messages[0][2])
- self.assertEqual([u'NOTE: hello', 'and bonjour', ' and servus'], messages[0][3])
+ self.assertEqual(six.u('Bonjour à tous'), messages[0][2])
+ self.assertEqual([six.u('NOTE: hello'), 'and bonjour', ' and servus'], messages[0][3])
def test_ignore_function_definitions(self):
buf = BytesIO(b"""\
@@ -454,11 +455,11 @@ bar()
_('no comment here')
""")
messages = list(extract.extract_javascript(buf, ('_',), ['NOTE:'], {}))
- self.assertEqual(u'Something', messages[0][2])
- self.assertEqual([u'NOTE: this will'], messages[0][3])
- self.assertEqual(u'Something else', messages[1][2])
- self.assertEqual([u'NOTE: this will show up', 'too.'], messages[1][3])
- self.assertEqual(u'no comment here', messages[2][2])
+ self.assertEqual(six.u('Something'), messages[0][2])
+ self.assertEqual([six.u('NOTE: this will')], messages[0][3])
+ self.assertEqual(six.u('Something else'), messages[1][2])
+ self.assertEqual([six.u('NOTE: this will show up'), 'too.'], messages[1][3])
+ self.assertEqual(six.u('no comment here'), messages[2][2])
self.assertEqual([], messages[2][3])
@@ -480,9 +481,9 @@ msg10 = dngettext(domain, 'Page', 'Pages
messages = \
list(extract.extract('python', buf, extract.DEFAULT_KEYWORDS, [],
{}))
- self.assertEqual([(5, (u'bunny', u'bunnies'), [], None),
- (8, u'Rabbit', [], None),
- (10, (u'Page', u'Pages'), [], None)], messages)
+ self.assertEqual([(5, (six.u('bunny'), six.u('bunnies')), [], None),
+ (8, six.u('Rabbit'), [], None),
+ (10, (six.u('Page'), six.u('Pages')), [], None)], messages)
def test_invalid_extract_method(self):
buf = BytesIO(b'')
@@ -501,8 +502,8 @@ n = ngettext('foo')
list(extract.extract('python', buf, extract.DEFAULT_KEYWORDS, [],
{}))
self.assertEqual(len(messages), 2)
- self.assertEqual(u'foo', messages[0][1])
- self.assertEqual((u'hello', u'there'), messages[1][1])
+ self.assertEqual(six.u('foo'), messages[0][1])
+ self.assertEqual((six.u('hello'), six.u('there')), messages[1][1])
def test_empty_string_msgid(self):
buf = BytesIO(b"""\
--- a/tests/messages/test_pofile.py
+++ b/tests/messages/test_pofile.py
@@ -13,6 +13,7 @@
from datetime import datetime
import unittest
+import six
from babel.core import Locale
from babel.messages.catalog import Catalog, Message
@@ -36,7 +37,7 @@ msgstr "Voh"''')
self.assertEqual('mydomain', catalog.domain)
def test_applies_specified_encoding_during_read(self):
- buf = BytesIO(u'''
+ buf = BytesIO(six.u('''
msgid ""
msgstr ""
"Project-Id-Version: 3.15\\n"
@@ -52,9 +53,9 @@ msgstr ""
"Generated-By: Babel 1.0dev-r313\\n"
msgid "foo"
-msgstr "bär"'''.encode('iso-8859-1'))
+msgstr "bär"''').encode('iso-8859-1'))
catalog = pofile.read_po(buf, locale='de_DE')
- self.assertEqual(u'bär', catalog.get('foo').string)
+ self.assertEqual(six.u('b\xe4r'), catalog.get('foo').string)
def test_read_multiline(self):
buf = StringIO(r'''msgid ""
@@ -121,15 +122,15 @@ msgstr ""
''')
catalog = pofile.read_po(buf)
self.assertEqual(1, len(list(catalog)))
- self.assertEqual(u'3.15', catalog.version)
- self.assertEqual(u'Fliegender Zirkus <fliegender@zirkus.de>',
+ self.assertEqual(six.u('3.15'), catalog.version)
+ self.assertEqual(six.u('Fliegender Zirkus <fliegender@zirkus.de>'),
catalog.msgid_bugs_address)
self.assertEqual(datetime(2007, 9, 27, 11, 19,
tzinfo=FixedOffsetTimezone(7 * 60)),
catalog.creation_date)
- self.assertEqual(u'John <cleese@bavaria.de>', catalog.last_translator)
- self.assertEqual(u'German Lang <de@babel.org>', catalog.language_team)
- self.assertEqual(u'iso-8859-2', catalog.charset)
+ self.assertEqual(six.u('John <cleese@bavaria.de>'), catalog.last_translator)
+ self.assertEqual(six.u('German Lang <de@babel.org>'), catalog.language_team)
+ self.assertEqual(six.u('iso-8859-2'), catalog.charset)
self.assertEqual(True, list(catalog)[0].fuzzy)
def test_obsolete_message(self):
@@ -145,9 +146,9 @@ msgstr "Bahr"
catalog = pofile.read_po(buf)
self.assertEqual(1, len(catalog))
self.assertEqual(1, len(catalog.obsolete))
- message = catalog.obsolete[u'foo']
- self.assertEqual(u'foo', message.id)
- self.assertEqual(u'Voh', message.string)
+ message = catalog.obsolete[six.u('foo')]
+ self.assertEqual(six.u('foo'), message.id)
+ self.assertEqual(six.u('Voh'), message.string)
self.assertEqual(['This is an obsolete message'], message.user_comments)
def test_obsolete_message_ignored(self):
@@ -243,7 +244,7 @@ msgstr[2] "Vohss"''')
self.assertEqual(3, catalog.num_plurals)
message = catalog['foo']
self.assertEqual(3, len(message.string))
- self.assertEqual(u'Vohss', message.string[2])
+ self.assertEqual(six.u('Vohss'), message.string[2])
def test_plural_with_square_brackets(self):
buf = StringIO(r'''msgid "foo"
@@ -261,8 +262,8 @@ class WritePoTestCase(unittest.TestCase)
def test_join_locations(self):
catalog = Catalog()
- catalog.add(u'foo', locations=[('main.py', 1)])
- catalog.add(u'foo', locations=[('utils.py', 3)])
+ catalog.add(six.u('foo'), locations=[('main.py', 1)])
+ catalog.add(six.u('foo'), locations=[('utils.py', 3)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#: main.py:1 utils.py:3
@@ -271,17 +272,17 @@ msgstr ""''', buf.getvalue().strip())
def test_write_po_file_with_specified_charset(self):
catalog = Catalog(charset='iso-8859-1')
- catalog.add('foo', u'äöü', locations=[('main.py', 1)])
+ catalog.add('foo', six.u('äöü'), locations=[('main.py', 1)])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=False)
po_file = buf.getvalue().strip()
assert b'"Content-Type: text/plain; charset=iso-8859-1\\n"' in po_file
- assert u'msgstr "äöü"'.encode('iso-8859-1') in po_file
+ assert six.u('msgstr "äöü"').encode('iso-8859-1') in po_file
def test_duplicate_comments(self):
catalog = Catalog()
- catalog.add(u'foo', auto_comments=['A comment'])
- catalog.add(u'foo', auto_comments=['A comment'])
+ catalog.add(six.u('foo'), auto_comments=['A comment'])
+ catalog.add(six.u('foo'), auto_comments=['A comment'])
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True)
self.assertEqual(b'''#. A comment
@@ -344,10 +345,10 @@ msgstr ""''', buf.getvalue().strip())
def test_wrap_locations_with_hyphens(self):
catalog = Catalog()
- catalog.add(u'foo', locations=[
+ catalog.add(six.u('foo'), locations=[
('doupy/templates/base/navmenu.inc.html.py', 60)
])
- catalog.add(u'foo', locations=[
+ catalog.add(six.u('foo'), locations=[
('doupy/templates/job-offers/helpers.html', 22)
])
buf = BytesIO()
@@ -390,9 +391,9 @@ msgstr ""
def test_pot_with_translator_comments(self):
catalog = Catalog()
- catalog.add(u'foo', locations=[('main.py', 1)],
+ catalog.add(six.u('foo'), locations=[('main.py', 1)],
auto_comments=['Comment About `foo`'])
- catalog.add(u'bar', locations=[('utils.py', 3)],
+ catalog.add(six.u('bar'), locations=[('utils.py', 3)],
user_comments=['Comment About `bar` with',
'multiple lines.'])
buf = BytesIO()
@@ -410,8 +411,8 @@ msgstr ""''', buf.getvalue().strip())
def test_po_with_obsolete_message(self):
catalog = Catalog()
- catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
- catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
+ catalog.add(six.u('foo'), six.u('Voh'), locations=[('main.py', 1)])
+ catalog.obsolete['bar'] = Message(six.u('bar'), six.u('Bahr'),
locations=[('utils.py', 3)],
user_comments=['User comment'])
buf = BytesIO()
@@ -426,7 +427,7 @@ msgstr "Voh"
def test_po_with_multiline_obsolete_message(self):
catalog = Catalog()
- catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
+ catalog.add(six.u('foo'), six.u('Voh'), locations=[('main.py', 1)])
msgid = r"""Here's a message that covers
multiple lines, and should still be handled
correctly.
@@ -454,8 +455,8 @@ msgstr "Voh"
def test_po_with_obsolete_message_ignored(self):
catalog = Catalog()
- catalog.add(u'foo', u'Voh', locations=[('main.py', 1)])
- catalog.obsolete['bar'] = Message(u'bar', u'Bahr',
+ catalog.add(six.u('foo'), six.u('Voh'), locations=[('main.py', 1)])
+ catalog.obsolete['bar'] = Message(six.u('bar'), six.u('Bahr'),
locations=[('utils.py', 3)],
user_comments=['User comment'])
buf = BytesIO()
@@ -466,8 +467,8 @@ msgstr "Voh"''', buf.getvalue().strip())
def test_po_with_previous_msgid(self):
catalog = Catalog()
- catalog.add(u'foo', u'Voh', locations=[('main.py', 1)],
- previous_id=u'fo')
+ catalog.add(six.u('foo'), six.u('Voh'), locations=[('main.py', 1)],
+ previous_id=six.u('fo'))
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
self.assertEqual(b'''#: main.py:1
@@ -477,8 +478,8 @@ msgstr "Voh"''', buf.getvalue().strip())
def test_po_with_previous_msgid_plural(self):
catalog = Catalog()
- catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
- locations=[('main.py', 1)], previous_id=(u'fo', u'fos'))
+ catalog.add((six.u('foo'), six.u('foos')), (six.u('Voh'), six.u('Voeh')),
+ locations=[('main.py', 1)], previous_id=(six.u('fo'), six.u('fos')))
buf = BytesIO()
pofile.write_po(buf, catalog, omit_header=True, include_previous=True)
self.assertEqual(b'''#: main.py:1
@@ -491,10 +492,10 @@ msgstr[1] "Voeh"''', buf.getvalue().stri
def test_sorted_po(self):
catalog = Catalog()
- catalog.add(u'bar', locations=[('utils.py', 3)],
+ catalog.add(six.u('bar'), locations=[('utils.py', 3)],
user_comments=['Comment About `bar` with',
'multiple lines.'])
- catalog.add((u'foo', u'foos'), (u'Voh', u'Voeh'),
+ catalog.add((six.u('foo'), six.u('foos')), (six.u('Voh'), six.u('Voeh')),
locations=[('main.py', 1)])
buf = BytesIO()
pofile.write_po(buf, catalog, sort_output=True)
@@ -530,8 +531,8 @@ msgstr ""''')
class PofileFunctionsTestCase(unittest.TestCase):
def test_unescape(self):
- escaped = u'"Say:\\n \\"hello, world!\\"\\n"'
- unescaped = u'Say:\n "hello, world!"\n'
+ escaped = six.u('"Say:\\n \\"hello, world!\\"\\n"')
+ unescaped = six.u('Say:\n "hello, world!"\n')
self.assertNotEqual(unescaped, escaped)
self.assertEqual(unescaped, pofile.unescape(escaped))
@@ -543,7 +544,7 @@ class PofileFunctionsTestCase(unittest.T
# handle irregular multi-line msgstr (no "" as first line)
# gracefully (#171)
msgstr = '"multi-line\\n"\n" translation"'
- expected_denormalized = u'multi-line\n translation'
+ expected_denormalized = six.u('multi-line\n translation')
self.assertEqual(expected_denormalized, pofile.denormalize(msgstr))
self.assertEqual(expected_denormalized,
--- a/tests/messages/test_jslexer.py
+++ b/tests/messages/test_jslexer.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
+import six
+
from babel.messages import jslexer
def test_unquote():
assert jslexer.unquote_string('""') == ''
- assert jslexer.unquote_string(r'"h\u00ebllo"') == u"hëllo"
+ assert jslexer.unquote_string(r'"h\u00ebllo"') == six.u("h\u00ebllo")
--- a/tests/messages/test_catalog.py
+++ b/tests/messages/test_catalog.py
@@ -14,6 +14,7 @@
import copy
import datetime
import unittest
+import six
from babel.dates import format_datetime, UTC
from babel.messages import catalog
@@ -91,35 +92,35 @@ class CatalogTestCase(unittest.TestCase)
def test_update_message_changed_to_plural(self):
cat = catalog.Catalog()
- cat.add(u'foo', u'Voh')
+ cat.add(six.u('foo'), six.u('Voh'))
tmpl = catalog.Catalog()
- tmpl.add((u'foo', u'foos'))
+ tmpl.add((six.u('foo'), six.u('foos')))
cat.update(tmpl)
- self.assertEqual((u'Voh', ''), cat['foo'].string)
+ self.assertEqual((six.u('Voh'), ''), cat['foo'].string)
assert cat['foo'].fuzzy
def test_update_message_changed_to_simple(self):
cat = catalog.Catalog()
- cat.add((u'foo' u'foos'), (u'Voh', u'Vöhs'))
+ cat.add((six.u('foo' 'foos')), (six.u('Voh'), six.u('Vöhs')))
tmpl = catalog.Catalog()
- tmpl.add(u'foo')
+ tmpl.add(six.u('foo'))
cat.update(tmpl)
- self.assertEqual(u'Voh', cat['foo'].string)
+ self.assertEqual(six.u('Voh'), cat['foo'].string)
assert cat['foo'].fuzzy
def test_update_message_updates_comments(self):
cat = catalog.Catalog()
- cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 5)])
- self.assertEqual(cat[u'foo'].auto_comments, [])
- self.assertEqual(cat[u'foo'].user_comments, [])
- # Update cat[u'foo'] with a new location and a comment
- cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 7)],
+ cat[six.u('foo')] = catalog.Message('foo', locations=[('main.py', 5)])
+ self.assertEqual(cat[six.u('foo')].auto_comments, [])
+ self.assertEqual(cat[six.u('foo')].user_comments, [])
+ # Update cat[six.u('foo')] with a new location and a comment
+ cat[six.u('foo')] = catalog.Message('foo', locations=[('main.py', 7)],
user_comments=['Foo Bar comment 1'])
- self.assertEqual(cat[u'foo'].user_comments, ['Foo Bar comment 1'])
+ self.assertEqual(cat[six.u('foo')].user_comments, ['Foo Bar comment 1'])
# now add yet another location with another comment
- cat[u'foo'] = catalog.Message('foo', locations=[('main.py', 9)],
+ cat[six.u('foo')] = catalog.Message('foo', locations=[('main.py', 9)],
auto_comments=['Foo Bar comment 2'])
- self.assertEqual(cat[u'foo'].auto_comments, ['Foo Bar comment 2'])
+ self.assertEqual(cat[six.u('foo')].auto_comments, ['Foo Bar comment 2'])
def test_update_fuzzy_matching_with_case_change(self):
cat = catalog.Catalog()
@@ -409,21 +410,21 @@ def test_catalog_plural_forms():
def test_catalog_setitem():
cat = catalog.Catalog()
- cat[u'foo'] = catalog.Message(u'foo')
- assert cat[u'foo'].id == 'foo'
+ cat[six.u('foo')] = catalog.Message(six.u('foo'))
+ assert cat[six.u('foo')].id == 'foo'
cat = catalog.Catalog()
- cat[u'foo'] = catalog.Message(u'foo', locations=[('main.py', 1)])
- assert cat[u'foo'].locations == [('main.py', 1)]
- cat[u'foo'] = catalog.Message(u'foo', locations=[('utils.py', 5)])
- assert cat[u'foo'].locations == [('main.py', 1), ('utils.py', 5)]
+ cat[six.u('foo')] = catalog.Message(six.u('foo'), locations=[('main.py', 1)])
+ assert cat[six.u('foo')].locations == [('main.py', 1)]
+ cat[six.u('foo')] = catalog.Message(six.u('foo'), locations=[('utils.py', 5)])
+ assert cat[six.u('foo')].locations == [('main.py', 1), ('utils.py', 5)]
def test_catalog_add():
cat = catalog.Catalog()
- foo = cat.add(u'foo')
+ foo = cat.add(six.u('foo'))
assert foo.id == 'foo'
- assert cat[u'foo'] is foo
+ assert cat[six.u('foo')] is foo
def test_catalog_update():
@@ -432,9 +433,9 @@ def test_catalog_update():
template.add('blue', locations=[('main.py', 100)])
template.add(('salad', 'salads'), locations=[('util.py', 42)])
cat = catalog.Catalog(locale='de_DE')
- cat.add('blue', u'blau', locations=[('main.py', 98)])
- cat.add('head', u'Kopf', locations=[('util.py', 33)])
- cat.add(('salad', 'salads'), (u'Salat', u'Salate'),
+ cat.add('blue', six.u('blau'), locations=[('main.py', 98)])
+ cat.add('head', six.u('Kopf'), locations=[('util.py', 33)])
+ cat.add(('salad', 'salads'), (six.u('Salat'), six.u('Salate')),
locations=[('util.py', 38)])
cat.update(template)
@@ -445,11 +446,11 @@ def test_catalog_update():
assert msg1.locations == [('main.py', 99)]
msg2 = cat['blue']
- assert msg2.string == u'blau'
+ assert msg2.string == six.u('blau')
assert msg2.locations == [('main.py', 100)]
msg3 = cat['salad']
- assert msg3.string == (u'Salat', u'Salate')
+ assert msg3.string == (six.u('Salat'), six.u('Salate'))
assert msg3.locations == [('util.py', 42)]
assert not 'head' in cat
--- a/tests/messages/test_mofile.py
+++ b/tests/messages/test_mofile.py
@@ -13,6 +13,7 @@
import os
import unittest
+import six
from babel.messages import mofile, Catalog
from babel._compat import BytesIO, text_type
@@ -47,26 +48,26 @@ class WriteMoTestCase(unittest.TestCase)
# can be applied to all subsequent messages by GNUTranslations
# (ensuring all messages are safely converted to unicode)
catalog = Catalog(locale='en_US')
- catalog.add(u'', '''\
+ catalog.add(six.u(''), '''\
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n''')
- catalog.add(u'foo', 'Voh')
- catalog.add((u'There is', u'There are'), (u'Es gibt', u'Es gibt'))
- catalog.add(u'Fizz', '')
+ catalog.add(six.u('foo'), 'Voh')
+ catalog.add((six.u('There is'), six.u('There are')), (six.u('Es gibt'), six.u('Es gibt')))
+ catalog.add(six.u('Fizz'), '')
catalog.add(('Fuzz', 'Fuzzes'), ('', ''))
buf = BytesIO()
mofile.write_mo(buf, catalog)
buf.seek(0)
translations = Translations(fp=buf)
- self.assertEqual(u'Voh', translations.ugettext('foo'))
+ self.assertEqual(six.u('Voh'), translations.ugettext('foo'))
assert isinstance(translations.ugettext('foo'), text_type)
- self.assertEqual(u'Es gibt', translations.ungettext('There is', 'There are', 1))
+ self.assertEqual(six.u('Es gibt'), translations.ungettext('There is', 'There are', 1))
assert isinstance(translations.ungettext('There is', 'There are', 1), text_type)
- self.assertEqual(u'Fizz', translations.ugettext('Fizz'))
+ self.assertEqual(six.u('Fizz'), translations.ugettext('Fizz'))
assert isinstance(translations.ugettext('Fizz'), text_type)
- self.assertEqual(u'Fuzz', translations.ugettext('Fuzz'))
+ self.assertEqual(six.u('Fuzz'), translations.ugettext('Fuzz'))
assert isinstance(translations.ugettext('Fuzz'), text_type)
- self.assertEqual(u'Fuzzes', translations.ugettext('Fuzzes'))
+ self.assertEqual(six.u('Fuzzes'), translations.ugettext('Fuzzes'))
assert isinstance(translations.ugettext('Fuzzes'), text_type)
def test_more_plural_forms(self):
--- a/tests/messages/test_checkers.py
+++ b/tests/messages/test_checkers.py
@@ -14,6 +14,7 @@
from datetime import datetime
import time
import unittest
+import six
from babel import __version__ as VERSION
from babel.core import Locale, UnknownLocaleError
@@ -35,7 +36,7 @@ class CheckersTestCase(unittest.TestCase
except UnknownLocaleError:
# Just an alias? Not what we're testing here, let's continue
continue
- po_file = (u"""\
+ po_file = (six.u("""\
# %(english_name)s translations for TestProject.
# Copyright (C) 2007 FooBar, Inc.
# This file is distributed under the same license as the TestProject
@@ -67,7 +68,7 @@ msgid "foobar"
msgid_plural "foobars"
msgstr[0] ""
-""" % dict(locale = _locale,
+""") % dict(locale = _locale,
english_name = locale.english_name,
version = VERSION,
year = time.strftime('%Y'),
@@ -102,7 +103,7 @@ msgstr[0] ""
except UnknownLocaleError:
# Just an alias? Not what we're testing here, let's continue
continue
- po_file = (u"""\
+ po_file = (six.u("""\
# %(english_name)s translations for TestProject.
# Copyright (C) 2007 FooBar, Inc.
# This file is distributed under the same license as the TestProject
@@ -136,7 +137,7 @@ msgstr[0] ""
msgstr[1] ""
msgstr[2] ""
-""" % dict(locale = _locale,
+""") % dict(locale = _locale,
english_name = locale.english_name,
version = VERSION,
year = time.strftime('%Y'),
--- a/babel/numbers.py
+++ b/babel/numbers.py
@@ -21,6 +21,7 @@
from decimal import Decimal, InvalidOperation
import math
import re
+import six
from babel.core import default_locale, Locale
from babel._compat import range_type
@@ -71,7 +72,7 @@ def get_decimal_symbol(locale=LC_NUMERIC
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('decimal', u'.')
+ return Locale.parse(locale).number_symbols.get('decimal', six.u('.'))
def get_plus_sign_symbol(locale=LC_NUMERIC):
@@ -82,7 +83,7 @@ def get_plus_sign_symbol(locale=LC_NUMER
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('plusSign', u'+')
+ return Locale.parse(locale).number_symbols.get('plusSign', six.u('+'))
def get_minus_sign_symbol(locale=LC_NUMERIC):
@@ -93,7 +94,7 @@ def get_minus_sign_symbol(locale=LC_NUME
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('minusSign', u'-')
+ return Locale.parse(locale).number_symbols.get('minusSign', six.u('-'))
def get_exponential_symbol(locale=LC_NUMERIC):
@@ -104,7 +105,7 @@ def get_exponential_symbol(locale=LC_NUM
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('exponential', u'E')
+ return Locale.parse(locale).number_symbols.get('exponential', six.u('E'))
def get_group_symbol(locale=LC_NUMERIC):
@@ -115,11 +116,11 @@ def get_group_symbol(locale=LC_NUMERIC):
:param locale: the `Locale` object or locale identifier
"""
- return Locale.parse(locale).number_symbols.get('group', u',')
+ return Locale.parse(locale).number_symbols.get('group', six.u(','))
def format_number(number, locale=LC_NUMERIC):
- u"""Return the given number formatted for a specific locale.
+ six.u("""Return the given number formatted for a specific locale.
>>> format_number(1099, locale='en_US')
u'1,099'
@@ -129,13 +130,13 @@ def format_number(number, locale=LC_NUME
:param number: the number to format
:param locale: the `Locale` object or locale identifier
- """
+ """)
# Do we really need this one?
return format_decimal(number, locale=locale)
def format_decimal(number, format=None, locale=LC_NUMERIC):
- u"""Return the given decimal number formatted for a specific locale.
+ six.u("""Return the given decimal number formatted for a specific locale.
>>> format_decimal(1.2345, locale='en_US')
u'1.234'
@@ -157,7 +158,7 @@ def format_decimal(number, format=None,
:param number: the number to format
:param format:
:param locale: the `Locale` object or locale identifier
- """
+ """)
locale = Locale.parse(locale)
if not format:
format = locale.decimal_formats.get(format)
@@ -166,7 +167,7 @@ def format_decimal(number, format=None,
def format_currency(number, currency, format=None, locale=LC_NUMERIC):
- u"""Return formatted currency value.
+ six.u("""Return formatted currency value.
>>> format_currency(1099.98, 'USD', locale='en_US')
u'$1,099.98'
@@ -188,7 +189,7 @@ def format_currency(number, currency, fo
:param number: the number to format
:param currency: the currency code
:param locale: the `Locale` object or locale identifier
- """
+ """)
locale = Locale.parse(locale)
if not format:
format = locale.currency_formats.get(format)
@@ -503,7 +504,7 @@ class NumberPattern(object):
self.exp_plus = exp_plus
if '%' in ''.join(self.prefix + self.suffix):
self.scale = 100
- elif u'‰' in ''.join(self.prefix + self.suffix):
+ elif six.u('\u2030') in ''.join(self.prefix + self.suffix):
self.scale = 1000
else:
self.scale = 1
@@ -540,7 +541,7 @@ class NumberPattern(object):
elif self.exp_plus:
exp_sign = get_plus_sign_symbol(locale)
exp = abs(exp)
- number = u'%s%s%s%s' % \
+ number = six.u('%s%s%s%s') % \
(self._format_sigdig(value, self.frac_prec[0],
self.frac_prec[1]),
get_exponential_symbol(locale), exp_sign,
@@ -566,13 +567,13 @@ class NumberPattern(object):
self.int_prec[1], locale)
b = self._format_frac(b, locale)
number = a + b
- retval = u'%s%s%s' % (self.prefix[is_negative], number,
+ retval = six.u('%s%s%s') % (self.prefix[is_negative], number,
self.suffix[is_negative])
- if u'¤' in retval:
- retval = retval.replace(u'¤¤¤',
+ if six.u('\xa4') in retval:
+ retval = retval.replace(six.u('\xa4\xa4\xa4'),
get_currency_name(currency, value, locale))
- retval = retval.replace(u'¤¤', currency.upper())
- retval = retval.replace(u'¤', get_currency_symbol(currency, locale))
+ retval = retval.replace(six.u('\xa4\xa4'), currency.upper())
+ retval = retval.replace(six.u('\xa4'), get_currency_symbol(currency, locale))
return retval
def _format_sigdig(self, value, min, max):
--- a/babel/dates.py
+++ b/babel/dates.py
@@ -20,6 +20,7 @@ from __future__ import division
import re
import pytz as _pytz
+import six
from datetime import date, datetime, time, timedelta
from bisect import bisect_right
@@ -312,7 +313,7 @@ def get_timezone_gmt(datetime=None, widt
seconds = offset.days * 24 * 60 * 60 + offset.seconds
hours, seconds = divmod(seconds, 3600)
if width == 'short':
- pattern = u'%+03d%02d'
+ pattern = six.u('%+03d%02d')
else:
pattern = locale.zone_formats['gmt'] % '%+03d:%02d'
return pattern % (hours, seconds // 60)
@@ -785,10 +786,10 @@ def format_timedelta(delta, granularity=
break
# This really should not happen
if pattern is None:
- return u''
+ return six.u('')
return pattern.replace('{0}', str(value))
- return u''
+ return six.u('')
def parse_date(string, locale=LC_TIME):
@@ -1178,4 +1179,4 @@ def parse_pattern(pattern):
elif charbuf:
append_chars()
- return DateTimePattern(pattern, u''.join(result).replace('\0', "'"))
+ return DateTimePattern(pattern, six.u('').join(result).replace('\0', "'"))
--- a/babel/core.py
+++ b/babel/core.py
@@ -10,6 +10,7 @@
"""
import os
+import six
from babel import localedata
from babel._compat import pickle, string_types
@@ -368,7 +369,7 @@ class Locale(object):
details.append(locale.variants.get(self.variant))
details = filter(None, details)
if details:
- retval += ' (%s)' % u', '.join(details)
+ retval += ' (%s)' % six.u(', ').join(details)
return retval
display_name = property(get_display_name, doc="""\
--- a/babel/messages/pofile.py
+++ b/babel/messages/pofile.py
@@ -12,6 +12,7 @@
import os
import re
+import six
from babel.messages.catalog import Catalog, Message
from babel.util import wraptext
@@ -195,9 +196,9 @@ def read_po(fileobj, locale=None, domain
context.append(line[7:].lstrip())
elif line.startswith('"'):
if in_msgid[0]:
- messages[-1] += u'\n' + line.rstrip()
+ messages[-1] += six.u('\n') + line.rstrip()
elif in_msgstr[0]:
- translations[-1][1] += u'\n' + line.rstrip()
+ translations[-1][1] += six.u('\n') + line.rstrip()
elif in_msgctxt[0]:
context.append(line.rstrip())
@@ -241,8 +242,8 @@ def read_po(fileobj, locale=None, domain
# No actual messages found, but there was some info in comments, from which
# we'll construct an empty header message
elif not counter[0] and (flags or user_comments or auto_comments):
- messages.append(u'')
- translations.append([0, u''])
+ messages.append(six.u(''))
+ translations.append([0, six.u('')])
_add_message()
return catalog
@@ -318,7 +319,7 @@ def normalize(string, prefix='', width=7
# separate line
buf.append(chunks.pop())
break
- lines.append(u''.join(buf))
+ lines.append(six.u('').join(buf))
else:
lines.append(line)
else:
@@ -331,7 +332,7 @@ def normalize(string, prefix='', width=7
if lines and not lines[-1]:
del lines[-1]
lines[-1] += '\n'
- return u'""\n' + u'\n'.join([(prefix + escape(l)) for l in lines])
+ return six.u('""\n') + six.u('\n').join([(prefix + escape(l)) for l in lines])
def write_po(fileobj, catalog, width=76, no_location=False, omit_header=False,
@@ -440,8 +441,8 @@ def write_po(fileobj, catalog, width=76,
for line in comment_header.splitlines():
lines += wraptext(line, width=width,
subsequent_indent='# ')
- comment_header = u'\n'.join(lines)
- _write(comment_header + u'\n')
+ comment_header = six.u('\n').join(lines)
+ _write(comment_header + six.u('\n'))
for comment in message.user_comments:
_write_comment(comment)
@@ -449,7 +450,7 @@ def write_po(fileobj, catalog, width=76,
_write_comment(comment, prefix='.')
if not no_location:
- locs = u' '.join([u'%s:%d' % (filename.replace(os.sep, '/'), lineno)
+ locs = six.u(' ').join([six.u('%s:%d') % (filename.replace(os.sep, '/'), lineno)
for filename, lineno in message.locations])
_write_comment(locs, prefix=':')
if message.flags:
--- a/babel/messages/jslexer.py
+++ b/babel/messages/jslexer.py
@@ -10,6 +10,7 @@
:license: BSD, see LICENSE for more details.
"""
+import six
from operator import itemgetter
import re
from babel._compat import unichr
@@ -124,7 +125,7 @@ def unquote_string(string):
if pos < len(string):
add(string[pos:])
- return u''.join(result)
+ return six.u('').join(result)
def tokenize(source):
--- a/babel/messages/mofile.py
+++ b/babel/messages/mofile.py
@@ -11,6 +11,7 @@
import array
import struct
+import six
from babel.messages.catalog import Catalog, Message
from babel._compat import range_type
@@ -115,7 +116,7 @@ def write_mo(fileobj, catalog, use_fuzzy
>>> catalog = Catalog(locale='en_US')
>>> catalog.add('foo', 'Voh')
<Message ...>
- >>> catalog.add((u'bar', u'baz'), (u'Bahr', u'Batz'))
+ >>> catalog.add((six.u('bar'), six.u('baz')), (six.u('Bahr'), six.u('Batz')))
<Message ...>
>>> catalog.add('fuz', 'Futz', flags=['fuzzy'])
<Message ...>
--- a/babel/messages/catalog.py
+++ b/babel/messages/catalog.py
@@ -11,6 +11,7 @@
import re
import time
+import six
from cgi import parse_header
from datetime import datetime, time as time_
@@ -43,7 +44,7 @@ PYTHON_FORMAT = re.compile(r'''(?x)
class Message(object):
"""Representation of a single message in a catalog."""
- def __init__(self, id, string=u'', locations=(), flags=(), auto_comments=(),
+ def __init__(self, id, string=six.u(''), locations=(), flags=(), auto_comments=(),
user_comments=(), previous_id=(), lineno=None, context=None):
"""Create the message object.
@@ -63,7 +64,7 @@ class Message(object):
"""
self.id = id #: The message ID
if not string and self.pluralizable:
- string = (u'', u'')
+ string = (six.u(''), six.u(''))
self.string = string #: The message translation
self.locations = list(distinct(locations))
self.flags = set(flags)
@@ -191,12 +192,12 @@ class TranslationError(Exception):
translations are encountered."""
-DEFAULT_HEADER = u"""\
+DEFAULT_HEADER = six.u("""\
# Translations template for PROJECT.
# Copyright (C) YEAR ORGANIZATION
# This file is distributed under the same license as the PROJECT project.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
-#"""
+#""")
if PY2:
@@ -362,7 +363,7 @@ class Catalog(object):
name = name.lower()
if name == 'project-id-version':
parts = value.split(' ')
- self.project = u' '.join(parts[:-1])
+ self.project = six.u(' ').join(parts[:-1])
self.version = parts[-1]
elif name == 'report-msgid-bugs-to':
self.msgid_bugs_address = value
@@ -554,7 +555,7 @@ class Catalog(object):
flags = set()
if self.fuzzy:
flags |= set(['fuzzy'])
- yield Message(u'', '\n'.join(buf), flags=flags)
+ yield Message(six.u(''), '\n'.join(buf), flags=flags)
for key in self._messages:
yield self._messages[key]
@@ -579,19 +580,19 @@ class Catalog(object):
"""Add or update the message with the specified ID.
>>> catalog = Catalog()
- >>> catalog[u'foo'] = Message(u'foo')
- >>> catalog[u'foo']
+ >>> catalog[six.u('foo')] = Message(six.u('foo'))
+ >>> catalog[six.u('foo')]
<Message u'foo' (flags: [])>
If a message with that ID is already in the catalog, it is updated
to include the locations and flags of the new message.
>>> catalog = Catalog()
- >>> catalog[u'foo'] = Message(u'foo', locations=[('main.py', 1)])
- >>> catalog[u'foo'].locations
+ >>> catalog[six.u('foo')] = Message(six.u('foo'), locations=[('main.py', 1)])
+ >>> catalog[six.u('foo')].locations
[('main.py', 1)]
- >>> catalog[u'foo'] = Message(u'foo', locations=[('utils.py', 5)])
- >>> catalog[u'foo'].locations
+ >>> catalog[six.u('foo')] = Message(six.u('foo'), locations=[('utils.py', 5)])
+ >>> catalog[six.u('foo')].locations
[('main.py', 1), ('utils.py', 5)]
:param id: the message ID
@@ -630,9 +631,9 @@ class Catalog(object):
"""Add or update the message with the specified ID.
>>> catalog = Catalog()
- >>> catalog.add(u'foo')
+ >>> catalog.add(six.u('foo'))
<Message ...>
- >>> catalog[u'foo']
+ >>> catalog[six.u('foo')]
<Message u'foo' (flags: [])>
This method simply constructs a `Message` object with the given
@@ -702,11 +703,11 @@ class Catalog(object):
>>> template.add(('salad', 'salads'), locations=[('util.py', 42)])
<Message ...>
>>> catalog = Catalog(locale='de_DE')
- >>> catalog.add('blue', u'blau', locations=[('main.py', 98)])
+ >>> catalog.add('blue', six.u('blau'), locations=[('main.py', 98)])
<Message ...>
- >>> catalog.add('head', u'Kopf', locations=[('util.py', 33)])
+ >>> catalog.add('head', six.u('Kopf'), locations=[('util.py', 33)])
<Message ...>
- >>> catalog.add(('salad', 'salads'), (u'Salat', u'Salate'),
+ >>> catalog.add(('salad', 'salads'), (six.u('Salat'), six.u('Salate')),
... locations=[('util.py', 38)])
<Message ...>
@@ -774,7 +775,7 @@ class Catalog(object):
if not isinstance(message.string, (list, tuple)):
fuzzy = True
message.string = tuple(
- [message.string] + ([u''] * (len(message.id) - 1))
+ [message.string] + ([six.u('')] * (len(message.id) - 1))
)
elif len(message.string) != self.num_plurals:
fuzzy = True
@@ -784,7 +785,7 @@ class Catalog(object):
message.string = message.string[0]
message.flags |= oldmsg.flags
if fuzzy:
- message.flags |= set([u'fuzzy'])
+ message.flags |= set([six.u('fuzzy')])
self[message.id] = message
for message in template:
--- a/babel/messages/frontend.py
+++ b/babel/messages/frontend.py
@@ -25,6 +25,7 @@ import re
import shutil
import sys
import tempfile
+import six
from babel import __version__ as VERSION
from babel import Locale, localedata
@@ -645,7 +646,7 @@ class CommandLineInterface(object):
identifiers = localedata.locale_identifiers()
longest = max([len(identifier) for identifier in identifiers])
identifiers.sort()
- format = u'%%-%ds %%s' % (longest + 1)
+ format = six.u('%%-%ds %%s') % (longest + 1)
for identifier in identifiers:
locale = Locale.parse(identifier)
output = format % (identifier, locale.english_name)
|