diff --git a/bin/srv.py b/bin/srv.py index 38b63a4..cf09b3e 100644 --- a/bin/srv.py +++ b/bin/srv.py @@ -4,6 +4,7 @@ """ Main server program. """ +from __future__ import print_function from gevent.wsgi import WSGIServer from gevent.monkey import patch_all @@ -120,8 +121,8 @@ def _proxy(*args, **kwargs): url_after = '?' + "&".join("arg=%s" % x for x in request.args['q'].split()) url += url_after - print url - print request.get_data() + print(url) + print(request.get_data()) resp = requests.request( method=request.method, url=url, diff --git a/lib/adapter_learnxiny.py b/lib/adapter_learnxiny.py index 0c511e6..a623a9e 100644 --- a/lib/adapter_learnxiny.py +++ b/lib/adapter_learnxiny.py @@ -1,6 +1,7 @@ """ Adapters for the cheat sheets from the Learn X in Y project """ +from __future__ import print_function import os import re @@ -29,7 +30,7 @@ class LearnXYAdapter(object): if "Comments" in self._topics_list: self._topics_list = [x for x in self._topics_list if x != "Comments"] + ["Comments"] self._topics_list += [":learn"] - print self.prefix, self._topics_list + print(self.prefix, self._topics_list) def _is_block_separator(self, before, now, after): if (re.match(r'////////*', before) @@ -141,8 +142,8 @@ class LearnXYAdapter(object): for block_name, block_contents in self._blocks: if block_name == name: - print "\n".join(block_contents) - print name + print("\n".join(block_contents)) + print(name) return "\n".join(block_contents) return None diff --git a/lib/beautifier.py b/lib/beautifier.py index f4b5e69..bbe974c 100644 --- a/lib/beautifier.py +++ b/lib/beautifier.py @@ -15,6 +15,7 @@ Exported functions: beautify(text, lang, options) code_blocks(text) """ +from __future__ import print_function from gevent.monkey import patch_all from gevent.subprocess import Popen @@ -237,7 +238,7 @@ def _beautify(text, filetype, add_comments=False, remove_text=False): # We shift the code if and only if we either convert the text into comments # or remove the text completely. Otherwise the code has to remain aligned unindent_code = add_comments or remove_text - print unindent_code + print(unindent_code) lines = [x.rstrip('\n') for x in text.splitlines()] lines = _cleanup_lines(lines) diff --git a/lib/get_answer.py b/lib/get_answer.py index 8ab80fa..ce0b15d 100644 --- a/lib/get_answer.py +++ b/lib/get_answer.py @@ -7,6 +7,7 @@ Exports: get_topic_type() get_answer() """ +from __future__ import print_function from gevent.monkey import patch_all from gevent.subprocess import Popen, PIPE @@ -273,9 +274,9 @@ def _get_answer_for_question(topic): query_text = re.sub('/[0-9]+$', '', query_text) query_text = re.sub('/[0-9]+$', '', query_text) detector = Detector(query_text) - print "query_text = ", query_text + print("query_text = ", query_text) supposed_lang = detector.languages[0].code - print "supposed lang = ", supposed_lang + print("supposed lang = ", supposed_lang) if len(topic_words) > 2 or supposed_lang in ['az', 'ru', 'uk', 'de', 'fr', 'es', 'it']: lang = supposed_lang if supposed_lang.startswith('zh_'): @@ -284,7 +285,7 @@ def _get_answer_for_question(topic): lang = supposed_lang except UnknownLanguage: - print "Unknown language (%s)" % query_text + print("Unknown language (%s)" % query_text) if lang != 'en': topic = ['--human-language', lang, topic] @@ -406,7 +407,7 @@ def get_answer(topic, keyword, options="", request_options=None): # pylint: disa section_name, rest = query.split('/', 1) section_name = SO_NAME.get(section_name, section_name) - print "%s/%s" % (section_name, rest) + print("%s/%s" % (section_name, rest)) return "%s/%s" % (section_name, rest) @@ -422,7 +423,7 @@ def get_answer(topic, keyword, options="", request_options=None): # pylint: disa # what type the query has start_time = time.time() topic_type = get_topic_type(topic) - print (time.time() - start_time)*1000 + print((time.time() - start_time)*1000) # checking if the answer is in the cache if topic != "": diff --git a/lib/globals.py b/lib/globals.py index d00939d..d4664a5 100644 --- a/lib/globals.py +++ b/lib/globals.py @@ -2,6 +2,7 @@ Global configuration of the project. All hardcoded pathes should be (theoretically) here. """ +from __future__ import print_function import logging import os @@ -29,7 +30,7 @@ def error(text): Log error `text` and produce a RuntimeError exception """ if not text.startswith('Too many queries'): - print text + print(text) logging.error("ERROR %s", text) raise RuntimeError(text) @@ -38,5 +39,5 @@ def log(text): Log error `text` (if it does not start with 'Too many queries') """ if not text.startswith('Too many queries'): - print text + print(text) logging.info(text) diff --git a/lib/panela/panela_colors.py b/lib/panela/panela_colors.py index ef8c798..649bb1f 100644 --- a/lib/panela/panela_colors.py +++ b/lib/panela/panela_colors.py @@ -21,7 +21,12 @@ from colors import find_nearest_color, HEX_TO_ANSI, rgb_from_str import pyte # http://stackoverflow.com/questions/19782975/convert-rgb-color-to-the-nearest-color-in-palette-web-safe-color -# pylint: disable=invalid-name + +try: + basestring # Python 2 +except NameError: + basestring = str # Python 3 + def color_mapping(clr): if clr == 'default': @@ -378,8 +383,8 @@ class Panela: char_iter = itertools.repeat(char) for x, y in get_line((x1,y1), (x2, y2)): - char = char_iter.next() - color = color_iter.next() + char = next(char_iter) + color = next(color_iter) background = next(background_iter) self.put_point(x, y, char=char, color=color, background=background)