示例#1
0
class PlexClient(object):
    __interfaces = None

    def __init__(self):
        # Construct interfaces
        self.http = HttpClient(self)
        self.configuration = ConfigurationManager()

        self.__interfaces = construct_map(self)

        # Discover modules
        ObjectManager.construct()

    @property
    def base_url(self):
        host = self.configuration.get('server.host', '127.0.0.1')
        port = self.configuration.get('server.port', 32400)

        return 'http://%s:%s' % (host, port)

    def __getitem__(self, path):
        parts = path.strip('/').split('/')

        cur = self.__interfaces
        parameters = []

        while parts and type(cur) is dict:
            key = parts.pop(0)

            if key == '*':
                key = None
            elif key not in cur:
                if None in cur:
                    parameters.append(key)

                    cur = cur[None]
                    continue

                return None

            cur = cur[key]

        while type(cur) is dict:
            cur = cur.get(None)

        if parts:
            parameters.extend(parts)

        if parameters:
            return InterfaceProxy(cur, parameters)

        return cur

    def __getattr__(self, name):
        interface = self.__interfaces.get(None)

        if not interface:
            raise Exception("Root interface not found")

        return getattr(interface, name)
示例#2
0
    def __init__(self):
        # Construct interfaces
        self.http = HttpClient(self)
        self.configuration = ConfigurationManager()

        self.__interfaces = construct_map(self)

        # Discover modules
        ObjectManager.construct()
示例#3
0
    def __init__(self):
        # Construct interfaces
        self.http = HttpClient(self)
        self.configuration = ConfigurationManager()

        self.__interfaces = construct_map(self)

        # Discover modules
        ObjectManager.construct()