Vim has a different string implementation of single quotes
| 38 | |
| 39 | |
| 40 | class PythonToVimStr(unicode): |
| 41 | """ Vim has a different string implementation of single quotes """ |
| 42 | __slots__ = [] |
| 43 | |
| 44 | def __new__(cls, obj, encoding='UTF-8'): |
| 45 | if not (is_py3 or isinstance(obj, unicode)): |
| 46 | obj = unicode.__new__(cls, obj, encoding) |
| 47 | |
| 48 | # Vim cannot deal with zero bytes: |
| 49 | obj = obj.replace('\0', '\\0') |
| 50 | return unicode.__new__(cls, obj) |
| 51 | |
| 52 | def __repr__(self): |
| 53 | # this is totally stupid and makes no sense but vim/python unicode |
| 54 | # support is pretty bad. don't ask how I came up with this... It just |
| 55 | # works... |
| 56 | # It seems to be related to that bug: http://bugs.python.org/issue5876 |
| 57 | if unicode is str: |
| 58 | s = self |
| 59 | else: |
| 60 | s = self.encode('UTF-8') |
| 61 | return '"%s"' % s.replace('\\', '\\\\').replace('"', r'\"') |
| 62 | |
| 63 | |
| 64 | class VimError(Exception): |
no outgoing calls
no test coverage detected