def __init__(self, inputs, group_operator, **kwargs):
        field = kwargs.get('field', 'day') 
        width = int(kwargs.get("width", 1))
        slide = int(kwargs.get("slide", width))
        inclusive = make_inclusive(kwargs.get("inclusive", "inc-exc"))
        snap_times = bool(kwargs.get("snap_times", True))
        skip_empty = util.to_bool(kwargs.get("skip_empty", True))

        if not field in DT_FIELDS:
            raise core.SmapException("Invalid datetime field: " + field)
        if not slide <= width:
            raise core.SmapException("window: Cannot slide more than the window width!")

        self.inclusive = make_inclusive(inclusive)
        if self.inclusive[0] == False:
            raise core.SmapException("Open intervals at the start are not supported")

        self.tzs = map(lambda x: dtutil.gettz(x['Properties/Timezone']), inputs)
        self.ops = map(lambda x: group_operator([x]), inputs)
        # self.ops = [[op([x]) for op in ops] for x in inputs]
        self.comparator = self.make_bin_comparator(field, width)
        self.snapper = make_bin_snapper(field, slide)
        self.snap_times = snap_times
        self.skip_empty = skip_empty
        self.bin_width = datetime.timedelta(**{field + 's': width})
        self.bin_slide = datetime.timedelta(**{field + 's': slide})
        self.name = "window(%s, field=%s, width=%i, inclusive=%s, snap_times=%s)" % ( \
            str(self.ops[0]), field, width, str(inclusive), str(snap_times))
        Operator.__init__(self, inputs, 
                          util.flatten(map(operator.attrgetter('outputs'), 
                                           self.ops)))
        self.reset()
Exemple #2
0
    def __init__(self, inputs, group_operator, **kwargs):
        field = kwargs.get('field', 'day')
        width = int(kwargs.get("width", 1))
        slide = int(kwargs.get("slide", width))
        inclusive = make_inclusive(kwargs.get("inclusive", "inc-exc"))
        snap_times = bool(kwargs.get("snap_times", True))
        skip_empty = util.to_bool(kwargs.get("skip_empty", True))

        if not field in DT_FIELDS:
            raise core.SmapException("Invalid datetime field: " + field)
        if not slide <= width:
            raise core.SmapException(
                "window: Cannot slide more than the window width!")

        self.inclusive = make_inclusive(inclusive)
        if self.inclusive[0] == False:
            raise core.SmapException(
                "Open intervals at the start are not supported")

        self.tzs = map(lambda x: dtutil.gettz(x['Properties/Timezone']),
                       inputs)
        self.ops = map(lambda x: group_operator([x]), inputs)
        # self.ops = [[op([x]) for op in ops] for x in inputs]
        self.comparator = self.make_bin_comparator(field, width)
        self.snapper = make_bin_snapper(field, slide)
        self.snap_times = snap_times
        self.skip_empty = skip_empty
        self.bin_width = datetime.timedelta(**{field + 's': width})
        self.bin_slide = datetime.timedelta(**{field + 's': slide})
        self.name = "window(%s, field=%s, width=%i, inclusive=%s, snap_times=%s)" % ( \
            str(self.ops[0]), field, width, str(inclusive), str(snap_times))
        Operator.__init__(
            self, inputs,
            util.flatten(map(operator.attrgetter('outputs'), self.ops)))
        self.reset()
Exemple #3
0
        def __init__(self, opts, verifyCallback=defaultVerifyCallback):
            if not 'key' in opts or not 'cert' in opts:
                raise ValueError("Cannot create ssl context without key and certificate files")

            DefaultOpenSSLContextFactory.__init__(self, 
                                                  os.path.expanduser(opts["key"]), 
                                                  os.path.expanduser(opts["cert"]))
            ctx = self.getContext()
            if 'verify' in opts and to_bool(opts['verify']):
                ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
                               verifyCallback)
            if 'ca' in opts:
                ctx.load_verify_locations(os.path.expanduser(opts["ca"]))
Exemple #4
0
        def getContext(self, hostname, port): 
            self.method = SSL.SSLv23_METHOD
            ctx = ClientContextFactory.getContext(self)

            if 'cert' in self.ssl_opts and 'key' in self.ssl_opts:
                ctx.use_certificate_file(os.path.expanduser(self.ssl_opts['cert']))
                ctx.use_privatekey_file(os.path.expanduser(self.ssl_opts['key']))

            if 'verify' in self.ssl_opts and to_bool(self.ssl_opts['verify']):
                ctx.set_verify(SSL.VERIFY_PEER | SSL.VERIFY_FAIL_IF_NO_PEER_CERT,
                               self.verifyCallback)
            if 'ca' in self.ssl_opts:
                ctx.load_verify_locations(os.path.expanduser(self.ssl_opts['CAFile']))

            return ctx