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

Switch to python3 host #48

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
2 changes: 1 addition & 1 deletion plugin/vimbits.vim
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
" Copyright 2014-2017 Floobits, Inc


if !has('python')
if !has('python3')
echomsg "Floobits error: no neovim python module. Run `pip install neovim` to fix. For more info, :he nvim-python"
endif

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import neovim

try:
unicode()
str()
except NameError:
unicode = str
str = str
Comment on lines 11 to +14

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this can be dropped. I am guessing it is only there because of s/unicode/str/g

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep, I think it's an artifact of 2to3


try:
import urllib
import urllib.request, urllib.parse, urllib.error
urllib = imp.reload(urllib)
from urllib import request
request = imp.reload(request)
Expand All @@ -24,19 +24,19 @@
URLError = urllib.error.URLError
assert Request and urlopen and HTTPError and URLError
except ImportError:
import urllib2
import urllib.request, urllib.error, urllib.parse
urllib2 = imp.reload(urllib2)
Request = urllib2.Request
urlopen = urllib2.urlopen
HTTPError = urllib2.HTTPError
URLError = urllib2.URLError
Request = urllib.request.Request
urlopen = urllib.request.urlopen
HTTPError = urllib.error.HTTPError
URLError = urllib.error.URLError


from common import api, msg, reactor, utils, shared as G
import editor
import vui
import view
import vim_handler
from .common import api, msg, reactor, utils, shared as G
from . import editor
from . import vui
from . import view
from . import vim_handler


VUI = vui.VUI()
Expand Down Expand Up @@ -266,7 +266,7 @@ def users_in_workspace(self):
if not G.AGENT:
return msg.warn('Not connected to a workspace.')
self.vim.command('echom "Users connected to %s"' % (G.AGENT.workspace,))
for user in G.AGENT.workspace_info['users'].values():
for user in list(G.AGENT.workspace_info['users'].values()):
self.vim.command('echom " %s connected with %s on %s"' % (user['username'], user['client'], user['platform']))

@neovim.command('FlooListMessages', sync=True)
Expand Down Expand Up @@ -296,7 +296,7 @@ def buf_enter(self):
except Exception as e:
msg.debug('Error running on_load patch handler for buf %s: %s' % (buf_id, str(e)))
# NOTE: we call highlight twice in follow mode... thats stupid
for user_id, highlight in G.AGENT.user_highlights.items():
for user_id, highlight in list(G.AGENT.user_highlights.items()):
if highlight['id'] == buf_id:
G.AGENT._on_highlight(highlight)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,31 @@


try:
import __builtin__
str_instances = (str, __builtin__.basestring)
import builtins
str_instances = (str, builtins.str)
except Exception:
str_instances = (str, )

try:
import urllib
import urllib.request, urllib.parse, urllib.error
from urllib.request import Request, urlopen
HTTPError = urllib.error.HTTPError
URLError = urllib.error.URLError
except (AttributeError, ImportError, ValueError):
import urllib2
from urllib2 import Request, urlopen
HTTPError = urllib2.HTTPError
URLError = urllib2.URLError
import urllib.request, urllib.error, urllib.parse
from urllib.request import Request, urlopen
HTTPError = urllib.error.HTTPError
URLError = urllib.error.URLError
Comment on lines 23 to +32

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this can be reduced to some qualified imports.


try:
from .. import editor
from . import cert, msg, shared as G, utils
except ImportError:
import cert
from . import cert
import editor
import msg
import shared as G
import utils
from . import msg
from . import shared as G
from . import utils


def get_basic_auth(host):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import traceback

try:
unicode()
str()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String will now always be there. This block and the code below predicating on the existence of str should be able to be removed / flattened-out.

except NameError:
unicode = None
str = None


def str_e(e):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
message = getattr(e, "message", None)
if not (message and unicode):
if not (message and str):
return str(e)
try:
return unicode(message, "utf8").encode("utf8")
return str(message, "utf8").encode("utf8")
except:
return message.encode("utf8")

Expand Down Expand Up @@ -55,7 +55,7 @@ def test2(excp):
assert isinstance(stre, str)
print(stre)

tests = [Exception("asdf"), Exception(u"aß∂ƒ"), Exception(u"asdf"), Exception(b"asdf1234")]
tests = [Exception("asdf"), Exception("aß∂ƒ"), Exception("asdf"), Exception(b"asdf1234")]
for t in tests:
test(t)
if getattr(sys, "exc_clear", None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def link_account(self, context, host, cb):
try:
reactor.reactor.connect(agent, host, G.DEFAULT_PORT, True)
except Exception as e:
print(str_e(e))
print((str_e(e)))

@utils.inlined_callbacks
def create_or_link_account(self, context, host, force, cb):
Expand Down Expand Up @@ -106,7 +106,7 @@ def create_or_link_account(self, context, host, force, cb):
try:
reactor.reactor.connect(agent, host, G.DEFAULT_PORT, True)
except Exception as e:
print(str_e(e))
print((str_e(e)))

def open_workspace(self):
if not self.agent:
Expand Down Expand Up @@ -295,7 +295,7 @@ def follow_user(self, context, cb=None):
users = self.agent.workspace_info.get('users')
userNames = set()
me = self.agent.get_username_by_id(self.agent.workspace_info['user_id'])
for user in users.values():
for user in list(users.values()):
username = user['username']
if username == me:
continue
Expand Down Expand Up @@ -479,7 +479,7 @@ def _get_host(self, context, cb):
if len(hosts) == 1:
host = hosts[0]
else:
little = ["%s on %s" % (a['username'], h) for h, a in G.AUTH.items()]
little = ["%s on %s" % (a['username'], h) for h, a in list(G.AUTH.items())]
(host, index) = yield self.user_select, context, 'Which Floobits account should be used?', hosts, little
if not host:
cb(None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from ..protocols import no_reconnect
assert api and G and msg and utils
except (ImportError, ValueError):
import base
from . import base
from floo import editor
from floo.common.protocols import no_reconnect
from floo.common.exc_fmt import str_e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from ..protocols import no_reconnect
assert api and G and utils
except (ImportError, ValueError):
import base
from . import base
from floo import editor
from floo.common.protocols import no_reconnect
from floo.common.exc_fmt import str_e
Expand Down Expand Up @@ -71,4 +71,4 @@ def _on_credentials(self, data):
try:
self.stop()
except Exception as e:
print(str_e(e))
print((str_e(e)))
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from ... import editor
from ..protocols import floo_proto
except (ImportError, ValueError) as e:
import base
from . import base
from floo import editor
from floo.common.lib import DMP
from floo.common.reactor import reactor
Expand All @@ -24,9 +24,9 @@
from floo.common.protocols import floo_proto

try:
unicode()
str()
except NameError:
unicode = str
str = str

try:
import io
Expand Down Expand Up @@ -328,7 +328,7 @@ def _initial_upload(self, ig, missing_bufs, changed_bufs, cb):
for buf_id in missing_buf_ids:
self.send({'name': 'delete_buf', 'id': buf_id})

for p, buf_id in self.paths_to_ids.items():
for p, buf_id in list(self.paths_to_ids.items()):
if p in files:
files.discard(p)
# TODO: recalculate size (need size in room_info)
Expand Down Expand Up @@ -372,7 +372,7 @@ def _scan_dir(self, bufs, ig, read_only):
if not read_only:
new_files = set([utils.to_rel_path(x) for x in ig.list_paths()])

for buf_id, buf in bufs.items():
for buf_id, buf in list(bufs.items()):
buf_id = int(buf_id) # json keys must be strings
buf_path = utils.get_full_path(buf['path'])
view = self.get_view(buf_id)
Expand Down Expand Up @@ -456,14 +456,14 @@ def _on_room_info(self, data):

ig = ignore.create_ignore_tree(G.PROJECT_PATH)
G.IGNORE = ig
for buf_id, buf in data['bufs'].items():
for buf_id, buf in list(data['bufs'].items()):
buf_id = int(buf_id) # json keys must be strings
self.bufs[buf_id] = buf
self.paths_to_ids[buf['path']] = buf_id
changed_bufs, missing_bufs, new_files = self._scan_dir(data['bufs'], ig, read_only)

ignored = []
for p, buf_id in self.paths_to_ids.items():
for p, buf_id in list(self.paths_to_ids.items()):
if p not in new_files:
ignored.append(p)
new_files.discard(p)
Expand Down Expand Up @@ -540,7 +540,7 @@ def refresh_workspace(self):
read_only = 'patch' not in self.workspace_info['perms']
changed_bufs, missing_bufs, new_files = self._scan_dir(self.bufs, G.IGNORE, read_only)
ignored = []
for p, buf_id in self.paths_to_ids.items():
for p, buf_id in list(self.paths_to_ids.items()):
if p not in new_files:
ignored.append(p)
new_files.discard(p)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .. protocols import tcp_server
except (ImportError, ValueError):
from floo.common.protocols import tcp_server
import base
from . import base


class TCPServerHandler(base.BaseHandler):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
from .exc_fmt import str_e
assert msg and str_e and utils
except ImportError:
import msg
from exc_fmt import str_e
from . import msg
from .exc_fmt import str_e

IGNORE_FILES = ['.gitignore', '.hgignore', '.ignore', '.flooignore']
HIDDEN_WHITELIST = ['.floo'] + IGNORE_FILES
Expand Down Expand Up @@ -166,14 +166,14 @@ def load(self, ignore_file):

def get_children(self):
children = list(self.children.values())
for c in self.children.values():
for c in list(self.children.values()):
children += c.get_children()
return children

def list_paths(self):
for f in self.files:
yield os.path.join(self.path, f)
for c in self.children.values():
for c in list(self.children.values()):
for p in c.list_paths():
yield p

Expand Down Expand Up @@ -203,7 +203,7 @@ def _is_ignored(self, rel_path, is_dir, log):
if not is_dir and file_name in HIDDEN_WHITELIST:
return False

for ignore_file, patterns in self.ignores.items():
for ignore_file, patterns in list(self.ignores.items()):
for pattern in patterns:
orig_pattern = pattern
negate = False
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
try:
from . import dmp_monkey
except ImportError:
import dmp_monkey
from . import dmp_monkey

dmp_monkey.monkey_patch()

try:
from . import diff_match_patch
except ImportError:
import diff_match_patch
from . import diff_match_patch

DMP = diff_match_patch.diff_match_patch()
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ def unquote_py3(x):
return parse.unquote(x)
unquote = unquote_py3
str_instances = str
unichr = chr
chr = chr
except ImportError:
import urllib as parse

def unquote_py2(x):
return parse.unquote(x.encode('utf-8')).decode('utf-8')
unquote = unquote_py2
import __builtin__
str_instances = (str, __builtin__.basestring)
import builtins
str_instances = (str, builtins.str)


class diff_match_patch:
Expand Down Expand Up @@ -439,11 +439,11 @@ def diff_linesToCharsMunge(text):
lineStart = lineEnd + 1

if line in lineHash:
chars.append(unichr(lineHash[line]))
chars.append(chr(lineHash[line]))
else:
lineArray.append(line)
lineHash[line] = len(lineArray) - 1
chars.append(unichr(len(lineArray) - 1))
chars.append(chr(len(lineArray) - 1))
return "".join(chars)

chars1 = diff_linesToCharsMunge(text1)
Expand Down Expand Up @@ -1642,7 +1642,7 @@ def patch_addPadding(self, patches):
paddingLength = self.Patch_Margin
nullPadding = ""
for x in range(1, paddingLength + 1):
nullPadding += unichr(x)
nullPadding += chr(x)

# Bump all the patches forward.
for patch in patches:
Expand Down
Loading