Factory method called by the parsers
967124
def create_event(self, timestamp, event_type, hostname, fields, tags=None):
        
        # Agent6 expects a specific set of fields, so we need to place all
        # extra fields in the msg_title and let the Datadog backend separate them
        # Any remaining fields that aren't a part of the datadog-agent payload
        # specification will be dropped.
        event_payload = fields._asdict()

        msg_text = {
            'event_type': event_payload.pop('event_type', None),
            'event_soft_hard': event_payload.pop('event_soft_hard', None),
            'check_name': event_payload.pop('check_name', None),
            'event_state': event_payload.pop('event_state', None),
            'payload': event_payload.pop('payload', None),
            'ack_author': event_payload.pop('ack_author', None),
        }

        msg_text = json.dumps(msg_text)
        self.log.info("Nagios Event pack: {}".format(msg_text))

        event_payload.update(
            {
                'timestamp': timestamp,
                'event_type': event_type,
                'msg_text': msg_text,
                'source_type_name': SOURCE_TYPE_NAME,
                'tags': tags,
            }
        )

        # if host is localhost, turn that into the internal host name
        host = event_payload.get('host', None)
        if host == "localhost":
            event_payload["host"] = hostname
        return event_payload
269739
function factory(original) {
  replacement.locator = original.locator

  return replacement

  /* Replacer for tokeniser or visitor. */
  function replacement(node) {
    var self = this
    var result = original.apply(self, arguments)
    var marker = result && result.type ? result : node
    var data

    try {
      data = jsYAML.safeLoad(marker.value)
      data = data && data.remark

      if (data) {
        self.setOptions(data)
      }
    } catch (error) {
      self.file.fail(error.message, marker)
    }

    return result
  }
}
1312986
def parse_args(self):
        
        # compile the parser
        self._compile()
        # clear the args
        self.args = None
        self._self_event('before_parse', 'parse', *sys.argv[1:], **{})
        # list commands/subcommands in argv
        cmds = [cmd for cmd in sys.argv[1:] if not cmd.startswith("-")]
        if (len(cmds) > 0 and not utils.check_help() and self.default_cmd
                and cmds[0] not in self.commands):
            # if we have at least one command which is not an help command
            # and we have a default command and the first command in arguments
            # is not in commands we insert the default command as second
            # argument (actually the first command)
            sys.argv.insert(1, self.default_cmd)
        # let's parse the arguments
        self.args = self.parser.parse_args()
        # set up the output.
        if self.args:
            # if we have some arguments
            if self.add_output and self.args.output is not None:
                # If add_output is True and we have an output file
                # setup the encoding
                self.encoding = self.args.encoding
                if self.args.encoding.lower() == 'raw':
                    # if we have passed a raw encoding we will write directly
                    # to the output file.
                    self._output = open(self.args.output, self.args.write_mode)
                else:
                    # else we will use the codecs module to write to the
                    # output file.
                    import codecs
                    self._output = codecs.open(
                        self.args.output, self.args.write_mode,
                        encoding=self.args.encoding)
            if self._cfg_factory:
                # if we have a config factory setup the config file with the
                # right param
                self.cfg_file = self.args.config
            # now is parsed.
            self._is_parsed = True
        return self
560133
def assign_parser(self, name):
        '''
        
        '''
        for n, p in list(self.Parsers.items()):
            if n != name:
                del self.Parsers[n]
        if len(self.Parsers) != 1:
            raise RuntimeError('Parser cannot be assigned!')
340041
def _get_parser_compound(cls, *parse_methods):
        
        def parse(value):
            parsed = value

            for method in parse_methods:
                parsed = method(parsed)

            return parsed

        return parse
277202
def parser(self):
        '''
        
        '''
        if not hasattr(self, '_parser'):
            self._parser = self._compile()
        return self._parser
1022430
def factory(cls, object_raw):
        
        if object_raw is None:
            return None
        if object_raw.type is ObjectRaw.Types.object:
            return ObjectObject(object_raw)
        elif object_raw.type is ObjectRaw.Types.type:
            return ObjectType(object_raw)
        elif object_raw.type is ObjectRaw.Types.array:
            return ObjectArray(object_raw)
        elif object_raw.type is ObjectRaw.Types.dynamic:
            return ObjectDynamic(object_raw)
        elif object_raw.type is ObjectRaw.Types.const:
            return ObjectConst(object_raw)
        elif object_raw.type is ObjectRaw.Types.enum:
            return ObjectEnum(object_raw)
        else:
            return Object(object_raw)
1241392
def init(parser = None):
    

    global p,subparsers
    if parser is None:
        p = argparse.ArgumentParser()
    else:
        p = parser

    arg = p.add_argument

    subparsers = p.add_subparsers()
1237386
function factory(name, schema = {}, options = {}) {
  class TangModel extends Model {
    constructor(data) {
      super(data, schema, options)
    }
  }

  TangModel.options = options
  TangModel.schema = schema

  Object.defineProperty(TangModel, 'name', { value: name })

  for (let name in schema.statics) {
    TangModel[name] = function() {
      return schema.statics[name].apply(TangModel, arguments)
    }
  }

  return TangModel
}
981931
function createParser(args) {
  if (!args || !args.file || !args.databaseType) {
    throw new BuildException(
      exceptions.IllegalArgument,
      'The file and the database type must be passed');
  }
  const types = initDatabaseTypeHolder(args.databaseType);
  if (args.editor) {
    const root = getRootElement(readFileContent(args.file));
    return getFileParserByEditor(args.editor, root, types, args.noUserManagement);
  }
  return getParserForSingleFile(args.file, types, args.noUserManagement);
}
681295
def _handle_factory_method(self, service_obj, method_name,
                               args=None, kwargs=None):
        "
        if args is None:
            args = []
        if kwargs is None:
            kwargs = {}

        _check_type('args', args, list)
        _check_type('kwargs', kwargs, dict)

        # Replace args
        new_args = self._replace_scalars_in_args(args)
        new_kwargs = self._replace_scalars_in_kwargs(kwargs)

        return getattr(service_obj, method_name)(*new_args, **new_kwargs)
457430
def create_parser(self, subparsers):
        
        self.parser = subparsers.add_parser(self.name, help=self.help, parents=self.parents)
        self.add_arguments()
        self.parser.set_defaults(func=self.handle)
        return self.parser
692010
def __get_calls_from_parser(proxy_parser, real_parser):
    
    __parsers[proxy_parser] = real_parser
    for method, safe, args, kwargs, proxy_subparser in proxy_parser.calls:
        args = (__proxy_to_real_parser(v) for v in args)
        kwargs = {k: __proxy_to_real_parser(v) for k, v in kwargs.items()}
        real_subparser = getattr(real_parser, method)(*args, **kwargs)
        if real_subparser is not None:
            __get_calls_from_parser(proxy_subparser, real_subparser)
372379
def _get_parser_call_method(self, parser_to_method):
        
        def inner_call(args=None, instance=None):
            """Allows to call the method invoked from the command line or
            provided argument.

            Args:
                args: list of arguments to parse, defaults to command line
                arguments
                instance: an instance of the decorated class. If instance is
                None, the default, and __init__ is decorated the object will be
                instantiated on the fly from the command line arguments
            """
            parser = self._cls.parser
            namespace = parser.parse_args(_get_args_to_parse(args, sys.argv))
            if instance is None:
                # If the __init__ method is not part of the method to
                # decorate we cannot instantiate the class
                if "__init__" not in parser_to_method:
                    raise ParseThisError(("'__init__' method is not decorated. "
                                          "Please provide an instance to "
                                          "'{}.parser.call' or decorate the "
                                          "'__init___' method with "
                                          "'create_parser'"
                                          .format(self._cls.__name__)))
                # We instantiate the class from the command line arguments
                instance = _call_method_from_namespace(self._cls, "__init__",
                                                       namespace)
            method_name = parser_to_method[namespace.method]
            return _call_method_from_namespace(instance, method_name, namespace)
        return inner_call
365911
function(factory, options) {
			this.base(options);
			this.factory = factory;
			this.callback(this.callbacks.init);	
			this.callback(this.callbacks.create);
		}
713853
function(methods) {
    var keys = Object.keys(methods);
    var len = keys.length;
    for (var i = 0; i < len; i++) {
      var key = keys[i];
      this[key] = lib.method.createMethod(methods[key]);
    }
    return factory;
  }
1187769
def create(self, module_name, class_name,
               args=None, kwargs=None, factory_method=None,
               factory_args=None, factory_kwargs=None, static=False,
               calls=None):
        
        if args is None:
            args = []
        if kwargs is None:
            kwargs = {}
        if factory_args is None:
            factory_args = []
        if factory_kwargs is None:
            factory_kwargs = {}
        if static is None:
            static = False

        # Verify
        _verify_create_args(module_name, class_name, static)

        # Import
        module = _import_module(module_name)

        # Instantiate
        service_obj = self._instantiate(module, class_name,
                                        args, kwargs, static)
        # Factory?
        if factory_method is not None:
            service_obj = self._handle_factory_method(service_obj,
                                                      factory_method,
                                                      factory_args,
                                                      factory_kwargs)
        # Extra Calls
        if calls is not None and isinstance(calls, list):
            self._handle_calls(service_obj, calls)

        # Return
        return service_obj