当前位置: 首页>>代码示例>>Python>>正文


Python Configuration.loads方法代码示例

本文整理汇总了Python中configuration.Configuration.loads方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.loads方法的具体用法?Python Configuration.loads怎么用?Python Configuration.loads使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在configuration.Configuration的用法示例。


在下文中一共展示了Configuration.loads方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Server

# 需要导入模块: from configuration import Configuration [as 别名]
# 或者: from configuration.Configuration import loads [as 别名]
class Server(Thread):
    """ SQLRelay server """

    def __init__(self, address, port=PORT, delay=2, timeout=TIMEOUT, listener=None):
        Thread.__init__(self)
        self.listener = listener
        self.a_lock = thread.allocate_lock()
        self.address = address
        self.port = port
        self.timeout = timeout
        self.socket = None
        self.running = True
        self.status = None
        self.configuration = None
        self.tnsnames = None
        self.tns_nodes = {}
        self.ora_nodes = {}
        self.link_tns = {}
        self.delay = delay

    def connect(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.setblocking(1)
        self.socket.settimeout(5.0)
        try:
            self.socket.connect_ex((self.address, self.port))
        except Exception:
            self.socket = None
        return self.socket != None

    def close(self):
        print "close %s" % self.address
        if self.socket:
            self.socket.close()
        self.socket = None

    def recv(self):
        reponse = ""
        try:
            strg = ""
            while True:
                c = self.socket.recv(1)
                if c == "\n" or c == "":
                    break
                else:
                    strg += c
            if c == "":
                return "(null)"
            try:
                size = atoi(strg)
            except:
                return "ERROR DATA %s" % strg
            while len(reponse) < size:
                reponse += self.socket.recv(4096)
        except Exception as e:
            syslog(LOG_ERR, str(e))
            self.socket = None
        return reponse

    def login(self):
        result = False
        try:
            self.recv().strip()
            self.socket.send("login sqlrelay sqlrelay\n")
            result = self.recv().strip() == "OK"
        except Exception as e:
            syslog(LOG_ERR, str(e))
            self.socket = None
        return result

    def load_status(self):
        response = None
        try:
            self.socket.send("status\n")
            response = self.recv()
        except Exception as e:
            syslog(LOG_ERR, "%s %s" % (self.address, e))
            self.socket = None

        if response:
            status = None
            try:
                status = json.loads(response, encoding="ascii")
            except Exception as e:
                syslog(LOG_ERR, "%s [%s] %s" % (self.address, response, e))

            if status:
                self.a_lock.acquire()
                self.status = status
                self.a_lock.release()
                if self.listener:
                    self.listener.on_status(self)

    def load_configuration(self):
        """ lecture du fichier sqlrelay.conf
            recuperation du ora_sid
        """
        self.socket.send("conf\n")
        response = self.recv()
        self.configuration = Configuration()
#.........这里部分代码省略.........
开发者ID:fredsobon,项目名称:stuff,代码行数:103,代码来源:server.py


注:本文中的configuration.Configuration.loads方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。