File: 0014-Port-to-python3.patch

package info (click to toggle)
ruby-pygments.rb 1.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,008 kB
  • sloc: ansic: 1,869; ruby: 612; python: 518; makefile: 10; sh: 4
file content (88 lines) | stat: -rw-r--r-- 3,093 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
From: Antonio Terceiro <terceiro@debian.org>
Date: Sun, 5 Apr 2020 10:21:43 -0300
Subject: Port to python3

---
 lib/pygments/mentos.py | 19 ++++++++-----------
 lib/pygments/popen.rb  |  4 ++--
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/lib/pygments/mentos.py b/lib/pygments/mentos.py
index f2557f1..2641c79 100755
--- a/lib/pygments/mentos.py
+++ b/lib/pygments/mentos.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 # -*- coding: utf-8 -*-
 
 import sys, re, os, signal
@@ -164,12 +164,9 @@ class Mentos(object):
                 res = json.dumps(res)
 
             elif method == 'highlight':
-                try:
-                    text = text.decode('utf-8')
-                except UnicodeDecodeError:
-                    # The text may already be encoded
-                    text = text
                 res = self.highlight_text(text, lexer, formatter_name, args, _convert_keys(opts))
+                if type(res) is bytes:
+                    res = res.decode('utf-8')
 
             elif method == 'css':
                 kwargs = _convert_keys(kwargs)
@@ -198,7 +195,7 @@ class Mentos(object):
         # Base header. We'll build on this, adding keys as necessary.
         base_header = {"method": method}
 
-        res_bytes = len(res) + 1
+        res_bytes = len(res.encode("utf-8")) + 1
         base_header["bytes"] = res_bytes
 
         out_header = json.dumps(base_header)
@@ -265,7 +262,7 @@ class Mentos(object):
             # The loop begins by reading off a simple 32-arity string
             # representing an integer of 32 bits. This is the length of
             # our JSON header.
-            size = sys.stdin.read(32)
+            size = sys.stdin.buffer.read(32).decode('utf-8')
 
             if not size:
                 break
@@ -281,7 +278,7 @@ class Mentos(object):
                 if not size_regex.match(size):
                     _write_error("Size received is not valid.")
 
-                line = sys.stdin.read(header_bytes)
+                line = sys.stdin.buffer.read(header_bytes).decode('utf-8')
 
                 header = json.loads(line)
 
@@ -295,8 +292,8 @@ class Mentos(object):
                 if kwargs:
                     _bytes = kwargs.get("bytes", 0)
 
-                # Read up to the given number bytes (possibly 0)
-                text = sys.stdin.read(_bytes)
+                # Read up to the given number of *bytes* (not chars) (possibly 0)
+                text = sys.stdin.buffer.read(_bytes).decode('utf-8')
 
                 # Sanity check the return.
                 if _bytes:
diff --git a/lib/pygments/popen.rb b/lib/pygments/popen.rb
index 917460e..987fc59 100644
--- a/lib/pygments/popen.rb
+++ b/lib/pygments/popen.rb
@@ -65,9 +65,9 @@ module Pygments
       if ENV['PYGMENTS_RB_PYTHON']
         return which(ENV['PYGMENTS_RB_PYTHON'])
       elsif windows? && which('py')
-        return 'py -2'
+        return 'py -3'
       end
-      return which('python2') || which('python')
+      return which('python3')
     end
 
     # Cross platform which command