Exemplo n.º 1
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(
         'on' if mole.verbose else 'off').line_break())
     self.params.add_parameter(
         'on', Parameter(lambda mole, _: self.set_verbose(mole, True)))
     self.params.add_parameter(
         'off', Parameter(lambda mole, _: self.set_verbose(mole, False)))
Exemplo n.º 2
0
 def __init__(self):
     self.params = Parameter(
         lambda mole, _: output_manager.normal(mole.mode).line_break())
     self.params.add_parameter(
         'union', Parameter(lambda mole, _: mole.set_mode('union')))
     self.params.add_parameter(
         'blind', Parameter(lambda mole, _: mole.set_mode('blind')))
Exemplo n.º 3
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(
         output_manager.result_output).line_break())
     self.params.add_parameter(
         'pretty', Parameter(lambda mole, _: self.set_output('pretty')))
     self.params.add_parameter(
         'plain', Parameter(lambda mole, _: self.set_output('plain')))
Exemplo n.º 4
0
class UsageCommand(Command):
    def __init__(self):
        self.params = None

    def initialize(self):
        if self.params is None:
            '[-] Error: chori is not a valid command'
            self.params = Parameter()
            for cmd in cmd_manager.cmds:
                self.params.add_parameter(
                    cmd,
                    Parameter(lambda __, _, cmd=cmd: output_manager.normal(
                        ' {0}'.format(cmd_manager.cmds[cmd].usage(cmd))).
                              line_break()))

    def blah(self, data):
        output_manager.normal(' {0}'.format(data)).line_break()

    def execute(self, mole, params):
        self.initialize()
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        self.initialize()
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' <CMD_NAME>'
Exemplo n.º 5
0
 def __init__(self):
     BaseFilterCommand.__init__(self,
                                lambda mole: mole.requester.query_filters)
     config = Parameter()
     config.set_param_generator(
         lambda mole, _: self.generate_config_parameters(mole))
     self.params.add_parameter('config', config)
Exemplo n.º 6
0
class UsageCommand(Command):
    def __init__(self):
        self.params = None

    def initialize(self):
        if self.params is None:
            '[-] Error: chori is not a valid command'
            self.params = Parameter()
            for cmd in cmd_manager.cmds:
                self.params.add_parameter(cmd, Parameter(lambda __, _, cmd=cmd:
                    output_manager.normal(' {0}'.format(cmd_manager.cmds[cmd].usage(cmd))).line_break()))

    def blah(self, data):
        output_manager.normal(' {0}'.format(data)).line_break()

    def execute(self, mole, params):
        self.initialize()
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        self.initialize()
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' <CMD_NAME>'
def parameters():
    parameters = [
        Parameter(value_descriptor=CategoryParameter(list(range(80, 90))),
                  name='1st'),
        Parameter(value_descriptor=CategoryParameter(list(range(80, 90))),
                  name='2nd'),
        Parameter(value_descriptor=RangeParameter(3, 100), name='3rd')
    ]
    return parameters
Exemplo n.º 8
0
    def testDefault(self):
        opt = Parameter('foo', default=12345)
        self.assertEqual(opt.name, 'foo')
        self.assertEqual(opt.default, 12345)
        self.assertEqual(opt.value, 12345)

        opt.value = '12345'
        self.assertEqual(opt.default, 12345)
        self.assertEqual(opt.value, '12345')
Exemplo n.º 9
0
 def func_i_alpha(r, l, lam):
     ia_p = []
     for i in range(len(parm.TIME)):
         ia = parm.get_i_alpha_at(i)
         w = theta = parm.get_theta_at(i)
         ia_p.append(r / l * ia + parm.P * lam / l * w * math.sin(theta) +
                     1 / l * parm.U_ALPHA)
     ia_p = np.asarray(ia_p)
     return ia_p * SCALER
Exemplo n.º 10
0
 def func_i_beta(r, l, lam):
     ib_p = []
     for i in range(len(parm.TIME)):
         ib = parm.get_i_beta_at(i)
         w = theta = parm.get_theta_at(i)
         ib_p.append(r / l * ib + parm.P * lam / l * w * math.cos(theta) +
                     1 / l * parm.U_BETA)
     ib_p = np.asarray(ib_p)
     return ib_p * SCALER
Exemplo n.º 11
0
def parameters():
    parameters = [
        Parameter(FieldSelector(object_name='NonRes Fixed Assembly Window',
                                field_name='Solar Heat Gain Coefficient'),
                  value_descriptor=RangeParameter(0.01, 0.99)),
        Parameter(FieldSelector('Lights', '*', 'Watts per Zone Floor Area'),
                  value_descriptor=RangeParameter(8, 12),
                  name='Lights Watts/Area')
    ]
    return parameters
Exemplo n.º 12
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(
         'on'
         if mole.requester.sender.follow_redirects else 'off').line_break())
     self.params.add_parameter(
         'on',
         Parameter(lambda mole, _: self.set_follow_redirects(mole, True)))
     self.params.add_parameter(
         'off',
         Parameter(lambda mole, _: self.set_follow_redirects(mole, False)))
Exemplo n.º 13
0
 def initialize(self):
     if self.params is None:
         '[-] Error: chori is not a valid command'
         self.params = Parameter()
         for cmd in cmd_manager.cmds:
             self.params.add_parameter(
                 cmd,
                 Parameter(lambda __, _, cmd=cmd: output_manager.normal(
                     ' {0}'.format(cmd_manager.cmds[cmd].usage(cmd))).
                           line_break()))
Exemplo n.º 14
0
    def testSize(self):
        opt = Parameter('foo', size=4)
        self.assertEqual(opt._Parameter__array, True)
        self.assertEqual(opt._Parameter__size, 4)

        with self.assertLogs(level=logging.WARNING) as cm:
            opt.value = (1, 2, 3)
        self.assertIn(
            "'foo' was defined as an array with length 4 but a value with length 3 was provided.",
            cm.output[0])
Exemplo n.º 15
0
    def testValue(self):
        opt = Parameter('foo')
        self.assertEqual(opt.name, 'foo')
        self.assertIsNone(opt.default)
        self.assertIsNone(opt.value)

        ret, err = opt.setValue(12345)
        self.assertEqual(ret, 0)
        self.assertEqual(err, None)
        self.assertEqual(opt.value, 12345)
Exemplo n.º 16
0
    def testSetRequired(self):
        opt = Parameter('year')
        self.assertEqual(opt.required, False)
        retcode, msg = opt.setRequired(True)
        self.assertEqual(retcode, 0)
        self.assertEqual(msg, None)
        self.assertEqual(opt.required, True)

        retcode, msg = opt.validate()
        self.assertEqual(retcode, 1)
        self.assertEqual(msg,
                         "The parameter 'year' is marked as required, but no value is assigned.")

        opt.setValue(1980)
        retcode, msg = opt.validate()
        self.assertEqual(retcode, 0)
        self.assertEqual(msg, None)

        retcode, msg = opt.setRequired(False)
        self.assertEqual(retcode, 1)
        self.assertEqual(
            msg,
            "The parameter 'year' has already been validated, the required state cannot be changed."
        )

        retcode, msg = opt.setRequired('wrong')
        self.assertEqual(retcode, 1)
        self.assertEqual(
            msg,
            "For the parameters 'year', the supplied value for `setRequired` must be a `bool`, a <class 'str'> was provided."
        )
Exemplo n.º 17
0
 def __init__(self, inpt_num, output_num, activate=Liner, timing=False):
     n, m = inpt_num, output_num
     self.active = activate
     if self.active.__name__ == "Sigmoid":
         self.w = Parameter(
             np.random.randn(n + 1, m) * np.sqrt(6. / (n + m + 1)))
     else:
         self.w = Parameter(
             np.random.uniform(-1, 1,
                               (n + 1, m)) * np.sqrt(6. / (n + m + 1)))
     self.timing = timing
Exemplo n.º 18
0
 def __init__(self, functor):
     self.functor = functor
     self.params = Parameter(lambda mole, _: self.print_filters(mole))
     add_param = Parameter()
     add_param.set_param_generator(
         lambda mole, _: self.generate_add_filters(mole))
     del_param = Parameter()
     del_param.set_param_generator(
         lambda mole, _: self.generate_del_filters(mole))
     self.params.add_parameter('add', add_param)
     self.params.add_parameter('del', del_param)
Exemplo n.º 19
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(
         str(mole.requester.sender)).line_break())
     self.params.add_parameter(
         'headsender',
         Parameter(
             lambda mole, _: self.set_sender(mole, HttpHeadRequestSender)))
     self.params.add_parameter(
         'httpsender',
         Parameter(
             lambda mole, _: self.set_sender(mole, HttpRequestSender)))
Exemplo n.º 20
0
    def __import_filters(self, mole, filter_manager, filters):

        for filter_node in filters:
            name = b64decode(filter_node.get('name').encode()).decode()
            init_params = loads(b64decode(filter_node.get('init_params').encode()))
            filter_object = filter_manager.add_filter(name, init_params)
            configurator = Parameter()
            configurator.set_param_generator(lambda mole, _: filter_object.configuration_parameters())
            for config_node in filter_node:
                config_params = loads(b64decode(config_node.get('config_params').encode()))
                configurator.execute(mole, config_params)
Exemplo n.º 21
0
def _make_linear_fluorescence(scale=.5, offset=65):
    scale = Parameter('scale', scale)
    offset = Parameter('offset', offset)
    linear = \
        {
            'type': 'observable',
            'observable_type': 'linear_transform',
            'name': 'linear_transform',
            'scale': scale,
            'offset': offset
        }
    return linear, [scale, offset], []
Exemplo n.º 22
0
    def testNone(self):
        opt = Parameter('year')
        self.assertEqual(opt.value, None)

        ret, err = opt.setValue(1980)
        self.assertEqual(ret, 0)
        self.assertEqual(err, None)

        ret, err = opt.setValue(None)
        self.assertEqual(opt.value, None)
        self.assertEqual(ret, 0)
        self.assertEqual(err, None)
Exemplo n.º 23
0
    def testValidate(self):
        sub = InputParameters()
        sub.add('year')

        opt = Parameter('date', default=sub)

        self.assertFalse(opt.is_validated)
        self.assertFalse(sub.parameter('year').is_validated)

        opt.validate()
        self.assertTrue(opt.is_validated)
        self.assertTrue(sub.parameter('year').is_validated)
Exemplo n.º 24
0
    def testPrivate(self):
        opt = Parameter('year')
        self.assertEqual(opt.private, False)

        opt = Parameter('year', private=True)
        self.assertEqual(opt.private, True)

        opt = Parameter('_year', private=False)
        self.assertEqual(opt.private, False)

        opt = Parameter('_year')
        self.assertEqual(opt.private, True)
Exemplo n.º 25
0
    def testName(self):
        opt = Parameter('foo')
        self.assertEqual(opt.name, 'foo')

        opt = Parameter(u'foo')
        self.assertEqual(opt.name, u'foo')

        with self.assertRaises(TypeError) as e:
            Parameter(42)
        self.assertIn(
            "The supplied 'name' argument must be a 'str', but <class 'int'> was provided.",
            str(e.exception))
Exemplo n.º 26
0
 def generate_config_parameters(self, mole):
     ret = {}
     for i in mole.requester.query_filters.active_filters():
         try:
             param = Parameter()
             subparams = mole.requester.query_filters.config_parameters(i)
             for subparam in subparams:
                 param.add_parameter(subparam, subparams[subparam])
             ret[i] = param
         except Exception as ex:
             print(ex)
     return ret
Exemplo n.º 27
0
    def testDoc(self):
        opt = Parameter('foo', doc='This is foo, not bar.')
        self.assertEqual(opt.doc, 'This is foo, not bar.')

        opt = Parameter('foo', doc=u'This is foo, not bar.')
        self.assertEqual(opt.doc, u'This is foo, not bar.')

        with self.assertRaises(TypeError) as e:
            Parameter('foo', doc=42)
        self.assertIn(
            "The supplied 'doc' argument must be a 'str', but <class 'int'> was provided.",
            str(e.exception))
Exemplo n.º 28
0
 def generate_config_parameters(self, mole):
     ret = {}
     for i in mole.requester.query_filters.active_filters():
         try:
             param = Parameter()
             subparams = mole.requester.query_filters.config_parameters(i)
             for subparam in subparams:
                 param.add_parameter(subparam, subparams[subparam])
             ret[i] = param
         except Exception as ex:
             print(ex)
     return ret
Exemplo n.º 29
0
 def func_w(j, lam):
     w = []
     for i in range(len(parm.TIME)):
         ia = parm.get_i_alpha_at(i)
         ib = parm.get_i_beta_at(i)
         theta = parm.get_theta_at(i)
         ci = parm.get_ci_at(i)
         w.append(-(lam / j * (-ia * math.sin(parm.P) * theta +
                               ib * math.cos(parm.P) * theta) -
                    parm.F / j * theta - ci / j))
     w = np.asarray(w)
     return w * SCALER
Exemplo n.º 30
0
    def testAllowWithTypeError(self):

        with self.assertRaises(TypeError) as e:
            Parameter('foo', allow='wrong')
        self.assertIn(
            "The supplied 'allow' argument must be a 'tuple', but <class 'str'> was provided.",
            str(e.exception))

        with self.assertRaises(TypeError) as e:
            Parameter('foo', vtype=int, allow=(1, '2'))
        self.assertIn(
            "The supplied 'allow' argument must be a 'tuple' of (<class 'int'>,) items, but a <class 'str'> item was provided.",
            str(e.exception))
def problem():
    problem = EPProblem([
        Parameter(
            FieldSelector(object_name='Mass NonRes Wall Insulation',
                          field_name='Thickness'),
            RangeParameter(min_val=0.01, max_val=0.99)),
        Parameter(
            FieldSelector(class_name='Construction',
                          object_name='ext-slab',
                          field_name='Outside Layer'),
            CategoryParameter(options=('HW CONCRETE', 'Invalid Material')))
    ])
    return problem
Exemplo n.º 32
0
class QueryModeCommand(Command):
    def __init__(self):
        self.params = Parameter(lambda mole, _: output_manager.normal(mole.mode).line_break())
        self.params.add_parameter('union', Parameter(lambda mole, _: mole.set_mode('union')))
        self.params.add_parameter('blind', Parameter(lambda mole, _: mole.set_mode('blind')))

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' <union|blind>'
Exemplo n.º 33
0
 def __init__(self, name, params):
     BaseQueryFilter.__init__(self, name, params)
     self.cast_match = re.compile('cast\([\w\d_\-@]+ as varchar\([\d]+\)\)')
     self.field_match = re.compile('cast\(([\w\d_\-@]+) as varchar\([\d]+\)\)')
     self.blacklist = []
     self.collation = params[0] if len(params) == 1 else 'DATABASE_DEFAULT'
     self.blist_param = Parameter(lambda _, __: self.print_blacklist())
     add_blist = Parameter(lambda _, params: self.blacklist_add(params))
     del_blist = Parameter(no_args_str='Expected argument after "del"')
     self.blist_param.add_parameter('add', add_blist)
     del_blist.set_param_generator(lambda _, __: self.del_generator())
     self.blist_param.add_parameter('del', del_blist)
     self.collation_param = Parameter(lambda _, params: self.exec_collation(params))
     self.params = { 'blacklist' : self.blist_param, 'collation' : self.collation_param }
Exemplo n.º 34
0
class BaseFilterCommand(Command):
    def __init__(self, functor):
        self.functor = functor
        self.params = Parameter(lambda mole, _: self.print_filters(mole))
        add_param = Parameter()
        add_param.set_param_generator(
            lambda mole, _: self.generate_add_filters(mole))
        del_param = Parameter()
        del_param.set_param_generator(
            lambda mole, _: self.generate_del_filters(mole))
        self.params.add_parameter('add', add_param)
        self.params.add_parameter('del', del_param)

    def generate_add_filters(self, mole):
        ret = {}
        for i in self.functor(mole).available_filters():
            ret[i] = Parameter(
                lambda mole, params, i=i: self.add_filter(mole, i, params))
        return ret

    def generate_del_filters(self, mole):
        ret = {}
        for i in self.functor(mole).active_filters():
            ret[i] = Parameter(
                lambda mole, params, i=i: self.functor(mole).remove_filter(i))
        return ret

    def add_filter(self, mole, name, params):
        try:
            self.functor(mole).add_filter(name, params)
        except FilterCreationError as ex:
            raise CommandException(
                'Filter {0} failed to initialize({1})'.format(name, str(ex)))

    def print_filters(self, mole):
        filters = self.functor(mole).active_filters_to_string()
        if len(filters) == 0:
            output_manager.normal('No filters added yet.').line_break()
        else:
            for i in filters:
                output_manager.normal(i).line_break()

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' [add|del|config] [FILTER_NAME [ARGS]]'
Exemplo n.º 35
0
    def testType(self):
        opt = Parameter('foo', vtype=int)
        self.assertIsNone(opt.default)
        self.assertIsNone(opt.value)

        opt.value = 1
        self.assertEqual(opt.value, 1)

        with self.assertLogs(level=logging.WARNING) as cm:
            opt.value = 's'
        self.assertEqual(len(cm.output), 1)
        self.assertIn(
            "'foo' must be of type (<class 'int'>,) but <class 'str'> provided.",
            cm.output[0])
Exemplo n.º 36
0
 def initialize(self):
     if self.params is None:
         '[-] Error: chori is not a valid command'
         self.params = Parameter()
         for cmd in cmd_manager.cmds:
             self.params.add_parameter(cmd, Parameter(lambda __, _, cmd=cmd:
                 output_manager.normal(' {0}'.format(cmd_manager.cmds[cmd].usage(cmd))).line_break()))
Exemplo n.º 37
0
class BaseFilterCommand(Command):
    def __init__(self, functor):
        self.functor = functor
        self.params = Parameter(lambda mole, _: self.print_filters(mole))
        add_param = Parameter()
        add_param.set_param_generator(lambda mole, _: self.generate_add_filters(mole))
        del_param = Parameter()
        del_param.set_param_generator(lambda mole, _: self.generate_del_filters(mole))
        self.params.add_parameter('add', add_param)
        self.params.add_parameter('del', del_param)

    def generate_add_filters(self, mole):
        ret = {}
        for i in self.functor(mole).available_filters():
            ret[i] = Parameter(lambda mole, params, i=i: self.add_filter(mole, i, params))
        return ret

    def generate_del_filters(self, mole):
        ret = {}
        for i in self.functor(mole).active_filters():
            ret[i] = Parameter(lambda mole, params, i=i: self.functor(mole).remove_filter(i))
        return ret

    def add_filter(self, mole, name, params):
        try:
            self.functor(mole).add_filter(name, params)
        except FilterCreationError as ex:
            raise CommandException('Filter {0} failed to initialize({1})'.format(name, str(ex)))

    def print_filters(self, mole):
        filters = self.functor(mole).active_filters_to_string()
        if len(filters) == 0:
            output_manager.normal('No filters added yet.').line_break()
        else:
            for i in filters:
                output_manager.normal(i).line_break()

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' [add|del|config] [FILTER_NAME [ARGS]]'
Exemplo n.º 38
0
 def __init__(self, functor):
     self.functor = functor
     self.params = Parameter(lambda mole, _: self.print_filters(mole))
     add_param = Parameter()
     add_param.set_param_generator(lambda mole, _: self.generate_add_filters(mole))
     del_param = Parameter()
     del_param.set_param_generator(lambda mole, _: self.generate_del_filters(mole))
     self.params.add_parameter('add', add_param)
     self.params.add_parameter('del', del_param)
Exemplo n.º 39
0
class RequestSenderCommand(Command):
    def __init__(self):
        self.params = Parameter(lambda mole, _: output_manager.normal(str(mole.requester.sender)).line_break())
        self.params.add_parameter('headsender', Parameter(lambda mole, _: self.set_sender(mole, HttpHeadRequestSender)))
        self.params.add_parameter('httpsender', Parameter(lambda mole, _: self.set_sender(mole, HttpRequestSender)))

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)

    def set_sender(self, mole, sender):
        mole.requester.sender = sender()
        mole.initialized = False
        mole.requester.encoding = None
Exemplo n.º 40
0
class VerboseCommand(Command):
    def __init__(self):
        self.params = Parameter(lambda mole, _: output_manager.normal('on' if mole.verbose else 'off').line_break())
        self.params.add_parameter('on', Parameter(lambda mole, _: self.set_verbose(mole, True)))
        self.params.add_parameter('off', Parameter(lambda mole, _: self.set_verbose(mole, False)))

    def set_verbose(self, mole, value):
        mole.verbose = value

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' <on|off>'
Exemplo n.º 41
0
class OutputCommand(Command):
    def __init__(self):
        self.params = Parameter(lambda mole, _: output_manager.normal(output_manager.result_output).line_break())
        self.params.add_parameter('pretty', Parameter(lambda mole, _: self.set_output('pretty')))
        self.params.add_parameter('plain', Parameter(lambda mole, _: self.set_output('plain')))

    def set_output(self, value):
        output_manager.result_output = value

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)

    def usage(self, cmd_name):
        return cmd_name + ' <pretty|plain>'
Exemplo n.º 42
0
class RedirectCommand(Command):
    def __init__(self):
        self.params = Parameter(lambda mole, _: output_manager.normal('on' if mole.requester.sender.follow_redirects else 'off').line_break())
        self.params.add_parameter('on', Parameter(lambda mole, _: self.set_follow_redirects(mole, True)))
        self.params.add_parameter('off', Parameter(lambda mole, _: self.set_follow_redirects(mole, False)))

    def set_follow_redirects(self, mole, value):
        mole.requester.sender.follow_redirects = value

    def execute(self, mole, params):
        self.params.execute(mole, params)

    def usage(self, cmd_name):
        return cmd_name + ' [on|off]'

    def parameters(self, mole, current_params):
        return self.params.parameter_list(mole, current_params)
Exemplo n.º 43
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal('on' if mole.verbose else 'off').line_break())
     self.params.add_parameter('on', Parameter(lambda mole, _: self.set_verbose(mole, True)))
     self.params.add_parameter('off', Parameter(lambda mole, _: self.set_verbose(mole, False)))
Exemplo n.º 44
0
 def __init__(self):
     BaseFilterCommand.__init__(self, lambda mole: mole.requester.query_filters)
     config = Parameter()
     config.set_param_generator(lambda mole, _: self.generate_config_parameters(mole))
     self.params.add_parameter('config', config)
Exemplo n.º 45
0
    def fromXML(text):
        """Recreates a Module from its XML specification.

        Parameters:
          text -- A string containing an XML representation of a Module.

        Output:
          A Module whose properties are specified by the given XML text."""

        module = etree.fromstring(text)
        name = module.attrib["name"]

        # List of required child elements that consist solely of text.
        textChildren = (
                "description",
                "domain",
                "codeLocation",
                "isParallel",
                "stoppingConditions",
                "className",
                )

        textValues = {}

        # Pull out the text from all required text-only tags.
        for childTag in textChildren:
            element = module.find(childTag)

            if element is None:
                print "Missing required tag:", childTag + "."
                exit(1)

            textValues[childTag] = str(element.text)

        #description         = textValues["description"]
        # Eliminate extra whitespace
        description         = re.sub(r'\s+',r' ',textValues["description"].strip())
        domain              = textValues["domain"]
        className           = textValues["className"]
        codeLocation        = textValues["codeLocation"]
        stopcond            = int(textValues["stoppingConditions"])
        isParallel          = eval(textValues["isParallel"].title())

        # Interface Name might not be known for all modules so this is
        # optional.
        interfaceElement = module.find("interfaceName")

        interfaceName = None
        if interfaceElement is not None:
            interfaceName = interfaceElement.text

        stoppingConditions = []
        for cond, code in StoppingConditions.items():
            if stopcond & code:
                stoppingConditions.append(cond)

        parameters = []
        paramsElement = module.find("parameters")

        if paramsElement is not None:
            for param in paramsElement.findall("parameter"):
                parameters.append(Parameter.paramFromElement(param))

        module = Module(
                name,
                description,
                domain,
                className,
                codeLocation,
                isParallel,
                stoppingConditions,
                [],
                parameters)

        module.interfaceName = interfaceName

        return module
Exemplo n.º 46
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(str(mole.requester.sender)).line_break())
     self.params.add_parameter('headsender', Parameter(lambda mole, _: self.set_sender(mole, HttpHeadRequestSender)))
     self.params.add_parameter('httpsender', Parameter(lambda mole, _: self.set_sender(mole, HttpRequestSender)))
Exemplo n.º 47
0
class SQLServerCollationFilter(BaseQueryFilter):
    def __init__(self, name, params):
        BaseQueryFilter.__init__(self, name, params)
        self.cast_match = re.compile('cast\([\w\d_\-@]+ as varchar\([\d]+\)\)')
        self.field_match = re.compile('cast\(([\w\d_\-@]+) as varchar\([\d]+\)\)')
        self.blacklist = []
        self.collation = params[0] if len(params) == 1 else 'DATABASE_DEFAULT'
        self.blist_param = Parameter(lambda _, __: self.print_blacklist())
        add_blist = Parameter(lambda _, params: self.blacklist_add(params))
        del_blist = Parameter(no_args_str='Expected argument after "del"')
        self.blist_param.add_parameter('add', add_blist)
        del_blist.set_param_generator(lambda _, __: self.del_generator())
        self.blist_param.add_parameter('del', del_blist)
        self.collation_param = Parameter(lambda _, params: self.exec_collation(params))
        self.params = { 'blacklist' : self.blist_param, 'collation' : self.collation_param }

    def configuration_parameters(self):
        return self.params

    def exec_collation(self, params):
        if len(params) < 1:
            output_manager.normal(self.collation).line_break()
        else:
            self.collation = params[0]

    def blacklist_add(self, params):
        if len(params) == 0:
            output_manager.error('Expected argument after "add"').line_break()
        else:
            for i in params:
                self.blacklist.append(i)

    def del_generator(self):
        ret = {}
        for i in self.blacklist:
            ret[i] = Parameter(lambda _, __, i=i: self.blacklist.remove(i))
        return ret

    def print_blacklist(self):
        if len(self.blacklist) == 0:
            output_manager.info('No fields in blacklist.').line_break()
        else:
            for i in self.blacklist:
                output_manager.normal(i).line_break()

    def filter_(self, query):
        try:
            matches = self.cast_match.findall(query)
            for i in matches:
                field = self.field_match.findall(i)[0]
                if not field in self.blacklist:
                    replaced = i.replace(field, '(' + field + ' COLLATE ' + self.collation + ')')
                    query = query.replace(i, replaced)
        except Exception as ex:
            output_manager.error('{0}'.format(ex)).line_break()
        return query

    def export_config(self):
        import copy
        blacklist_config = ['blacklist', 'add'] + copy.copy(self.blacklist)
        collation_config = ['collation', self.collation]
        return [blacklist_config, collation_config]

    def __str__(self):
        return self.name + ' ' + self.collation
Exemplo n.º 48
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(mole.mode).line_break())
     self.params.add_parameter('union', Parameter(lambda mole, _: mole.set_mode('union')))
     self.params.add_parameter('blind', Parameter(lambda mole, _: mole.set_mode('blind')))
Exemplo n.º 49
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal('on' if mole.requester.sender.follow_redirects else 'off').line_break())
     self.params.add_parameter('on', Parameter(lambda mole, _: self.set_follow_redirects(mole, True)))
     self.params.add_parameter('off', Parameter(lambda mole, _: self.set_follow_redirects(mole, False)))
Exemplo n.º 50
0
 def __init__(self):
     self.params = Parameter(lambda mole, _: output_manager.normal(output_manager.result_output).line_break())
     self.params.add_parameter('pretty', Parameter(lambda mole, _: self.set_output('pretty')))
     self.params.add_parameter('plain', Parameter(lambda mole, _: self.set_output('plain')))