@@ -344,20 +344,19 @@ def __eq__(self, other):
344344 if sval == oval :
345345 return True
346346
347-
348- class UrlField (ListField ):
347+ class UrlListField (ListField ):
349348 """
350349 A URL field. The validated value is a list of URLs.
351350 """
352351 def _validate (self , * args , ** kwargs ):
353352 """
354353 Check that URLs are valid. Return a list of errors.
355354 """
356- errors = super (UrlField , self )._validate (* args , ** kwargs )
357- for url in self .value :
355+ errors = super (UrlListField , self )._validate (* args , ** kwargs )
356+ name = self .name
357+ val = self .value
358+ for url in val :
358359 if not self .is_valid_url (url ):
359- name = self .name
360- val = self .value
361360 msg = (u'Field %(name)s: Invalid URL: %(val)s' % locals ())
362361 errors .append (Error (WARNING , msg ))
363362 return errors
@@ -372,6 +371,32 @@ def is_valid_url(url):
372371 return valid
373372
374373
374+ class UrlField (StringField ):
375+ """
376+ A URL field. The validated value is a URL.
377+ """
378+ def _validate (self , * args , ** kwargs ):
379+ """
380+ Check that URL is valid. Return a list of errors.
381+ """
382+ errors = super (UrlField , self )._validate (* args , ** kwargs )
383+ name = self .name
384+ val = self .value
385+ if not self .is_valid_url (val ):
386+ msg = (u'Field %(name)s: Invalid URL: %(val)s' % locals ())
387+ errors .append (Error (WARNING , msg ))
388+ return errors
389+
390+ @staticmethod
391+ def is_valid_url (url ):
392+ """
393+ Return True if a URL is valid.
394+ """
395+ scheme , netloc , _path , _p , _q , _frg = urlparse (url )
396+ valid = scheme in ('http' , 'https' , 'ftp' ) and netloc
397+ return valid
398+
399+
375400class PathField (ListField ):
376401 """
377402 A field pointing to one or more paths relative to the ABOUT file location.
@@ -692,7 +717,7 @@ def create_fields(self):
692717 ('license_key' , ListField ()),
693718 ('license_name' , ListField ()),
694719 ('license_file' , FileTextField ()),
695- ('license_url' , UrlField ()),
720+ ('license_url' , UrlListField ()),
696721 ('copyright' , StringField ()),
697722 ('notice_file' , FileTextField ()),
698723 ('notice_url' , UrlField ()),
@@ -704,7 +729,7 @@ def create_fields(self):
704729
705730 ('changelog_file' , FileTextField ()),
706731
707- ('owner' , ListField ()),
732+ ('owner' , StringField ()),
708733 ('owner_url' , UrlField ()),
709734 ('contact' , ListField ()),
710735 ('author' , ListField ()),
@@ -1066,7 +1091,7 @@ def load_dict(self, fields_dict, base_dir, running_inventory=False,
10661091 return errors
10671092
10681093
1069- def dumps (self , with_absent = False , with_empty = True ):
1094+ def dumps (self , use_mapping = False , mapping_file = False , with_absent = False , with_empty = True ):
10701095 """
10711096 Return self as a formatted ABOUT string.
10721097 If with_absent, include absent (not present) fields.
@@ -1113,9 +1138,10 @@ def dumps(self, with_absent=False, with_empty=True):
11131138 if lic_group [3 ]:
11141139 lic_dict ['url' ] = lic_group [3 ]
11151140 about_data .setdefault ('licenses' , []).append (lic_dict )
1116- return saneyaml .dump (about_data )
1141+ formatted_about_data = util .format_output (about_data , use_mapping , mapping_file )
1142+ return saneyaml .dump (formatted_about_data )
11171143
1118- def dump (self , location , with_absent = False , with_empty = True ):
1144+ def dump (self , location , use_mapping = False , mapping_file = False , with_absent = False , with_empty = True ):
11191145 """
11201146 Write formatted ABOUT representation of self to location.
11211147 If with_absent, include absent (not present) fields.
@@ -1135,7 +1161,7 @@ def dump(self, location, with_absent=False, with_empty=True):
11351161 if on_windows :
11361162 about_file_path = add_unc (about_file_path )
11371163 with codecs .open (about_file_path , mode = 'wb' , encoding = 'utf-8' ) as dumped :
1138- dumped .write (self .dumps (with_absent , with_empty ))
1164+ dumped .write (self .dumps (use_mapping , mapping_file , with_absent , with_empty ))
11391165
11401166 def dump_lic (self , location , license_dict ):
11411167 """
0 commit comments