@@ -140,7 +140,7 @@ def find_locale_dir():
140140open_text_file = partial (codecs .open , encoding = "utf-8" , errors = "strict" )
141141
142142# This is the same as decoding the byte values in codecs.BOM:
143- UNICODE_BYTE_ORDER_MARK = "\uFEFF "
143+ UNICODE_BYTE_ORDER_MARK = "\ufeff "
144144
145145
146146def make_bag (
@@ -422,8 +422,8 @@ def compare_manifests_with_fs(self):
422422
423423 def compare_fetch_with_fs (self ):
424424 """Compares the fetch entries with the files actually
425- in the payload, and returns a list of all the files
426- that still need to be fetched.
425+ in the payload, and returns a list of all the files
426+ that still need to be fetched.
427427 """
428428
429429 files_on_fs = set (self .payload_files ())
@@ -449,7 +449,7 @@ def payload_files(self):
449449 yield rel_path
450450
451451 def payload_entries (self ):
452- """Return a dictionary of items """
452+ """Return a dictionary of items"""
453453 # Don't use dict comprehension (compatibility with Python < 2.7)
454454 return dict (
455455 (key , value )
@@ -618,7 +618,9 @@ def is_valid(self, processes=1, fast=False, completeness_only=False):
618618 """
619619
620620 try :
621- self .validate (processes = processes , fast = fast , completeness_only = completeness_only )
621+ self .validate (
622+ processes = processes , fast = fast , completeness_only = completeness_only
623+ )
622624 except BagError :
623625 return False
624626
@@ -776,7 +778,10 @@ def validate_fetch(self):
776778
777779 # each parsed url must resolve to a scheme and point to a netloc
778780 # if the scheme is file, netloc is not necessary
779- if not (all ((parsed_url .scheme , parsed_url .netloc )) or parsed_url .scheme == "file" ):
781+ if not (
782+ all ((parsed_url .scheme , parsed_url .netloc ))
783+ or parsed_url .scheme == "file"
784+ ):
780785 raise BagError (_ ("Malformed URL in fetch.txt: %s" ) % url )
781786
782787 def _validate_contents (self , processes = 1 , fast = False , completeness_only = False ):
@@ -851,11 +856,11 @@ def _validate_completeness(self):
851856 only_in_manifests , only_on_fs = self .compare_manifests_with_fs ()
852857 for path in only_in_manifests :
853858 e = FileMissing (path )
854- LOGGER .warning (force_unicode (e ))
859+ LOGGER .warning (str (e ))
855860 errors .append (e )
856861 for path in only_on_fs :
857862 e = UnexpectedFile (path )
858- LOGGER .warning (force_unicode (e ))
863+ LOGGER .warning (str (e ))
859864 errors .append (e )
860865
861866 if errors :
@@ -906,7 +911,7 @@ def _validate_entries(self, processes):
906911 e = ChecksumMismatch (
907912 rel_path , alg , stored_hash .lower (), computed_hash
908913 )
909- LOGGER .warning (force_unicode (e ))
914+ LOGGER .warning (str (e ))
910915 errors .append (e )
911916
912917 if errors :
@@ -963,7 +968,7 @@ def __init__(self, message, details=None):
963968
964969 def __str__ (self ):
965970 if len (self .details ) > 0 :
966- details = "; " .join ([force_unicode (e ) for e in self .details ])
971+ details = "; " .join ([str (e ) for e in self .details ])
967972 return "%s: %s" % (self .message , details )
968973 return self .message
969974
@@ -988,7 +993,7 @@ def __str__(self):
988993 return _ (
989994 '%(path)s %(algorithm)s validation failed: expected="%(expected)s" found="%(found)s"'
990995 ) % {
991- "path" : force_unicode (self .path ),
996+ "path" : str (self .path ),
992997 "algorithm" : self .algorithm ,
993998 "expected" : self .expected ,
994999 "found" : self .found ,
@@ -997,9 +1002,9 @@ def __str__(self):
9971002
9981003class FileMissing (ManifestErrorDetail ):
9991004 def __str__ (self ):
1000- return _ (
1001- "%s exists in manifest but was not found on filesystem"
1002- ) % force_unicode ( self . path )
1005+ return _ ("%s exists in manifest but was not found on filesystem" ) % str (
1006+ self . path
1007+ )
10031008
10041009
10051010class UnexpectedFile (ManifestErrorDetail ):
@@ -1138,7 +1143,7 @@ def _calc_hashes(args):
11381143 try :
11391144 f_hashes = _calculate_file_hashes (full_path , f_hashers )
11401145 except BagValidationError as e :
1141- f_hashes = dict ((alg , force_unicode (e )) for alg in f_hashers .keys ())
1146+ f_hashes = dict ((alg , str (e )) for alg in f_hashers .keys ())
11421147
11431148 return rel_path , f_hashes , hashes
11441149
@@ -1161,7 +1166,7 @@ def _calculate_file_hashes(full_path, f_hashers):
11611166 except (OSError , IOError ) as e :
11621167 raise BagValidationError (
11631168 _ ("Could not read %(filename)s: %(error)s" )
1164- % {"filename" : full_path , "error" : force_unicode (e )}
1169+ % {"filename" : full_path , "error" : str (e )}
11651170 )
11661171
11671172 return dict ((alg , h .hexdigest ()) for alg , h in f_hashers .items ())
@@ -1187,11 +1192,11 @@ def _load_tag_file(tag_file_name, encoding="utf-8-sig"):
11871192
11881193def _parse_tags (tag_file ):
11891194 """Parses a tag file, according to RFC 2822. This
1190- includes line folding, permitting extra-long
1191- field values.
1195+ includes line folding, permitting extra-long
1196+ field values.
11921197
1193- See http://www.faqs.org/rfcs/rfc2822.html for
1194- more information.
1198+ See http://www.faqs.org/rfcs/rfc2822.html for
1199+ more information.
11951200 """
11961201
11971202 tag_name = None
@@ -1237,7 +1242,7 @@ def _make_tag_file(bag_info_path, bag_info):
12371242 values = [values ]
12381243 for txt in values :
12391244 # strip CR, LF and CRLF so they don't mess up the tag file
1240- txt = re .sub (r"\n|\r|(\r\n)" , "" , force_unicode (txt ))
1245+ txt = re .sub (r"\n|\r|(\r\n)" , "" , str (txt ))
12411246 f .write ("%s: %s\n " % (h , txt ))
12421247
12431248
@@ -1433,19 +1438,6 @@ def _decode_filename(s):
14331438 return s
14341439
14351440
1436- def force_unicode_py2 (s ):
1437- """Reliably return a Unicode string given a possible unicode or byte string"""
1438- if isinstance (s , str ):
1439- return s .decode ("utf-8" )
1440- else :
1441- return unicode (s )
1442-
1443-
1444- if sys .version_info > (3 , 0 ):
1445- force_unicode = str
1446- else :
1447- force_unicode = force_unicode_py2
1448-
14491441# following code is used for command line program
14501442
14511443
@@ -1531,7 +1523,10 @@ def _make_parser():
15311523 metadata_args = parser .add_argument_group (_ ("Optional Bag Metadata" ))
15321524 for header in STANDARD_BAG_INFO_HEADERS :
15331525 metadata_args .add_argument (
1534- "--%s" % header .lower (), type = str , action = BagHeaderAction , default = argparse .SUPPRESS
1526+ "--%s" % header .lower (),
1527+ type = str ,
1528+ action = BagHeaderAction ,
1529+ default = argparse .SUPPRESS ,
15351530 )
15361531
15371532 parser .add_argument (
@@ -1574,7 +1569,9 @@ def main():
15741569 parser .error (_ ("--fast is only allowed as an option for --validate!" ))
15751570
15761571 if args .completeness_only and not args .validate :
1577- parser .error (_ ("--completeness-only is only allowed as an option for --validate!" ))
1572+ parser .error (
1573+ _ ("--completeness-only is only allowed as an option for --validate!" )
1574+ )
15781575
15791576 _configure_logging (args )
15801577
@@ -1593,7 +1590,9 @@ def main():
15931590 if args .fast :
15941591 LOGGER .info (_ ("%s valid according to Payload-Oxum" ), bag_dir )
15951592 elif args .completeness_only :
1596- LOGGER .info (_ ("%s is complete and valid according to Payload-Oxum" ), bag_dir )
1593+ LOGGER .info (
1594+ _ ("%s is complete and valid according to Payload-Oxum" ), bag_dir
1595+ )
15971596 else :
15981597 LOGGER .info (_ ("%s is valid" ), bag_dir )
15991598 except BagError as e :
0 commit comments