2
0
mirror of https://github.com/mhinz/neovim-remote synced 2024-11-11 13:10:34 +00:00

Move address type detection logic into own function

This commit is contained in:
Marco Hinz 2017-09-30 12:52:05 +02:00
parent 3926064c43
commit 538e18be6d
No known key found for this signature in database
GPG Key ID: 1C980A1B657B4A4F

View File

@ -45,12 +45,9 @@ class Neovim():
def attach(self):
try:
if ':' in self.address:
if get_address_type(self.address) == 'tcp':
ip, port = self.address.split(':', 1)
if port.isdigit():
self.server = neovim.attach('tcp', address=ip, port=int(port))
else:
self.server = neovim.attach('socket', path=self.address)
self.server = neovim.attach('tcp', address=ip, port=int(port))
else:
self.server = neovim.attach('socket', path=self.address)
except OSError:
@ -64,7 +61,7 @@ class Neovim():
return True
else:
address = self.address
if not ':' in address:
if get_address_type(address) == 'socket':
if os.path.exists(address) and not stat.S_ISSOCK(os.stat(address).st_mode):
with tempfile.NamedTemporaryFile(dir='/tmp', prefix='nvimsocket_') as f:
self.address = f.name
@ -324,6 +321,16 @@ def print_sockaddrs():
print(addr)
def get_address_type(address):
try:
ip, port = address.split(':', 1)
if port.isdigit():
return 'tcp'
raise ValueError
except ValueError:
return 'socket'
def main(argv=sys.argv, env=os.environ):
options, arguments = parse_args(argv)
address = env.get('NVIM_LISTEN_ADDRESS')