diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-01-14 16:34:44 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-01-15 10:25:12 +0900 |
commit | 900386ad4615a3dbbc04501ef24c5a43385c6078 (patch) | |
tree | e7c547f76f2100bd99be8962fe7a07c1a64d1c34 | |
parent | 8293cbe18989cabc30375754087091a53a78b3ee (diff) | |
download | tdeaddons-r14.1.0.tar.gz tdeaddons-r14.1.0.zip |
Drop python2 support.r14.1.0
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
-rwxr-xr-x | knewsticker-scripts/fyensget.py | 18 | ||||
-rwxr-xr-x | knewsticker-scripts/sportscores.py | 34 | ||||
-rwxr-xr-x | konq-plugins/imagerotation/exif.py | 47 | ||||
-rwxr-xr-x | konq-plugins/imagerotation/orient.py | 36 |
4 files changed, 67 insertions, 68 deletions
diff --git a/knewsticker-scripts/fyensget.py b/knewsticker-scripts/fyensget.py index d93e13a..bfdae96 100755 --- a/knewsticker-scripts/fyensget.py +++ b/knewsticker-scripts/fyensget.py @@ -15,7 +15,7 @@ ### along with this program; if not, write to the Free Software ### Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import urllib, re,string +import urllib.request, urllib.parse, urllib.error, re,string ################################################################################ # Groups of interest @@ -29,7 +29,7 @@ articleBase = "http://www.fyens.dk/" # Query the sections ################################################################################ def readSections(): - FILE=urllib.urlopen(base+"Menu.php") + FILE=urllib.request.urlopen(base+"Menu.php") REG=re.compile("<a href=\"([^\"]*)\" target=\"Indhold\" class=\"Overskrift.\">(.*?)</a><br>") result=[] line=FILE.readline() @@ -46,20 +46,20 @@ def readSections(): # Fetch articles from a single section ################################################################################ def readSection( url, title ): - FILE=urllib.urlopen(base+url) + FILE=urllib.request.urlopen(base+url) REG=re.compile("<a href=\"([^\"]*)\" class=\"Overskrift.\">(.*?)</a>") line = FILE.readline() while line: match = REG.search(line) if match: - print "<item>\n\t<title>" + title + ": " +match.group(2) + "</title>" - print "\t<link>"+articleBase+match.group(1)+"</link>\n</item>" + print("<item>\n\t<title>" + title + ": " +match.group(2) + "</title>") + print("\t<link>"+articleBase+match.group(1)+"</link>\n</item>") line=FILE.readline() ################################################################################ # Print Header ################################################################################ -print """<?xml version="1.0" encoding="ISO-8859-1"?> +print("""<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd"> <rss version="0.91"> @@ -68,7 +68,7 @@ print """<?xml version="1.0" encoding="ISO-8859-1"?> <language>dk</language> <link>http://www.fyens.dk/</link> <description>Fyens Stiftstidende</description> -""" +""") ################################################################################ # Main @@ -81,8 +81,8 @@ for (url, title) in l: ################################################################################ # Print footer. ################################################################################ -print """ +print(""" </channel> </rss> -""" +""") diff --git a/knewsticker-scripts/sportscores.py b/knewsticker-scripts/sportscores.py index ce9d04d..e9a33aa 100755 --- a/knewsticker-scripts/sportscores.py +++ b/knewsticker-scripts/sportscores.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import string, urllib, sys +import string, urllib.request, urllib.parse, urllib.error, sys if len(sys.argv) > 1: sport = sys.argv[1] @@ -8,21 +8,21 @@ else: class SportsParser: def __init__(self): - print "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>" - print "<rdf:RDF" - print "xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"" - print "xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">" - print "<channel>" - print "<title>%s</title>" %self.title() - print "<description>%s</description>" %self.description() - print "<link>%s</link>" %self.link() - print "</channel>" + print("<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>") + print("<rdf:RDF") + print("xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"") + print("xmlns=\"http://my.netscape.com/rdf/simple/0.9/\">") + print("<channel>") + print("<title>%s</title>" %self.title()) + print("<description>%s</description>" %self.description()) + print("<link>%s</link>" %self.link()) + print("</channel>") self.processScores(self.inputFile()) - print "</rdf:RDF>" + print("</rdf:RDF>") def processScores(self, inputFile): try: - input = urllib.urlopen(self.inputFile()) + input = urllib.request.urlopen(self.inputFile()) lines = input.readlines() except: sys.exit(5) @@ -32,10 +32,10 @@ class SportsParser: self.handleScoreLine(line) def handleGame(self, headline, link): - print "<item>" - print "<title>%s</title>" %headline - print "<link>%s</link>" %link - print "</item>" + print("<item>") + print("<title>%s</title>" %headline) + print("<link>%s</link>" %link) + print("</item>") class NHLParser(SportsParser): def isScoreLine(self, line): @@ -235,7 +235,7 @@ try: parser = globals()["%sParser" %(sport)]() except: - print "Invalid sport type '%s' selected." %sport + print("Invalid sport type '%s' selected." %sport) sys.exit(2) sys.exit(0) diff --git a/konq-plugins/imagerotation/exif.py b/konq-plugins/imagerotation/exif.py index 60fce74..d96759b 100755 --- a/konq-plugins/imagerotation/exif.py +++ b/konq-plugins/imagerotation/exif.py @@ -97,7 +97,7 @@ EXIF_TAGS={ 0x010F: ('Make', ), 0x0110: ('Model', ), 0x0111: ('StripOffsets', ), - 0x0112: ('Qt::Orientation', ), + 0x0112: ('Orientation', ), 0x0115: ('SamplesPerPixel', ), 0x0116: ('RowsPerStrip', ), 0x0117: ('StripByteCounts', ), @@ -631,7 +631,7 @@ MAKERNOTE_CANON_TAG_0x004={ def s2n_motorola(str): x=0 for c in str: - x=(long(x) << 8) | ord(c) + x=(int(x) << 8) | ord(c) return x # extract multibyte integer in Intel format (big endian) @@ -707,7 +707,7 @@ class EXIF_header: val=s2n_motorola(slice) # Sign extension ? if signed: - msb=1L << (8*length-1) + msb=1 << (8*length-1) if val & msb: val=val-(msb << 1) return val @@ -750,8 +750,7 @@ class EXIF_header: field_type=self.s2n(entry+2, 2) if not 0 < field_type < len(FIELD_TYPES): # unknown field type - raise ValueError, \ - 'unknown type %d in tag 0x%04X' % (field_type, tag) + raise ValueError('unknown type %d in tag 0x%04X' % (field_type, tag)) typelen=FIELD_TYPES[field_type][0] count=self.s2n(entry+4, 4) offset=entry+8 @@ -807,8 +806,8 @@ class EXIF_header: values, field_offset, count*typelen) if self.debug: - print ' %s: %s' % (tag_name, - repr(self.tags[ifd_name+' '+tag_name])) + print(' %s: %s' % (tag_name, + repr(self.tags[ifd_name+' '+tag_name]))) # extract uncompressed TIFF thumbnail (like pulling teeth) # we take advantage of the pre-existing layout in the thumbnail IFD as @@ -920,7 +919,7 @@ class EXIF_header: for i in (('MakerNote Tag 0x0001', MAKERNOTE_CANON_TAG_0x001), ('MakerNote Tag 0x0004', MAKERNOTE_CANON_TAG_0x004)): if self.debug: - print ' SubMakerNote BitSet for ' +i[0] + print(' SubMakerNote BitSet for ' +i[0]) self.canon_decode_tag(self.tags[i[0]].values, i[1]) return @@ -937,7 +936,7 @@ class EXIF_header: else: val=value[i] if self.debug: - print ' '+name+':', val + print(' '+name+':', val) self.tags['MakerNote '+name]=val # process an image file (expects an open file object) @@ -973,7 +972,7 @@ def process_file(file, debug=0, noclose=0): # deal with the EXIF info we found if debug: - print {'I': 'Intel', 'M': 'Motorola'}[endian], 'format' + print({'I': 'Intel', 'M': 'Motorola'}[endian], 'format') hdr=EXIF_header(file, endian, offset, debug) ifd_list=hdr.list_IFDs() ctr=0 @@ -986,7 +985,7 @@ def process_file(file, debug=0, noclose=0): else: IFD_name='IFD %d' % ctr if debug: - print ' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i) + print(' IFD %d (%s) at offset %d:' % (ctr, IFD_name, i)) hdr.tags['Exif Offset'] = offset hdr.tags['Exif Endian'] = endian hdr.tags[IFD_name+' IFDOffset'] = i @@ -995,28 +994,28 @@ def process_file(file, debug=0, noclose=0): exif_off=hdr.tags.get(IFD_name+' ExifOffset') if exif_off: if debug: - print ' EXIF SubIFD at offset %d:' % exif_off.values[0] + print(' EXIF SubIFD at offset %d:' % exif_off.values[0]) hdr.dump_IFD(exif_off.values[0], 'EXIF') # Interoperability IFD contained in EXIF IFD #intr_off=hdr.tags.get('EXIF SubIFD InteroperabilityOffset') intr_off=hdr.tags.get('EXIF InteroperabilityOffset') if intr_off: if debug: - print ' EXIF Interoperability SubSubIFD at offset %d:' \ - % intr_off.values[0] + print(' EXIF Interoperability SubSubIFD at offset %d:' \ + % intr_off.values[0]) hdr.dump_IFD(intr_off.values[0], 'EXIF Interoperability', dict=INTR_TAGS) # deal with MakerNote contained in EXIF IFD - if hdr.tags.has_key('EXIF MakerNote'): + if 'EXIF MakerNote' in hdr.tags: if debug: - print ' EXIF MakerNote SubSubIFD at offset %d:' \ - % intr_off.values[0] + print(' EXIF MakerNote SubSubIFD at offset %d:' \ + % intr_off.values[0]) hdr.decode_maker_note() # GPS IFD gps_off=hdr.tags.get(IFD_name+' GPSInfoOffset') if gps_off: if debug: - print ' GPS SubIFD at offset %d:' % gps_off.values[0] + print(' GPS SubIFD at offset %d:' % gps_off.values[0]) hdr.dump_IFD(gps_off.values[0], 'GPS', dict=GPS_TAGS) ctr+=1 @@ -1035,7 +1034,7 @@ def process_file(file, debug=0, noclose=0): # Sometimes in a TIFF file, a JPEG thumbnail is hidden in the MakerNote # since it's not allowed in a uncompressed TIFF IFD - if not hdr.tags.has_key('JPEGThumbnail'): + if 'JPEGThumbnail' not in hdr.tags: thumb_off=hdr.tags.get('MakerNote JPEGThumbnail') if thumb_off: file.seek(offset+thumb_off.values[0]) @@ -1050,21 +1049,21 @@ if __name__ == '__main__': import sys if len(sys.argv) < 2: - print 'Usage: %s files...\n' % sys.argv[0] + print('Usage: %s files...\n' % sys.argv[0]) sys.exit(0) for filename in sys.argv[1:]: try: file=open(filename, 'rb') except: - print filename, 'unreadable' - print + print(filename, 'unreadable') + print() continue - print filename+':' + print(filename+':') # data=process_file(file, 1) # with debug info data=process_file(file, 1) if not data: - print 'No EXIF information found' + print('No EXIF information found') continue # x=data.keys() diff --git a/konq-plugins/imagerotation/orient.py b/konq-plugins/imagerotation/orient.py index 8db06ad..f7a0047 100755 --- a/konq-plugins/imagerotation/orient.py +++ b/konq-plugins/imagerotation/orient.py @@ -13,42 +13,42 @@ def compose(delta, old): def deg2o(d): map={90:6, 270:8, 180:3} - if map.has_key(d): + if d in map: return map[d] else: return 0 if len(sys.argv) < 2: - print 'Usage: %s [[+]orientnum] file\n' % sys.argv[0] + print('Usage: %s [[+]orientnum] file\n' % sys.argv[0]) sys.exit(1) try: if len(sys.argv) == 2: filename=sys.argv[1] - file=open(filename, "r"); + file=open(filename, 'rb'); else: filename=sys.argv[2] mod=sys.argv[1] fd = os.open(filename, os.O_RDWR) - file=os.fdopen(fd,'r') + file=os.fdopen(fd,'rb') # check file exists and is readable file.read(1) file.seek(0,0) except: - print 'Cannot open', filename + print('Cannot open', filename) sys.exit(1) tags=exif.process_file(file,0,1) if not tags: - print 'no EXIF information in', filename + print('no EXIF information in', filename) sys.exit(1) -if not tags.has_key('Exif Offset') \ - or not tags.has_key('Image Qt::Orientation'): - print 'cannot get orientation info in', filename +if 'Exif Offset' not in tags \ + or 'Image Orientation' not in tags: + print('cannot get orientation info in', filename) sys.exit(1) exifp = tags['Exif Offset'] endian = tags['Exif Endian'] -tagp = tags['Image Qt::Orientation'].field_offset +tagp = tags['Image Orientation'].field_offset orientp = exifp + tagp @@ -59,11 +59,11 @@ file.seek(orientp) o = ord(file.read(1)) if o < 1 or o > 8: - print 'orientation out of range', o + print('orientation out of range', o) sys.exit(1) if len(sys.argv) == 2: - print 'orientation is', o + print('orientation is', o) sys.exit(0) try: @@ -74,18 +74,18 @@ try: elif deg2o(deltao) != 0: newo = compose(deg2o(deltao), o) else: - print 'cannot understand orientation modification', mod + print('cannot understand orientation modification', mod) sys.exit(1) # it will still hit the except ... how to fix? else: newo = int(mod) except: - print 'expected numeric orientation and got',mod + print('expected numeric orientation and got',mod) sys.exit(1) if newo < 1 or newo > 8: newo = deg2o(newo) if newo == 0: - print 'cannot understand orientation', deltao + print('cannot understand orientation', deltao) sys.exit(1) os.lseek(fd,orientp,0) @@ -93,12 +93,12 @@ os.write(fd,chr(newo)) # Thumbnail orientation : thumb_ifdp = 0 -if tags.has_key('Thumbnail Qt::Orientation'): - thumb_tagp = tags['Thumbnail Qt::Orientation'].field_offset +if 'Thumbnail Orientation' in tags: + thumb_tagp = tags['Thumbnail Orientation'].field_offset thumb_orientp = exifp + thumb_tagp if endian == 'M': # MM byte order thumb_orientp += 1 os.lseek(fd,thumb_orientp,0) os.write(fd,chr(newo)) -print 'orientation changed from', o, 'to', newo +print('orientation changed from', o, 'to', newo) |