|
1
|
|
|
"""Shared utility functions.""" |
|
2
|
|
|
|
|
3
|
6 |
|
import sys |
|
4
|
6 |
|
from traceback import format_exception |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
6 |
|
def format_exc_skip(skip, limit=None): |
|
8
|
|
|
"""Like traceback.format_exc but allow skipping the first frames.""" |
|
9
|
6 |
|
etype, val, tb = sys.exc_info() |
|
10
|
6 |
|
for i in range(skip): |
|
11
|
6 |
|
tb = tb.tb_next |
|
12
|
6 |
|
return (''.join(format_exception(etype, val, tb, limit))).rstrip() |
|
13
|
|
|
|
|
14
|
|
|
|
|
15
|
|
|
# Taken from SimpleNamespace in python 3 |
|
16
|
6 |
|
class Version: |
|
17
|
|
|
"""Helper class for version info.""" |
|
18
|
|
|
|
|
19
|
6 |
|
def __init__(self, **kwargs): |
|
20
|
|
|
"""Create the Version object.""" |
|
21
|
6 |
|
self.__dict__.update(kwargs) |
|
22
|
|
|
|
|
23
|
6 |
|
def __repr__(self): |
|
24
|
|
|
"""Return str representation of the Version.""" |
|
25
|
|
|
keys = sorted(self.__dict__) |
|
26
|
|
|
items = ("{}={!r}".format(k, self.__dict__[k]) for k in keys) |
|
|
|
|
|
|
27
|
|
|
return "{}({})".format(type(self).__name__, ", ".join(items)) |
|
28
|
|
|
|
|
29
|
6 |
|
def __eq__(self, other): |
|
30
|
|
|
"""Check if version is same as other.""" |
|
31
|
|
|
return self.__dict__ == other.__dict__ |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
6 |
|
def get_client_info(kind, type_, method_spec): |
|
35
|
|
|
"""Returns a tuple describing the client.""" |
|
36
|
6 |
|
name = "python{}-{}".format(sys.version_info[0], kind) |
|
37
|
6 |
|
attributes = {"license": "Apache v2", |
|
38
|
|
|
"website": "github.com/neovim/pynvim"} |
|
39
|
6 |
|
return (name, VERSION.__dict__, type_, method_spec, attributes) |
|
40
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
VERSION = Version(major=0, minor=4, patch=0, prerelease='') |
|
43
|
|
|
|