Skip to content

Commit

Permalink
Merge pull request #152 from tony/libtmux
Browse files Browse the repository at this point in the history
Decouple tmux API into libtmux
  • Loading branch information
tony committed May 22, 2016
2 parents 50d576c + 1b9227b commit cbcbf34
Show file tree
Hide file tree
Showing 22 changed files with 586 additions and 443 deletions.
4 changes: 4 additions & 0 deletions libtmux/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .pane import Pane
from .server import Server
from .session import Session
from .window import Window
91 changes: 91 additions & 0 deletions libtmux/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -*- coding: utf8 -*-
import sys

PY2 = sys.version_info[0] == 2

_identity = lambda x: x


if PY2:
unichr = unichr
text_type = unicode
string_types = (str, unicode)
integer_types = (int, long)
from urllib import urlretrieve

text_to_native = lambda s, enc: s.encode(enc)

iterkeys = lambda d: d.iterkeys()
itervalues = lambda d: d.itervalues()
iteritems = lambda d: d.iteritems()

from cStringIO import StringIO as BytesIO
from StringIO import StringIO
import cPickle as pickle
import ConfigParser as configparser

from itertools import izip, imap
range_type = xrange

cmp = cmp

input = raw_input
from string import lower as ascii_lowercase
import urlparse

exec('def reraise(tp, value, tb=None):\n raise tp, value, tb')

def implements_to_string(cls):
cls.__unicode__ = cls.__str__
cls.__str__ = lambda x: x.__unicode__().encode('utf-8')
return cls

def console_to_str(s):
return s.decode('utf_8')

else:
unichr = chr
text_type = str
string_types = (str,)
integer_types = (int, )

text_to_native = lambda s, enc: s

iterkeys = lambda d: iter(d.keys())
itervalues = lambda d: iter(d.values())
iteritems = lambda d: iter(d.items())

from io import StringIO, BytesIO
import pickle
import configparser

izip = zip
imap = map
range_type = range

cmp = lambda a, b: (a > b) - (a < b)

input = input
from string import ascii_lowercase
import urllib.parse as urllib
import urllib.parse as urlparse
from urllib.request import urlretrieve

console_encoding = sys.__stdout__.encoding

implements_to_string = _identity

def console_to_str(s):
""" From pypa/pip project, pip.backwardwardcompat. License MIT. """
try:
return s.decode(console_encoding)
except UnicodeDecodeError:
return s.decode('utf_8')

def reraise(tp, value, tb=None):
if value.__traceback__ is not tb:
raise(value.with_traceback(tb))
raise value


number_types = integer_types + (float,)
Loading

0 comments on commit cbcbf34

Please sign in to comment.