efficient vim config
[dotfiles/.git] / .local / lib / python2.7 / site-packages / pynvim / util.py
1 """Shared utility functions."""
2
3 import sys
4 from traceback import format_exception
5
6
7 def format_exc_skip(skip, limit=None):
8     """Like traceback.format_exc but allow skipping the first frames."""
9     etype, val, tb = sys.exc_info()
10     for i in range(skip):
11         tb = tb.tb_next
12     return (''.join(format_exception(etype, val, tb, limit))).rstrip()
13
14
15 # Taken from SimpleNamespace in python 3
16 class Version:
17     """Helper class for version info."""
18
19     def __init__(self, **kwargs):
20         """Create the Version object."""
21         self.__dict__.update(kwargs)
22
23     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     def __eq__(self, other):
30         """Check if version is same as other."""
31         return self.__dict__ == other.__dict__
32
33
34 def get_client_info(kind, type_, method_spec):
35     """Returns a tuple describing the client."""
36     name = "python{}-{}".format(sys.version_info[0], kind)
37     attributes = {"license": "Apache v2",
38                   "website": "github.com/neovim/pynvim"}
39     return (name, VERSION.__dict__, type_, method_spec, attributes)
40
41
42 VERSION = Version(major=0, minor=4, patch=2, prerelease='')