1 |
Python's formatter module is scheduled for removal in Python 3.6, so |
2 |
replace it with a minimalistic derivation. |
3 |
|
4 |
X-Gentoo-Bug: 547732 |
5 |
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=547732 |
6 |
--- |
7 |
bin/repoman | 2 +- |
8 |
pym/_emerge/JobStatusDisplay.py | 4 +-- |
9 |
pym/portage/output.py | 4 +-- |
10 |
pym/portage/util/formatter.py | 69 +++++++++++++++++++++++++++++++++++++++++ |
11 |
4 files changed, 74 insertions(+), 5 deletions(-) |
12 |
create mode 100644 pym/portage/util/formatter.py |
13 |
|
14 |
diff --git a/bin/repoman b/bin/repoman |
15 |
index e9c89c2..00457fa 100755 |
16 |
--- a/bin/repoman |
17 |
+++ b/bin/repoman |
18 |
@@ -11,7 +11,6 @@ from __future__ import print_function, unicode_literals |
19 |
import codecs |
20 |
import copy |
21 |
import errno |
22 |
-import formatter |
23 |
import io |
24 |
import logging |
25 |
import re |
26 |
@@ -56,6 +55,7 @@ except (ImportError, SystemError, RuntimeError, Exception): |
27 |
from portage import os |
28 |
from portage import _encodings |
29 |
from portage import _unicode_encode |
30 |
+import portage.util.formatter as formatter |
31 |
import repoman.checks |
32 |
from repoman.checks import run_checks |
33 |
from repoman.check_missingslot import check_missingslot |
34 |
diff --git a/pym/_emerge/JobStatusDisplay.py b/pym/_emerge/JobStatusDisplay.py |
35 |
index 9f6f09b..b8e142a 100644 |
36 |
--- a/pym/_emerge/JobStatusDisplay.py |
37 |
+++ b/pym/_emerge/JobStatusDisplay.py |
38 |
@@ -1,14 +1,14 @@ |
39 |
-# Copyright 1999-2013 Gentoo Foundation |
40 |
+# Copyright 1999-2015 Gentoo Foundation |
41 |
# Distributed under the terms of the GNU General Public License v2 |
42 |
|
43 |
from __future__ import unicode_literals |
44 |
|
45 |
-import formatter |
46 |
import io |
47 |
import sys |
48 |
import time |
49 |
|
50 |
import portage |
51 |
+import portage.util.formatter as formatter |
52 |
from portage import os |
53 |
from portage import _encodings |
54 |
from portage import _unicode_encode |
55 |
diff --git a/pym/portage/output.py b/pym/portage/output.py |
56 |
index 7846627..bb7542b 100644 |
57 |
--- a/pym/portage/output.py |
58 |
+++ b/pym/portage/output.py |
59 |
@@ -1,4 +1,4 @@ |
60 |
-# Copyright 1998-2014 Gentoo Foundation |
61 |
+# Copyright 1998-2015 Gentoo Foundation |
62 |
# Distributed under the terms of the GNU General Public License v2 |
63 |
|
64 |
from __future__ import division |
65 |
@@ -7,7 +7,6 @@ __docformat__ = "epytext" |
66 |
|
67 |
import errno |
68 |
import io |
69 |
-import formatter |
70 |
import re |
71 |
import subprocess |
72 |
import sys |
73 |
@@ -16,6 +15,7 @@ import portage |
74 |
portage.proxy.lazyimport.lazyimport(globals(), |
75 |
'portage.util:writemsg', |
76 |
) |
77 |
+import portage.util.formatter as formatter |
78 |
|
79 |
from portage import os |
80 |
from portage import _encodings |
81 |
diff --git a/pym/portage/util/formatter.py b/pym/portage/util/formatter.py |
82 |
new file mode 100644 |
83 |
index 0000000..ce6799e |
84 |
--- /dev/null |
85 |
+++ b/pym/portage/util/formatter.py |
86 |
@@ -0,0 +1,69 @@ |
87 |
+# Copyright 2015 Gentoo Foundation |
88 |
+# Distributed under the terms of the GNU General Public License v2 |
89 |
+# |
90 |
+# This is a minimalistic derivation of Python's deprecated formatter module, |
91 |
+# supporting only the methods related to style, literal data, and line breaks. |
92 |
+ |
93 |
+import sys |
94 |
+ |
95 |
+ |
96 |
+class AbstractFormatter(object): |
97 |
+ """The standard formatter.""" |
98 |
+ |
99 |
+ def __init__(self, writer): |
100 |
+ self.writer = writer # Output device |
101 |
+ self.style_stack = [] # Other state, e.g. color |
102 |
+ self.hard_break = True # Have a hard break |
103 |
+ |
104 |
+ def add_line_break(self): |
105 |
+ if not self.hard_break: |
106 |
+ self.writer.send_line_break() |
107 |
+ self.hard_break = True |
108 |
+ |
109 |
+ def add_literal_data(self, data): |
110 |
+ if not data: return |
111 |
+ self.hard_break = data[-1:] == '\n' |
112 |
+ self.writer.send_literal_data(data) |
113 |
+ |
114 |
+ def push_style(self, *styles): |
115 |
+ for style in styles: |
116 |
+ self.style_stack.append(style) |
117 |
+ self.writer.new_styles(tuple(self.style_stack)) |
118 |
+ |
119 |
+ def pop_style(self, n=1): |
120 |
+ del self.style_stack[-n:] |
121 |
+ self.writer.new_styles(tuple(self.style_stack)) |
122 |
+ |
123 |
+ |
124 |
+class NullWriter(object): |
125 |
+ """Minimal writer interface to use in testing & inheritance. |
126 |
+ |
127 |
+ A writer which only provides the interface definition; no actions are |
128 |
+ taken on any methods. This should be the base class for all writers |
129 |
+ which do not need to inherit any implementation methods. |
130 |
+ """ |
131 |
+ def __init__(self): pass |
132 |
+ def flush(self): pass |
133 |
+ def new_styles(self, styles): pass |
134 |
+ def send_line_break(self): pass |
135 |
+ def send_literal_data(self, data): pass |
136 |
+ |
137 |
+ |
138 |
+class DumbWriter(NullWriter): |
139 |
+ """Simple writer class which writes output on the file object passed in |
140 |
+ as the file parameter or, if file is omitted, on standard output. |
141 |
+ """ |
142 |
+ |
143 |
+ def __init__(self, file=None, maxcol=None): |
144 |
+ NullWriter.__init__(self) |
145 |
+ self.file = file or sys.stdout |
146 |
+ |
147 |
+ def flush(self): |
148 |
+ self.file.flush() |
149 |
+ |
150 |
+ def send_line_break(self): |
151 |
+ self.file.write('\n') |
152 |
+ |
153 |
+ def send_literal_data(self, data): |
154 |
+ self.file.write(data) |
155 |
+ |
156 |
-- |
157 |
2.3.5 |