19
19
20
20
from codecs import BOM_UTF8 , BOM_UTF16 , BOM_UTF16_BE , BOM_UTF16_LE
21
21
22
- import six
23
22
from ._version import __version__
24
23
25
24
# imported lazily to avoid startup performance hit if it isn't used
@@ -121,10 +120,6 @@ def match_utf8(encoding):
121
120
'write_empty_values' : False ,
122
121
}
123
122
124
- # this could be replaced if six is used for compatibility, or there are no
125
- # more assertions about items being a string
126
-
127
-
128
123
def getObj (s ):
129
124
global compiler
130
125
if compiler is None :
@@ -553,11 +548,11 @@ def __getitem__(self, key):
553
548
"""Fetch the item and do string interpolation."""
554
549
val = dict .__getitem__ (self , key )
555
550
if self .main .interpolation :
556
- if isinstance (val , six . string_types ):
551
+ if isinstance (val , str ):
557
552
return self ._interpolate (key , val )
558
553
if isinstance (val , list ):
559
554
def _check (entry ):
560
- if isinstance (entry , six . string_types ):
555
+ if isinstance (entry , str ):
561
556
return self ._interpolate (key , entry )
562
557
return entry
563
558
new = [_check (entry ) for entry in val ]
@@ -580,7 +575,7 @@ def __setitem__(self, key, value, unrepr=False):
580
575
``unrepr`` must be set when setting a value to a dictionary, without
581
576
creating a new sub-section.
582
577
"""
583
- if not isinstance (key , six . string_types ):
578
+ if not isinstance (key , str ):
584
579
raise ValueError ('The key "%s" is not a string.' % key )
585
580
586
581
# add the comment
@@ -614,11 +609,11 @@ def __setitem__(self, key, value, unrepr=False):
614
609
if key not in self :
615
610
self .scalars .append (key )
616
611
if not self .main .stringify :
617
- if isinstance (value , six . string_types ):
612
+ if isinstance (value , str ):
618
613
pass
619
614
elif isinstance (value , (list , tuple )):
620
615
for entry in value :
621
- if not isinstance (entry , six . string_types ):
616
+ if not isinstance (entry , str ):
622
617
raise TypeError ('Value is not a string "%s".' % entry )
623
618
else :
624
619
raise TypeError ('Value is not a string "%s".' % value )
@@ -959,7 +954,7 @@ def as_bool(self, key):
959
954
return False
960
955
else :
961
956
try :
962
- if not isinstance (val , six . string_types ):
957
+ if not isinstance (val , str ):
963
958
# TODO: Why do we raise a KeyError here?
964
959
raise KeyError ()
965
960
else :
@@ -1230,7 +1225,7 @@ def __init__(self, infile=None, options=None, configspec=None, encoding=None,
1230
1225
1231
1226
1232
1227
def _load (self , infile , configspec ):
1233
- if isinstance (infile , six . string_types ):
1228
+ if isinstance (infile , str ):
1234
1229
self .filename = infile
1235
1230
if os .path .isfile (infile ):
1236
1231
with open (infile , 'rb' ) as h :
@@ -1298,7 +1293,7 @@ def set_section(in_section, this_section):
1298
1293
break
1299
1294
break
1300
1295
1301
- assert all (isinstance (line , six . string_types ) for line in content ), repr (content )
1296
+ assert all (isinstance (line , str ) for line in content ), repr (content )
1302
1297
content = [line .rstrip ('\r \n ' ) for line in content ]
1303
1298
1304
1299
self ._parse (content )
@@ -1403,7 +1398,7 @@ def _handle_bom(self, infile):
1403
1398
else :
1404
1399
line = infile
1405
1400
1406
- if isinstance (line , six . text_type ):
1401
+ if isinstance (line , str ):
1407
1402
# it's already decoded and there's no need to do anything
1408
1403
# else, just use the _decode utility method to handle
1409
1404
# listifying appropriately
@@ -1448,7 +1443,7 @@ def _handle_bom(self, infile):
1448
1443
1449
1444
# No encoding specified - so we need to check for UTF8/UTF16
1450
1445
for BOM , (encoding , final_encoding ) in list (BOMS .items ()):
1451
- if not isinstance (line , six . binary_type ) or not line .startswith (BOM ):
1446
+ if not isinstance (line , bytes ) or not line .startswith (BOM ):
1452
1447
# didn't specify a BOM, or it's not a bytestring
1453
1448
continue
1454
1449
else :
@@ -1464,30 +1459,26 @@ def _handle_bom(self, infile):
1464
1459
else :
1465
1460
infile = newline
1466
1461
# UTF-8
1467
- if isinstance (infile , six . text_type ):
1462
+ if isinstance (infile , str ):
1468
1463
return infile .splitlines (True )
1469
- elif isinstance (infile , six . binary_type ):
1464
+ elif isinstance (infile , bytes ):
1470
1465
return infile .decode ('utf-8' ).splitlines (True )
1471
1466
else :
1472
1467
return self ._decode (infile , 'utf-8' )
1473
1468
# UTF16 - have to decode
1474
1469
return self ._decode (infile , encoding )
1475
1470
1476
1471
1477
- if six .PY2 and isinstance (line , str ):
1478
- # don't actually do any decoding, since we're on python 2 and
1479
- # returning a bytestring is fine
1480
- return self ._decode (infile , None )
1481
1472
# No BOM discovered and no encoding specified, default to UTF-8
1482
- if isinstance (infile , six . binary_type ):
1473
+ if isinstance (infile , bytes ):
1483
1474
return infile .decode ('utf-8' ).splitlines (True )
1484
1475
else :
1485
1476
return self ._decode (infile , 'utf-8' )
1486
1477
1487
1478
1488
1479
def _a_to_u (self , aString ):
1489
1480
"""Decode ASCII strings to unicode if a self.encoding is specified."""
1490
- if isinstance (aString , six . binary_type ) and self .encoding :
1481
+ if isinstance (aString , bytes ) and self .encoding :
1491
1482
return aString .decode (self .encoding )
1492
1483
else :
1493
1484
return aString
@@ -1499,9 +1490,9 @@ def _decode(self, infile, encoding):
1499
1490
1500
1491
if is a string, it also needs converting to a list.
1501
1492
"""
1502
- if isinstance (infile , six . string_types ):
1493
+ if isinstance (infile , str ):
1503
1494
return infile .splitlines (True )
1504
- if isinstance (infile , six . binary_type ):
1495
+ if isinstance (infile , bytes ):
1505
1496
# NOTE: Could raise a ``UnicodeDecodeError``
1506
1497
if encoding :
1507
1498
return infile .decode (encoding ).splitlines (True )
@@ -1510,7 +1501,7 @@ def _decode(self, infile, encoding):
1510
1501
1511
1502
if encoding :
1512
1503
for i , line in enumerate (infile ):
1513
- if isinstance (line , six . binary_type ):
1504
+ if isinstance (line , bytes ):
1514
1505
# NOTE: The isinstance test here handles mixed lists of unicode/string
1515
1506
# NOTE: But the decode will break on any non-string values
1516
1507
# NOTE: Or could raise a ``UnicodeDecodeError``
@@ -1520,7 +1511,7 @@ def _decode(self, infile, encoding):
1520
1511
1521
1512
def _decode_element (self , line ):
1522
1513
"""Decode element to unicode if necessary."""
1523
- if isinstance (line , six . binary_type ) and self .default_encoding :
1514
+ if isinstance (line , bytes ) and self .default_encoding :
1524
1515
return line .decode (self .default_encoding )
1525
1516
else :
1526
1517
return line
@@ -1532,7 +1523,7 @@ def _str(self, value):
1532
1523
Used by ``stringify`` within validate, to turn non-string values
1533
1524
into strings.
1534
1525
"""
1535
- if not isinstance (value , six . string_types ):
1526
+ if not isinstance (value , str ):
1536
1527
# intentially 'str' because it's just whatever the "normal"
1537
1528
# string type is for the python version we're dealing with
1538
1529
return str (value )
@@ -1786,7 +1777,7 @@ def _quote(self, value, multiline=True):
1786
1777
return self ._quote (value [0 ], multiline = False ) + ','
1787
1778
return ', ' .join ([self ._quote (val , multiline = False )
1788
1779
for val in value ])
1789
- if not isinstance (value , six . string_types ):
1780
+ if not isinstance (value , str ):
1790
1781
if self .stringify :
1791
1782
# intentially 'str' because it's just whatever the "normal"
1792
1783
# string type is for the python version we're dealing with
@@ -2111,7 +2102,7 @@ def write(self, outfile=None, section=None):
2111
2102
if not output .endswith (newline ):
2112
2103
output += newline
2113
2104
2114
- if isinstance (output , six . binary_type ):
2105
+ if isinstance (output , bytes ):
2115
2106
output_bytes = output
2116
2107
else :
2117
2108
output_bytes = output .encode (self .encoding or
@@ -2353,7 +2344,7 @@ def reload(self):
2353
2344
This method raises a ``ReloadError`` if the ConfigObj doesn't have
2354
2345
a filename attribute pointing to a file.
2355
2346
"""
2356
- if not isinstance (self .filename , six . string_types ):
2347
+ if not isinstance (self .filename , str ):
2357
2348
raise ReloadError ()
2358
2349
2359
2350
filename = self .filename
0 commit comments