Handles external calling for this module

    Execute this python module and provide the args shown below to
    external call this module to send email messages!

    :return: None
968363
def main():
    
    log = logging.getLogger(mod_logger + '.main')
    parser = argparse.ArgumentParser(description='This module allows sending email messages.')
    parser.add_argument('-f', '--file', help='Full path to a plain text file', required=False)
    parser.add_argument('-s', '--sender', help='Email address of the sender', required=False)
    parser.add_argument('-r', '--recipient', help='Email address of the recipient', required=False)
    args = parser.parse_args()

    am = AssetMailer()
    err = None
    if args.file:
        try:
            am.send_text_file(text_file=args.file, sender=args.sender, recipient=args.recipient)
        except AssetMailerError:
            _, ex, trace = sys.exc_info()
            err = '{n}: There was a problem sending email with file {f} from sender {s} to recipient {r}:\n{e}'.format(
                n=ex.__class__.__name__, f=args.file, s=args.sender, r=args.recipient, e=str(ex))
            log.error(err)
    else:
        try:
            am.send_cons3rt_agent_logs()
        except AssetMailerError:
            _, ex, trace = sys.exc_info()
            err = '{n}: There was a problem sending cons3rt agent log files:\n{e}'.format(
                n=ex.__class__.__name__, e=str(ex))
            log.error(err)
    if err is None:
        log.info('Successfully send email')
57819
def execute(self):
        
        # Ensure that we have commands registered
        if not self.commands or self._parser is None:
            raise NotImplementedError(
                "No commands registered with this program!"
            )

        # Handle input from the command line
        args = self.parser.parse_args()                # Parse the arguments

        try:

            handle_default_args(args)                  # Handle the default args

            if not hasattr(args, 'func'):              # Handle no subcommands
                self.parser.print_help()
                self.exit(0)

            msg = args.func(args)                      # Call the default function
            msg = "{}\n".format(msg) if msg else ''    # Format the message
            self.exit(0, msg)                          # Exit cleanly with message

        except Exception as e:
            if hasattr(args, 'traceback') and args.traceback:
                traceback.print_exc()

            msg = color.format(str(e), color.RED)
            self.exit(1, msg)
1179096
def handle_invocation(self, message):
        
        req_id = message.request_id
        reg_id = message.registration_id
        if reg_id in self._registered_calls:
            handler = self._registered_calls[reg_id][REGISTERED_CALL_CALLBACK]
            invoke = WampInvokeWrapper(self,handler,message)
            invoke.start()
        else:
            error_uri = self.get_full_uri('error.unknown.uri')
            self.send_message(ERROR(
                request_code = WAMP_INVOCATION,
                request_id = req_id,
                details = {},
                error =error_uri
            ))
734725
def call(mail)
      begin
        Bugsnag.configuration.set_request_data :mailman_msg, mail.to_s
        yield
      rescue Exception => ex
        Bugsnag.notify(ex, true) do |report|
          report.severity = "error"
          report.severity_reason = {
            :type => Bugsnag::Report::UNHANDLED_EXCEPTION_MIDDLEWARE,
            :attributes => FRAMEWORK_ATTRIBUTES
          }
        end
        raise
      ensure
        Bugsnag.configuration.clear_request_data
      end
    end
275694
def method_missing(meth, *args, &block)
       if mail.respond_to?(meth)
         mail.send(meth, *args, &block)
       else
         super
       end
    end
724941
def do_execute(self):
        
        result = None
        f = None
        try:
            if bool(self.resolve_option("append")):
                f = open(str(self.resolve_option("output")), "a")
            else:
                f = open(str(self.resolve_option("output")), "w")
            f.write(str(self.input.payload))
            f.write("\n")
        except Exception as e:
            result = self.full_name + "\n" + traceback.format_exc()
        finally:
            if f is not None:
                f.close()
        return result
359940
def handle(self, *args, **options):
        
        if len(args) < 1:
            raise CommandError("Please specify an action. See --help.")

        action = args[0]
        email = None

        if action not in self.valid_actions:
            message = "Invalid action: %s" % action
            raise CommandError(message)

        if action in ['verify', 'delete']:
            if len(args) < 2:
                message = "Please specify an email address to %s." % action
                raise CommandError(message)

            email = args[1]

            if not email or not self._is_valid_email(email):
                message = "Invalid email address provided: %s" % email
                raise CommandError(message)

        # Hand this off to the action routing method.
        self._route_action(action, email)
1252754
def run_from_argv(self, argv):
        """"""
        self.argv_string = ' '.join(argv)
        super(EmailNotificationCommand, self).run_from_argv(argv)
67373
def _execute(self, sender, event_args):
        '''
        
        '''
        with self._lock:
            while not self._messages.empty():
                msg, args, kwargs = self._messages.get(False)
                for subscriber in self._subscribers[msg]:
                    try:
                        subscriber(*args, **kwargs)
                    except weakref.ReferenceError:
                        # Reference to handler is lost and it is OK to silence it
                        pass
349662
def handle(self):
        
        self.output = PyStratumStyle(self.input, self.output)

        command = self.get_application().find('constants')
        ret = command.execute(self.input, self.output)
        if ret:
            return ret

        command = self.get_application().find('loader')
        ret = command.execute(self.input, self.output)
        if ret:
            return ret

        command = self.get_application().find('wrapper')
        ret = command.execute(self.input, self.output)

        self.output.writeln('')

        return ret
593003
def _handle(self, msg):
        

        def handler_yielder():
            for handler in self.handlers:
                yield handler

        def handler_callback(_):
            if msg.propagate:
                try:
                    h = hyielder.next()
                    g = self._pool.spawn(handler_runner, h)
                    g.link(handler_callback)
                except StopIteration:
                    pass

        def handler_runner(h):
            for command in h.commands:
                if command == msg.command:
                    method = getattr(h, h.commands[command])
                    method(msg)

        hyielder = handler_yielder()
        try:
            next_handler = hyielder.next()
            g = self._pool.spawn(handler_runner, next_handler)
            g.link(handler_callback)
        except StopIteration:
            pass
106643
def call(self, command, *args):
        

        if not command:
            return

        # Look for local methods first
        try:
            res = self.registered[command]['function'](self, *args)
            return Response('local', res, None)

        # Method not found, try remote
        except KeyError:

            # Execute remote command
            res, err = self.client.call(command, *args)
            return Response('remote', res, err, self.client.is_multi())

        # Local exception
        except Exception as e:
            return Response('local', res, str(e))
270411
def handle_request(self, msg):
        
        method = self.__class__.unhandled_request
        if msg.name in self._request_handlers:
            method = self._request_handlers[msg.name]

        try:
            reply = method(self, msg)
            if isinstance(reply, Message):
                # If it is a message object, assume it is a reply.
                reply.mid = msg.mid
                assert (reply.mtype == Message.REPLY)
                assert (reply.name == msg.name)
                self._logger.info("%s OK" % (msg.name,))
                self.send_message(reply)
            else:
                # Just pass on what is, potentially, a future. The implementor
                # of the request handler method must arrange for a reply to be
                # sent. Since clients have no business dealing with requests in
                # any case we don't do much to help them.
                return reply
        # We do want to catch everything that inherits from Exception
        # pylint: disable-msg = W0703
        except Exception:
            e_type, e_value, trace = sys.exc_info()
            reason = "\n".join(traceback.format_exception(
                e_type, e_value, trace, self._tb_limit))
            self._logger.error("Request %s FAIL: %s" % (msg.name, reason))
807571
def handle(self, *args, **options):
        
        now = arrow.utcnow().to(settings.TIME_ZONE)
        now = now.date()

        digest = Digest.objects.filter(date_end=str(now)).order_by('user', 'date_end')
        users = digest.distinct('user')

        subject = 'Your digester'

        msg_plain = render_to_string('digest/email.txt', {'digest': digest, 'subject': subject})
        msg_html = render_to_string('digest/email.html', {'digest': digest, 'subject': subject})
        message = msg_plain
        from_email = settings.ADMINS
        recipient_list = ()
        for user in users:
            recipient_list += (user.user.email,)

        send_mail(subject, message, from_email, recipient_list,
                  html_message=msg_html)
284834
def handle(self, *args, **options):
        
        if options["sub_command"] == "add":
            self.handle_add(options)
        elif options["sub_command"] == "update":
            self.handle_update(options)
        elif options["sub_command"] == "details":
            self.handle_details(options["username"])
        elif options["sub_command"] == "list":
            self.handle_list(options["all"], options["csv"])
844948
def run(args: List[str],
        get_output: bool = False,
        encoding: str = sys.getdefaultencoding()) -> Tuple[str, str]:
    
    printable = " ".join(shlex.quote(x) for x in args).replace("\n", r"\n")
    log.debug("Running external command: {}", printable)
    if get_output:
        p = subprocess.run(args, stdout=subprocess.PIPE,
                           stderr=subprocess.PIPE, check=True)
        stdout, stderr = p.stdout.decode(encoding), p.stderr.decode(encoding)
    else:
        subprocess.check_call(args)
        stdout, stderr = "", ""
    return stdout, stderr
159653
def do_execute(self):
        
        formatstr = str(self.resolve_option("format"))
        expanded = self.storagehandler.expand(formatstr)
        self._output.append(Token(expanded))
        return None