Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3 updates #368

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions bin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,26 @@
from __future__ import print_function

import sys

if sys.version_info[0] < 3:
reload(sys)
sys.setdefaultencoding('utf8')

import sys
import logging
import os
import requests
import sys

import jinja2
from flask import Flask, request, send_from_directory, redirect, Response
import requests
from flask import Flask, Response, redirect, request, send_from_directory

sys.path.append(os.path.abspath(os.path.join(__file__, "..", "..", "lib")))
from cheat_wrapper import cheat_wrapper
from config import CONFIG
from limits import Limits
from cheat_wrapper import cheat_wrapper
from post import process_post_request
from options import parse_args

from stateful_queries import save_query, last_query

from post import process_post_request
from stateful_queries import last_query, save_query

if not os.path.exists(os.path.dirname(CONFIG["path.log.main"])):
os.makedirs(os.path.dirname(CONFIG["path.log.main"]))
Expand All @@ -58,7 +58,7 @@
# (https://github.com/pallets/werkzeug/issues/1969)
# resulting in duplicating lines. In that case we need root
# stderr handler to skip lines from werkzeug.
class SkipFlaskLogger(object):
class SkipFlaskLogger():
def filter(self, record):
if record.name != 'werkzeug':
return True
Expand Down
3 changes: 2 additions & 1 deletion bin/clean_cache.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import sys

import redis

REDIS = redis.Redis(host='localhost', port=6379, db=0)

for key in sys.argv[1:]:
REDIS.delete(key)

6 changes: 3 additions & 3 deletions bin/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from __future__ import print_function

from datetime import datetime
import os
from os import path
import re
import shutil
import subprocess
from subprocess import Popen
import sys
from datetime import datetime
from os import path
from subprocess import Popen

SHARE_DIR = path.join(path.dirname(__file__), "../share/")

Expand Down
4 changes: 2 additions & 2 deletions bin/srv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

from gevent.monkey import patch_all
from gevent.pywsgi import WSGIServer

patch_all()

import os
import sys

from app import app, CONFIG

from app import CONFIG, app

if '--debug' in sys.argv:
# Not all debug mode features are available under `gevent`
Expand Down
4 changes: 2 additions & 2 deletions lib/adapter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

# pylint: disable=wildcard-import,relative-import

from os.path import dirname, basename, isfile, join
import glob
from os.path import basename, dirname, isfile, join

__all__ = [
basename(f)[:-3]
for f in glob.glob(join(dirname(__file__), "*.py"))
if isfile(f) and not f.endswith('__init__.py')]

from .adapter import all_adapters
from . import *
from .adapter import all_adapters
6 changes: 4 additions & 2 deletions lib/adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import abc
import os
from six import with_metaclass

from config import CONFIG
from six import with_metaclass


class AdapterMC(type):
"""
Expand All @@ -21,7 +23,7 @@ def __repr__(cls):
return getattr(cls, '_class_repr')()
return super(AdapterMC, cls).__repr__()

class Adapter(with_metaclass(AdapterMC, object)):
class Adapter(with_metaclass(AdapterMC)):
"""
An abstract class, defines methods:

Expand Down
1 change: 1 addition & 0 deletions lib/adapter/cheat_cheat.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .git_adapter import GitRepositoryAdapter


class Cheat(GitRepositoryAdapter):
"""
cheat/cheat adapter
Expand Down
3 changes: 2 additions & 1 deletion lib/adapter/cheat_sheets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

# pylint: disable=relative-import

import os
import glob
import os

from .git_adapter import GitRepositoryAdapter


def _remove_initial_underscore(filename):
if filename.startswith('_'):
filename = filename[1:]
Expand Down
2 changes: 1 addition & 1 deletion lib/adapter/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os.path
import re
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

from .adapter import Adapter

Expand Down
3 changes: 1 addition & 2 deletions lib/adapter/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Adapter(object):
class Adapter():
pass

class cheatAdapter(Adapter):
pass

3 changes: 2 additions & 1 deletion lib/adapter/git_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import glob
import os

from .adapter import Adapter # pylint: disable=relative-import
from .adapter import Adapter # pylint: disable=relative-import


def _get_filenames(path):
return [os.path.split(topic)[1] for topic in glob.glob(path)]
Expand Down
11 changes: 6 additions & 5 deletions lib/adapter/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
path.internal.pages
"""

import sys
import os
import collections
import os
import sys

try:
from rapidfuzz import process, fuzz
from rapidfuzz import fuzz, process
_USING_FUZZYWUZZY=False
except ImportError:
from fuzzywuzzy import process, fuzz
from fuzzywuzzy import fuzz, process
_USING_FUZZYWUZZY=True

from config import CONFIG
from .adapter import Adapter
from fmt.internal import colorize_internal

from .adapter import Adapter

_INTERNAL_TOPICS = [
":cht.sh",
":bash_completion",
Expand Down
4 changes: 3 additions & 1 deletion lib/adapter/latenz.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

# pylint: disable=relative-import

import sys
import os
import sys

from .git_adapter import GitRepositoryAdapter


class Latenz(GitRepositoryAdapter):

"""
Expand Down
6 changes: 5 additions & 1 deletion lib/adapter/learnxiny.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@
# pylint: disable=relative-import

from __future__ import print_function

import os
import re

from config import CONFIG

from .git_adapter import GitRepositoryAdapter


class LearnXinY(GitRepositoryAdapter):

"""
Expand Down Expand Up @@ -62,7 +66,7 @@ def is_found(self, topic):

return self.adapters[lang].is_valid(topic)

class LearnXYAdapter(object):
class LearnXYAdapter():

"""
Parent class of all languages adapters
Expand Down
6 changes: 3 additions & 3 deletions lib/adapter/question.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

import os
import re
from subprocess import Popen, PIPE
from subprocess import PIPE, Popen

from config import CONFIG
from languages_data import SO_NAME
from polyglot.detect import Detector
from polyglot.detect.base import UnknownLanguage

from config import CONFIG
from languages_data import SO_NAME
from .upstream import UpstreamAdapter

NOT_FOUND_MESSAGE = """404 NOT FOUND
Expand Down
6 changes: 4 additions & 2 deletions lib/adapter/rosetta.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

# pylint: disable=relative-import

import os
import glob
import os

import yaml

from .git_adapter import GitRepositoryAdapter
from .cheat_sheets import CheatSheets
from .git_adapter import GitRepositoryAdapter


class Rosetta(GitRepositoryAdapter):

Expand Down
3 changes: 2 additions & 1 deletion lib/adapter/tldr.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@

# pylint: disable=relative-import,abstract-method

import re
import os
import re

from .git_adapter import GitRepositoryAdapter


class Tldr(GitRepositoryAdapter):

"""
Expand Down
4 changes: 3 additions & 1 deletion lib/adapter/upstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# pylint: disable=relative-import

import textwrap
import requests

import requests
from config import CONFIG

from .adapter import Adapter


def _are_you_offline():
return textwrap.dedent(
"""
Expand Down
1 change: 0 additions & 1 deletion lib/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
<!-- Place this tag right after the last button or just before your close body tag. -->
<script async defer id="github-bjs" src="https://buttons.github.io/buttons.js"></script>
"""

3 changes: 2 additions & 1 deletion lib/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
cache.redis.port
"""

import os
import json
import os

from config import CONFIG

_REDIS = None
Expand Down
10 changes: 5 additions & 5 deletions lib/cheat_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
cheat_wrapper()
"""

import re
import json
import re

import frontend.ansi
import frontend.html
import postprocessing
from languages_data import LANGUAGE_ALIAS, rewrite_editor_section_name
from routing import get_answers, get_topics_list
from search import find_answers_by_keyword
from languages_data import LANGUAGE_ALIAS, rewrite_editor_section_name
import postprocessing

import frontend.html
import frontend.ansi

def _add_section_name(query):
# temporary solution before we don't find a fixed one
Expand Down
2 changes: 2 additions & 0 deletions lib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@
"""

from __future__ import print_function

import os

from pygments.styles import get_all_styles

#def get_all_styles():
# return []

Expand Down
6 changes: 3 additions & 3 deletions lib/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@

from __future__ import print_function

import sys
import logging
import os
import subprocess
import sys
import textwrap

from globals import fatal
import adapter
import cache

from config import CONFIG
from globals import fatal


def _log(*message):
logging.info(*message)
Expand Down
10 changes: 5 additions & 5 deletions lib/fmt/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@

from __future__ import print_function

import sys
import os
import textwrap
import hashlib
import os
import re
from itertools import groupby, chain
import sys
import textwrap
from itertools import chain, groupby
from subprocess import Popen
from tempfile import NamedTemporaryFile

import cache
from config import CONFIG
from languages_data import VIM_NAME
import cache

FNULL = open(os.devnull, 'w')
TEXT = 0
Expand Down
Loading