mirror of
https://github.com/mhinz/neovim-remote
synced 2024-11-11 13:10:34 +00:00
Refactoring: sanitize address
This commit is contained in:
parent
83b9d014f7
commit
df89d17f56
29
nvr/nvr.py
29
nvr/nvr.py
@ -61,17 +61,9 @@ class Neovim():
|
||||
if self.server:
|
||||
return True
|
||||
|
||||
address = self.address
|
||||
if get_address_type(address) == 'socket' and os.path.exists(address):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(address)
|
||||
except:
|
||||
with tempfile.NamedTemporaryFile(dir='/tmp', prefix='nvimsocket_') as f:
|
||||
self.address = f.name
|
||||
|
||||
if not silent and not self._msg_shown:
|
||||
self._show_msg(address)
|
||||
self._show_msg(self.address)
|
||||
self._msg_shown = True
|
||||
|
||||
return False
|
||||
@ -170,6 +162,23 @@ class Neovim():
|
||||
""".format(o, o, o, o, self.address)))
|
||||
|
||||
|
||||
def sanitize_address(address, env):
|
||||
if not address:
|
||||
address = env.get('NVIM_LISTEN_ADDRESS')
|
||||
if not address:
|
||||
address = '/tmp/nvimsocket'
|
||||
|
||||
if get_address_type(address) == 'socket' and os.path.exists(address):
|
||||
try:
|
||||
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
sock.connect(address)
|
||||
except:
|
||||
with tempfile.NamedTemporaryFile(dir='/tmp', prefix='nvimsocket_') as f:
|
||||
address = f.name
|
||||
|
||||
return address
|
||||
|
||||
|
||||
def parse_args(argv):
|
||||
form_class = argparse.RawDescriptionHelpFormatter
|
||||
usage = '{} [arguments]'.format(argv[0])
|
||||
@ -363,6 +372,8 @@ def main(argv=sys.argv, env=os.environ):
|
||||
print_sockaddrs()
|
||||
return
|
||||
|
||||
address = sanitize_address(options.servername, env)
|
||||
|
||||
nvim = Neovim(address, options.s)
|
||||
nvim.attach()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user