示例#1
0
 def start(self):
     Middleware.start(self)
     self.conns_per_min = netius.conf("CONNS_PER_MIN", self.conns_per_min, cast = int)
     self.whitelist = netius.conf("WHITELIST", self.whitelist, cast = list)
     self.blacklist = []
     self.conn_map = dict()
     self.minute = int(time.time() // 60)
     self.owner.bind("connection_c", self.on_connection_c)
示例#2
0
    def test_none(self):
        netius.conf_s("AGE", None)
        result = netius.conf("AGE", cast=int)

        self.assertEqual(result, None)

        result = netius.conf("HEIGHT", cast=int)

        self.assertEqual(result, None)
示例#3
0
    def test_none(self):
        netius.conf_s("AGE", None)
        result = netius.conf("AGE", cast = int)

        self.assertEqual(result, None)

        result = netius.conf("HEIGHT", cast = int)

        self.assertEqual(result, None)
示例#4
0
 def start(self):
     Middleware.start(self)
     self.conns_per_min = netius.conf("CONNS_PER_MIN",
                                      self.conns_per_min,
                                      cast=int)
     self.whitelist = netius.conf("WHITELIST", self.whitelist, cast=list)
     self.blacklist = []
     self.conn_map = dict()
     self.minute = int(time.time() // 60)
     self.owner.bind("connection_c", self.on_connection_c)
示例#5
0
    def test_basic(self):
        netius.conf_s("NAME", "name")
        result = netius.conf("NAME")

        self.assertEqual(result, "name")

        result = netius.conf("NAME", cast = str)

        self.assertEqual(result, "name")
        self.assertEqual(type(result), str)

        result = netius.conf("NAME", cast = "str")

        self.assertEqual(result, "name")
        self.assertEqual(type(result), str)

        netius.conf_s("AGE", "10")
        result = netius.conf("AGE", cast = int)

        self.assertEqual(result, 10)
        self.assertEqual(type(result), int)

        result = netius.conf("AGE", cast = "int")

        self.assertEqual(result, 10)
        self.assertEqual(type(result), int)

        result = netius.conf("AGE", cast = str)

        self.assertEqual(result, "10")
        self.assertEqual(type(result), str)

        result = netius.conf("HEIGHT")

        self.assertEqual(result, None)
示例#6
0
    def test_basic(self):
        netius.conf_s("NAME", "name")
        result = netius.conf("NAME")

        self.assertEqual(result, "name")

        result = netius.conf("NAME", cast=str)

        self.assertEqual(result, "name")
        self.assertEqual(type(result), str)

        result = netius.conf("NAME", cast="str")

        self.assertEqual(result, "name")
        self.assertEqual(type(result), str)

        netius.conf_s("AGE", "10")
        result = netius.conf("AGE", cast=int)

        self.assertEqual(result, 10)
        self.assertEqual(type(result), int)

        result = netius.conf("AGE", cast="int")

        self.assertEqual(result, 10)
        self.assertEqual(type(result), int)

        result = netius.conf("AGE", cast=str)

        self.assertEqual(result, "10")
        self.assertEqual(type(result), str)

        result = netius.conf("HEIGHT")

        self.assertEqual(result, None)
示例#7
0
文件: mjpg.py 项目: maxssage/netius
 def on_frame(client, parser, data):
     global index
     base_path = netius.conf("IMAGES_PATH", "images")
     base_path = os.path.abspath(base_path)
     base_path = os.path.normpath(base_path)
     if not os.path.exists(base_path): os.makedirs(base_path)
     path = os.path.join(base_path, "%08d.jpg" % index)
     file = open(path, "wb")
     try: file.write(data)
     finally: file.close()
     index += 1
示例#8
0
 def on_frame(protocol, data):
     global index
     index += 1
     if index >= limit: return protocol.close()
     base_path = netius.conf("IMAGES_PATH", "images")
     base_path = os.path.abspath(base_path)
     base_path = os.path.normpath(base_path)
     if not os.path.exists(base_path): os.makedirs(base_path)
     path = os.path.join(base_path, "%08d.jpg" % index)
     file = open(path, "wb")
     try: file.write(data)
     finally: file.close()
     print("Saved frame %08d of %d bytes" % (index, len(data)))
示例#9
0
 def on_frame(protocol, data):
     global index
     index += 1
     if index >= limit: return protocol.close()
     base_path = netius.conf("IMAGES_PATH", "images")
     base_path = os.path.abspath(base_path)
     base_path = os.path.normpath(base_path)
     if not os.path.exists(base_path): os.makedirs(base_path)
     path = os.path.join(base_path, "%08d.jpg" % index)
     file = open(path, "wb")
     try: file.write(data)
     finally: file.close()
     print("Saved frame %08d of %d bytes" % (index, len(data)))
示例#10
0
 def on_frame(client, parser, data):
     global index
     base_path = netius.conf("IMAGES_PATH", "images")
     base_path = os.path.abspath(base_path)
     base_path = os.path.normpath(base_path)
     if not os.path.exists(base_path): os.makedirs(base_path)
     path = os.path.join(base_path, "%08d.jpg" % index)
     file = open(path, "wb")
     try:
         file.write(data)
     finally:
         file.close()
     index += 1
示例#11
0
    def _build_hosts(self, alias = True):
        # tries to retrieve the complete set of configuration
        # values associated with the port suffix, this represents
        # the possible linked container addresses
        linked = netius.conf_suffix("_PORT")

        # iterates over the linked values, validating them and adding
        # them to the list of registered hosts
        for name, host in netius.legacy.iteritems(linked):
            # retrieves the name part of the configuration name
            # and converts it into lower cased value, note that
            # an extra dashed version is created, so that a proper
            # alias may be created for such naming
            base = name[:-5].lower()
            base_dash = base.replace("_", "-")

            # "builds" the name reference of the service and tries
            # to retrieve it from the configuration, it should exist
            # in case this port value represent a service
            name_ref = base.upper() + "_NAME"
            name_value = netius.conf(name_ref, None)
            if not name_value: continue

            # runs a series of validation on both the base and name
            # value to make sure that this value represents a valid
            # linked service/container
            # linked service/container (valid name reference found)
            if name.endswith("_ENV_PORT"): continue
            if not name.find("_ENV_") == -1: continue
            if base[-1].isdigit() and name_value[-1].isdigit(): continue

            # validates that the provided host is a valid URL value and
            # if that's not the case continues the loop (ignores)
            if not self._valid_url(host): continue

            # replaces the prefix of the reference (assumes HTTP) and
            # then adds the base value to the registered hosts
            host = host.replace("tcp://", "http://")
            host = str(host)
            self.hosts[base] = host

            # validates that the dashed version of the name is not the
            # same as the base one (at least one underscore) and if that's
            # not the case skips the current iteration
            if base == base_dash: continue

            # checks if the alias based registration is enabled and adds
            # the dashed version as an alias for such case or as an host
            # otherwise (static registration)
            if alias: self.alias[base_dash] = base
            else: self.hosts[base_dash] = host
示例#12
0
    def _build_hosts(self, alias=True):
        # tries to retrieve the complete set of configuration
        # values associated with the port suffix, this represents
        # the possible linked container addresses
        linked = netius.conf_suffix("_PORT")

        # iterates over the linked values, validating them and adding
        # them to the list of registered hosts
        for name, host in netius.legacy.iteritems(linked):
            # retrieves the name part of the configuration name
            # and converts it into lower cased value, note that
            # an extra dashed version is created, so that a proper
            # alias may be created for such naming
            base = name[:-5].lower()
            base_dash = base.replace("_", "-")

            # "builds" the name reference of the service and tries
            # to retrieve it from the configuration, it should exist
            # in case this port value represent a service
            name_ref = base.upper() + "_NAME"
            name_value = netius.conf(name_ref, None)
            if not name_value: continue

            # runs a series of validation on both the base and name
            # value to make sure that this value represents a valid
            # linked service/container
            # linked service/container (valid name reference found)
            if name.endswith("_ENV_PORT"): continue
            if not name.find("_ENV_") == -1: continue
            if base[-1].isdigit() and name_value[-1].isdigit(): continue

            # validates that the provided host is a valid URL value and
            # if that's not the case continues the loop (ignores)
            if not self._valid_url(host): continue

            # replaces the prefix of the reference (assumes HTTP) and
            # then adds the base value to the registered hosts
            host = host.replace("tcp://", "http://")
            host = str(host)
            self.hosts[base] = host

            # validates that the dashed version of the name is not the
            # same as the base one (at least one underscore) and if that's
            # not the case skips the current iteration
            if base == base_dash: continue

            # checks if the alias based registration is enabled and adds
            # the dashed version as an alias for such case or as an host
            # otherwise (static registration)
            if alias: self.alias[base_dash] = base
            else: self.hosts[base_dash] = host
示例#13
0
 def load_registry(cls):
     return netius.conf("REGISTRY", {})
示例#14
0
 def load_registry(cls):
     return netius.conf("REGISTRY", {})
示例#15
0
 def start(self):
     Middleware.start(self)
     self.blacklist = netius.conf("BLACKLIST", self.blacklist, cast = list)
     self.whitelist = netius.conf("WHITELIST", self.whitelist, cast = list)
     self.owner.bind("connection_c", self.on_connection_c)
示例#16
0
        # instance to the protocol defined by the current instance
        return loop, self

class APNClient(netius.ClientAgent):

    protocol = APNProtocol

    @classmethod
    def notify_s(cls, token, loop = None, **kwargs):
        protocol = cls.protocol()
        return protocol.notify(token, loop = loop, **kwargs)

if __name__ == "__main__":
    def on_finish(protocol):
        netius.compat_loop(loop).stop()

    token = netius.conf("APN_TOKEN", None)
    key_file = netius.conf("APN_KEY_FILE", None)
    cer_file = netius.conf("APN_CER_FILE", None)

    loop, protocol = APNClient.notify_s(
        token, key_file = key_file, cer_file = cer_file
    )

    protocol.bind("finish", on_finish)

    loop.run_forever()
    loop.close()
else:
    __path__ = []
示例#17
0
 def start(self):
     Middleware.start(self)
     self.version = netius.conf("PROXY_VERSION", self.version, cast = int)
     self.owner.bind("connection_c", self.on_connection_c)
示例#18
0
文件: apn.py 项目: sitedata/netius
        # instance to the protocol defined by the current instance
        return loop, self

class APNClient(netius.ClientAgent):

    protocol = APNProtocol

    @classmethod
    def notify_s(cls, token, loop = None, **kwargs):
        protocol = cls.protocol()
        return protocol.notify(token, loop = loop, **kwargs)

if __name__ == "__main__":
    def on_finish(protocol):
        netius.compat_loop(loop).stop()

    token = netius.conf("APN_TOKEN", None)
    key_file = netius.conf("APN_KEY_FILE", None)
    cer_file = netius.conf("APN_CER_FILE", None)

    loop, protocol = APNClient.notify_s(
        token, key_file = key_file, cer_file = cer_file
    )

    protocol.bind("finish", on_finish)

    loop.run_forever()
    loop.close()
else:
    __path__ = []
示例#19
0
    def on_frame(protocol, data):
        global index
        index += 1
        if index >= limit: return protocol.close()
        base_path = netius.conf("IMAGES_PATH", "images")
        base_path = os.path.abspath(base_path)
        base_path = os.path.normpath(base_path)
        if not os.path.exists(base_path): os.makedirs(base_path)
        path = os.path.join(base_path, "%08d.jpg" % index)
        file = open(path, "wb")
        try: file.write(data)
        finally: file.close()
        print("Saved frame %08d of %d bytes" % (index, len(data)))

    def on_finish(protocol):
        netius.compat_loop(loop).stop()

    url = netius.conf("MJPG_URL", "http://euglena.stanford.edu:20005/?action=stream")

    client = MJPGClient()
    loop, protocol = client.get(url)

    protocol.bind("frame", on_frame)
    protocol.bind("finish", on_finish)

    loop.run_forever()
    loop.close()
else:
    __path__ = []
示例#20
0
文件: proxy.py 项目: sitedata/netius
 def start(self):
     Middleware.start(self)
     self.version = netius.conf("PROXY_VERSION", self.version, cast=int)
     self.owner.bind("connection_c", self.on_connection_c)
示例#21
0
 def start(self):
     Middleware.start(self)
     self.period = netius.conf("ANNOYER_PERIOD", self.period, cast = float)
     self._thread = threading.Thread(target = self._run)
     self._thread.start()
示例#22
0
    def on_frame(protocol, data):
        global index
        index += 1
        if index >= limit: return protocol.close()
        base_path = netius.conf("IMAGES_PATH", "images")
        base_path = os.path.abspath(base_path)
        base_path = os.path.normpath(base_path)
        if not os.path.exists(base_path): os.makedirs(base_path)
        path = os.path.join(base_path, "%08d.jpg" % index)
        file = open(path, "wb")
        try: file.write(data)
        finally: file.close()
        print("Saved frame %08d of %d bytes" % (index, len(data)))

    def on_finish(protocol):
        netius.compat_loop(loop).stop()

    url = netius.conf("MJPG_URL", "http://euglena.stanford.edu:20005/?action=stream")

    client = MJPGClient()
    loop, protocol = client.get(url)

    protocol.bind("frame", on_frame)
    protocol.bind("finish", on_finish)

    loop.run_forever()
    loop.close()
else:
    __path__ = []
示例#23
0
 def start(self):
     Middleware.start(self)
     self.period = netius.conf("ANNOYER_PERIOD", self.period, cast = float)
     self._thread = threading.Thread(target = self._run)
     self._thread.start()
示例#24
0
 def start(self):
     Middleware.start(self)
     self.blacklist = netius.conf("BLACKLIST", self.blacklist, cast=list)
     self.whitelist = netius.conf("WHITELIST", self.whitelist, cast=list)
     self.owner.bind("connection_c", self.on_connection_c)