5
5
"""
6
6
import os
7
7
import tempfile
8
- import http .client as client
9
8
import xml .etree .ElementTree as parser
9
+ from http import client
10
10
from itertools import dropwhile
11
11
from re import search , sub
12
12
from sys import stderr
@@ -37,7 +37,7 @@ def header(self):
37
37
return ''
38
38
39
39
xml_resource = 'https://raw.githubusercontent.com/' \
40
- 'spdx/license-list-XML/master /src/%s.xml'
40
+ 'spdx/license-list-XML/main /src/%s.xml'
41
41
resource = quote (xml_resource % self .spdx_code , safe = '/:' )
42
42
license_data = None
43
43
cache = _find_cached_license (self .spdx_code )
@@ -139,25 +139,47 @@ def license_text(self):
139
139
return ''
140
140
141
141
# TODO: find a more reliable license generator: # pylint: disable=W0511
142
- # https://github.com/spdx/license-list-data/blob/master /text/MIT.txt
143
- # https://github.com/spdx/license-list-data/blob/master /text/0BSD.txt
142
+ # https://github.com/spdx/license-list-data/blob/main /text/MIT.txt
143
+ # https://github.com/spdx/license-list-data/blob/main /text/0BSD.txt
144
144
# https://github.com/spdx/license-list-data/blob/2e20899c0504ff6c0acfcc1b0994d7163ce46939/text/Unlicense.txt#L10
145
145
# https://github.com/spdx/license-list-data/blob/2e20899c0504ff6c0acfcc1b0994d7163ce46939/text/BSD-1-Clause.txt#L9
146
146
#
147
147
# full text of new licenses added since v3.11 are fetched from
148
148
# the HEAD of spdx/license-list-data; USE THEM AT YOUR OWN RISK
149
149
spdx_revision = '2e20899c0504ff6c0acfcc1b0994d7163ce46939' \
150
150
if not self .spdx_code in [
151
+ 'AdaCore-doc' ,
152
+ 'ASWF-Digital-Assets-1.0' ,
153
+ 'ASWF-Digital-Assets-1.1' ,
154
+ 'Boehm-GC' ,
151
155
'BSD-3-Clause-Modification' ,
152
156
'BSD-3-Clause-No-Military-License' ,
153
157
'BSD-4-Clause-Shortened' ,
154
158
'C-UDA-1.0' ,
159
+ 'CC-BY-SA-3.0-IGO' ,
155
160
'DRL-1.0' ,
161
+ 'dtoa' ,
156
162
'FreeBSD-DOC' ,
157
163
'GD' ,
164
+ 'Inner-Net-2.0' ,
165
+ 'Latex2e-translated-notice' ,
166
+ 'Linux-man-pages-1-para' ,
167
+ 'Linux-man-pages-copyleft-2-para' ,
168
+ 'Linux-man-pages-copyleft-var' ,
169
+ 'metamail' ,
158
170
'MIT-Modern-Variant' ,
159
- 'OGDL-Taiwan-1.0' ] \
160
- else 'master'
171
+ 'MIT-Festival' ,
172
+ 'NIST-Software' ,
173
+ 'OGDL-Taiwan-1.0' ,
174
+ 'OLFL-1.3' ,
175
+ 'OPL-UK-3.0' ,
176
+ 'SGP4' ,
177
+ 'TermReadKey' ,
178
+ 'UnixCrypt' ,
179
+ 'Widget-Workshop' ,
180
+ 'Xdebug-1.03' ,
181
+ 'Xfig' ] \
182
+ else 'main'
161
183
162
184
text_resource = 'https://raw.githubusercontent.com/' \
163
185
'spdx/license-list-data/' + spdx_revision + \
@@ -272,37 +294,36 @@ def _fetch_license(resource, spdx_id):
272
294
_ , ext = os .path .splitext (resource )
273
295
274
296
try :
275
- response = request .urlopen (request .Request (resource ))
297
+ with request .urlopen (request .Request (resource )) as response :
298
+ if response .status == 200 :
299
+ response_text = response .read ().decode ('utf8' )
300
+ if ext .lower () == '.xml' :
301
+ try :
302
+ license_data = parser .fromstring (response_text )
303
+ except (client .IncompleteRead , parser .ParseError , TypeError ):
304
+ print ("Got invalid licence data from %s." % (resource ),
305
+ file = stderr )
306
+ else :
307
+ license_data = response_text
276
308
277
- if response .status == 200 :
278
- response_text = response .read ().decode ('utf8' )
279
- if ext .lower () == '.xml' :
280
309
try :
281
- license_data = parser .fromstring (response_text )
282
- except (client .IncompleteRead , parser .ParseError , TypeError ):
283
- print ("Got invalid licence data from %s." % (resource ),
284
- file = stderr )
310
+ _ , temp_file = \
311
+ tempfile .mkstemp (prefix = spdx_id + '_' ,
312
+ suffix = ext ,
313
+ text = True )
314
+ if temp_file :
315
+ try :
316
+ with open (temp_file , 'w' , encoding = 'utf-8' ) as tmp :
317
+ tmp .write (response_text )
318
+ except IOError :
319
+ pass
320
+
321
+ except IOError :
322
+ pass
285
323
else :
286
- license_data = response_text
287
-
288
- try :
289
- _ , temp_file = \
290
- tempfile .mkstemp (prefix = spdx_id + '_' ,
291
- suffix = ext ,
292
- text = True )
293
- if temp_file :
294
- try :
295
- with open (temp_file , 'w' , encoding = 'utf-8' ) as tmp :
296
- tmp .write (response_text )
297
- except IOError :
298
- pass
299
-
300
- except IOError :
301
- pass
302
- else :
303
- print ("Unexpected response [%d] from %s.\n "
304
- % (response .status_code , resource ),
305
- file = stderr )
324
+ print ("Unexpected response [%d] from %s.\n "
325
+ % (response .status_code , resource ),
326
+ file = stderr )
306
327
307
328
except (urllib_error .HTTPError ,
308
329
urllib_error .URLError ):
@@ -314,6 +335,7 @@ def _fetch_license(resource, spdx_id):
314
335
'0BSD' ,
315
336
'AAL' ,
316
337
'Abstyles' ,
338
+ 'AdaCore-doc' ,
317
339
'Adobe-2006' ,
318
340
'Adobe-Glyph' ,
319
341
'ADSL' ,
@@ -346,13 +368,16 @@ def _fetch_license(resource, spdx_id):
346
368
'Artistic-1.0-cl8' ,
347
369
'Artistic-1.0-Perl' ,
348
370
'Artistic-2.0' ,
371
+ 'ASWF-Digital-Assets-1.0' ,
372
+ 'ASWF-Digital-Assets-1.1' ,
349
373
'Bahyph' ,
350
374
'Barr' ,
351
375
'Beerware' ,
352
376
'BitTorrent-1.0' ,
353
377
'BitTorrent-1.1' ,
354
378
'blessing' ,
355
379
'BlueOak-1.0.0' ,
380
+ 'Boehm-GC' ,
356
381
'Borceux' ,
357
382
'BSD-1-Clause' ,
358
383
'BSD-2-Clause' ,
@@ -377,11 +402,11 @@ def _fetch_license(resource, spdx_id):
377
402
'BUSL-1.1' ,
378
403
'bzip2-1.0.5' ,
379
404
'bzip2-1.0.6' ,
380
- 'C-UDA-1.0' ,
381
405
'CAL-1.0' ,
382
406
'CAL-1.0-Combined-Work-Exception' ,
383
407
'Caldera' ,
384
408
'CATOSL-1.1' ,
409
+ 'CC0-1.0' ,
385
410
'CC-BY-1.0' ,
386
411
'CC-BY-2.0' ,
387
412
'CC-BY-2.5' ,
@@ -416,9 +441,9 @@ def _fetch_license(resource, spdx_id):
416
441
'CC-BY-SA-2.5' ,
417
442
'CC-BY-SA-3.0' ,
418
443
'CC-BY-SA-3.0-AT' ,
444
+ 'CC-BY-SA-3.0-IGO' ,
419
445
'CC-BY-SA-4.0' ,
420
446
'CC-PDDC' ,
421
- 'CC0-1.0' ,
422
447
'CDDL-1.0' ,
423
448
'CDDL-1.1' ,
424
449
'CDLA-Permissive-1.0' ,
@@ -448,13 +473,15 @@ def _fetch_license(resource, spdx_id):
448
473
'CrystalStacker' ,
449
474
'CUA-OPL-1.0' ,
450
475
'Cube' ,
476
+ 'C-UDA-1.0' ,
451
477
'curl' ,
452
478
'D-FSL-1.0' ,
453
479
'diffmark' ,
454
480
'DOC' ,
455
481
'Dotseqn' ,
456
482
'DRL-1.0' ,
457
483
'DSDP' ,
484
+ 'dtoa' ,
458
485
'dvipdfm' ,
459
486
'ECL-1.0' ,
460
487
'ECL-2.0' ,
@@ -523,6 +550,7 @@ def _fetch_license(resource, spdx_id):
523
550
'iMatix' ,
524
551
'Imlib2' ,
525
552
'Info-ZIP' ,
553
+ 'Inner-Net-2.0' ,
526
554
'Intel' ,
527
555
'Intel-ACPI' ,
528
556
'Interbase-1.0' ,
@@ -535,6 +563,7 @@ def _fetch_license(resource, spdx_id):
535
563
'LAL-1.2' ,
536
564
'LAL-1.3' ,
537
565
'Latex2e' ,
566
+ 'Latex2e-translated-notice' ,
538
567
'Leptonica' ,
539
568
'LGPL-2.0-only' ,
540
569
'LGPL-2.0-or-later' ,
@@ -550,6 +579,9 @@ def _fetch_license(resource, spdx_id):
550
579
'LiLiQ-P-1.1' ,
551
580
'LiLiQ-R-1.1' ,
552
581
'LiLiQ-Rplus-1.1' ,
582
+ 'Linux-man-pages-1-para' ,
583
+ 'Linux-man-pages-copyleft-2-para' ,
584
+ 'Linux-man-pages-copyleft-var' ,
553
585
'Linux-OpenIB' ,
554
586
'LPL-1.0' ,
555
587
'LPL-1.02' ,
@@ -559,16 +591,18 @@ def _fetch_license(resource, spdx_id):
559
591
'LPPL-1.3a' ,
560
592
'LPPL-1.3c' ,
561
593
'MakeIndex' ,
594
+ 'metamail' ,
562
595
'MirOS' ,
563
596
'MIT' ,
564
597
'MIT-0' ,
565
598
'MIT-advertising' ,
566
599
'MIT-CMU' ,
567
600
'MIT-enna' ,
568
601
'MIT-feh' ,
602
+ 'MIT-Festival' ,
569
603
'MIT-Modern-Variant' ,
570
- 'MIT-open-group' ,
571
604
'MITNFA' ,
605
+ 'MIT-open-group' ,
572
606
'Motosoto' ,
573
607
'mpich2' ,
574
608
'MPL-1.0' ,
@@ -587,12 +621,13 @@ def _fetch_license(resource, spdx_id):
587
621
'NBPL-1.0' ,
588
622
'NCGL-UK-2.0' ,
589
623
'NCSA' ,
590
- 'Net-SNMP' ,
591
624
'NetCDF' ,
625
+ 'Net-SNMP' ,
592
626
'Newsletr' ,
593
627
'NGPL' ,
594
628
'NIST-PD' ,
595
629
'NIST-PD-fallback' ,
630
+ 'NIST-Software' ,
596
631
'NLOD-1.0' ,
597
632
'NLPL' ,
598
633
'Nokia' ,
@@ -604,7 +639,6 @@ def _fetch_license(resource, spdx_id):
604
639
'NRL' ,
605
640
'NTP' ,
606
641
'NTP-0' ,
607
- 'O-UDA-1.0' ,
608
642
'OCCT-PL' ,
609
643
'OCLC-2.0' ,
610
644
'ODbL-1.0' ,
@@ -638,15 +672,18 @@ def _fetch_license(resource, spdx_id):
638
672
'OLDAP-2.6' ,
639
673
'OLDAP-2.7' ,
640
674
'OLDAP-2.8' ,
675
+ 'OLFL-1.3' ,
641
676
'OML' ,
642
677
'OpenSSL' ,
643
678
'OPL-1.0' ,
679
+ 'OPL-UK-3.0' ,
644
680
'OSET-PL-2.1' ,
645
681
'OSL-1.0' ,
646
682
'OSL-1.1' ,
647
683
'OSL-2.0' ,
648
684
'OSL-2.1' ,
649
685
'OSL-3.0' ,
686
+ 'O-UDA-1.0' ,
650
687
'Parity-6.0.0' ,
651
688
'Parity-7.0.0' ,
652
689
'PDDL-1.0' ,
@@ -670,14 +707,15 @@ def _fetch_license(resource, spdx_id):
670
707
'RSA-MD' ,
671
708
'RSCPL' ,
672
709
'Ruby' ,
673
- 'SAX-PD' ,
674
710
'Saxpath' ,
711
+ 'SAX-PD' ,
675
712
'SCEA' ,
676
713
'Sendmail' ,
677
714
'Sendmail-8.23' ,
678
715
'SGI-B-1.0' ,
679
716
'SGI-B-1.1' ,
680
717
'SGI-B-2.0' ,
718
+ 'SGP4' ,
681
719
'SHL-0.5' ,
682
720
'SHL-0.51' ,
683
721
'SimPL-2.0' ,
@@ -699,6 +737,7 @@ def _fetch_license(resource, spdx_id):
699
737
'TAPR-OHL-1.0' ,
700
738
'TCL' ,
701
739
'TCP-wrappers' ,
740
+ 'TermReadKey' ,
702
741
'TMate' ,
703
742
'TORQUE-1.1' ,
704
743
'TOSL' ,
@@ -708,6 +747,7 @@ def _fetch_license(resource, spdx_id):
708
747
'Unicode-DFS-2015' ,
709
748
'Unicode-DFS-2016' ,
710
749
'Unicode-TOU' ,
750
+ 'UnixCrypt' ,
711
751
'Unlicense' ,
712
752
'UPL-1.0' ,
713
753
'Vim' ,
@@ -717,10 +757,13 @@ def _fetch_license(resource, spdx_id):
717
757
'W3C-19980720' ,
718
758
'W3C-20150513' ,
719
759
'Watcom-1.0' ,
760
+ 'Widget-Workshop' ,
720
761
'Wsuipa' ,
721
762
'WTFPL' ,
722
763
'X11' ,
764
+ 'Xdebug-1.03' ,
723
765
'Xerox' ,
766
+ 'Xfig' ,
724
767
'XFree86-1.1' ,
725
768
'xinetd' ,
726
769
'Xnet' ,
@@ -744,7 +787,7 @@ def _fetch_license(resource, spdx_id):
744
787
_PD_LICENSE_IDS = [
745
788
'ANTLR-PD' , 'ANTLR-PD-fallback' , 'CC-PDDC' , 'CC0-1.0' ,
746
789
'libselinux-1.0' , 'NIST-PD' , 'NIST-PD-fallback' , 'PDDL-1.0' ,
747
- 'SAX-PD' , 'Unlicense' ]
790
+ 'SAX-PD' , 'SGP4' , ' Unlicense' ]
748
791
"""
749
792
Licenses with no copyright requirement
750
793
"""
0 commit comments