當前位置: 首頁>>代碼示例>>Python>>正文


Python utils.formatdate方法代碼示例

本文整理匯總了Python中email.utils.formatdate方法的典型用法代碼示例。如果您正苦於以下問題:Python utils.formatdate方法的具體用法?Python utils.formatdate怎麽用?Python utils.formatdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在email.utils的用法示例。


在下文中一共展示了utils.formatdate方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: message

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def message(self):
        encoding = self.encoding or settings.DEFAULT_CHARSET
        msg = SafeMIMEText(self.body, self.content_subtype, encoding)
        msg = self._create_message(msg)
        msg['Subject'] = self.subject
        msg['From'] = self.extra_headers.get('From', self.from_email)
        msg['To'] = self.extra_headers.get('To', ', '.join(self.to))
        if self.cc:
            msg['Cc'] = ', '.join(self.cc)
        if self.reply_to:
            msg['Reply-To'] = self.extra_headers.get('Reply-To', ', '.join(self.reply_to))

        # Email header names are case-insensitive (RFC 2045), so we have to
        # accommodate that when doing comparisons.
        header_names = [key.lower() for key in self.extra_headers]
        if 'date' not in header_names:
            msg['Date'] = formatdate()
        if 'message-id' not in header_names:
            # Use cached DNS_NAME for performance
            msg['Message-ID'] = make_msgid(domain=DNS_NAME)
        for name, value in self.extra_headers.items():
            if name.lower() in ('from', 'to'):  # From and To are already handled
                continue
            msg[name] = value
        return msg 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:27,代碼來源:message.py

示例2: send_email

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def send_email(msg_to, msg_subject, msg_body, msg_from=None,
        smtp_server='localhost', envelope_from=None,
        headers={}):

  if not msg_from:
    msg_from = app.config['EMAIL_FROM']

  if not envelope_from:
    envelope_from = parseaddr(msg_from)[1]

  msg = MIMEText(msg_body)

  msg['Subject'] = Header(msg_subject)
  msg['From'] = msg_from
  msg['To'] = msg_to
  msg['Date'] = formatdate()
  msg['Message-ID'] = make_msgid()
  msg['Errors-To'] = envelope_from

  if request:
    msg['X-Submission-IP'] = request.remote_addr

  s = smtplib.SMTP(smtp_server)
  s.sendmail(envelope_from, msg_to, msg.as_string())
  s.close() 
開發者ID:hadleyrich,項目名稱:GerbLook,代碼行數:27,代碼來源:utils.py

示例3: add_auth

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def add_auth(self, request):
        if self.credentials is None:
            raise NoCredentialsError
        if 'Date' in request.headers:
            del request.headers['Date']
        request.headers['Date'] = formatdate(usegmt=True)
        if self.credentials.token:
            if 'X-Amz-Security-Token' in request.headers:
                del request.headers['X-Amz-Security-Token']
            request.headers['X-Amz-Security-Token'] = self.credentials.token
        new_hmac = hmac.new(self.credentials.secret_key.encode('utf-8'),
                            digestmod=sha256)
        new_hmac.update(request.headers['Date'].encode('utf-8'))
        encoded_signature = encodebytes(new_hmac.digest()).strip()
        signature = ('AWS3-HTTPS AWSAccessKeyId=%s,Algorithm=%s,Signature=%s' %
                     (self.credentials.access_key, 'HmacSHA256',
                      encoded_signature.decode('utf-8')))
        if 'X-Amzn-Authorization' in request.headers:
            del request.headers['X-Amzn-Authorization']
        request.headers['X-Amzn-Authorization'] = signature 
開發者ID:skarlekar,項目名稱:faces,代碼行數:22,代碼來源:auth.py

示例4: _set_necessary_date_headers

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def _set_necessary_date_headers(self, request):
        # The spec allows for either the Date _or_ the X-Amz-Date value to be
        # used so we check both.  If there's a Date header, we use the date
        # header.  Otherwise we use the X-Amz-Date header.
        if 'Date' in request.headers:
            del request.headers['Date']
            datetime_timestamp = datetime.datetime.strptime(
                request.context['timestamp'], SIGV4_TIMESTAMP)
            request.headers['Date'] = formatdate(
                int(calendar.timegm(datetime_timestamp.timetuple())))
            if 'X-Amz-Date' in request.headers:
                del request.headers['X-Amz-Date']
        else:
            if 'X-Amz-Date' in request.headers:
                del request.headers['X-Amz-Date']
            request.headers['X-Amz-Date'] = request.context['timestamp'] 
開發者ID:skarlekar,項目名稱:faces,代碼行數:18,代碼來源:auth.py

示例5: send_mail

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def send_mail(send_from, send_to, subject, text, files=[], server="localhost", ssl=False, username=None, password=None):
    msg = MIMEMultipart('alternative')
    msg.set_charset('utf-8')
    msg['From'] = send_from
    msg['To'] = send_to
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject
    part = MIMEText(text)
    part.set_charset('utf-8')
    msg.attach(part)
    if ssl:
        smtp = smtplib.SMTP_SSL(server)
    else:
        smtp = smtplib.SMTP(server)
    if username:
        smtp.login(username, password)
    smtp.sendmail(send_from, send_to, msg.as_string())
    smtp.close() 
開發者ID:leancloud,項目名稱:satori,代碼行數:20,代碼來源:smtp.py

示例6: send_mail_by_postfix

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def send_mail_by_postfix(mail_to, content_type, content,
                         subject=DEFAULT_EMAIL_NOTIFY_SUBJECT,
                         mail_from=EMAIL_NOTIFY_NAME,
                         server=EMAIL_SMTP_SERVER):
    """
    使用 Postfix 作為 SMTP Server 來發送郵件
    """
    logger.debug('run send_mail_by_postfix')
    if type(mail_to) != list:
        raise TypeError('mail_to is not a list')

    if content_type not in ('plain', 'html'):
        raise ValueError('content_type is not plain or html')

    msg = MIMEMultipart()
    msg['From'] = mail_from
    msg['To'] = COMMASPACE.join(mail_to)
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject
    msg.attach(MIMEText(content, _subtype=content_type, _charset='utf-8'))

    smtp = smtplib.SMTP(server)
    smtp.sendmail(mail_from, mail_to, msg.as_string())
    smtp.close()
    logger.info('郵件發送成功') 
開發者ID:restran,項目名稱:fomalhaut-panel,代碼行數:27,代碼來源:tasks.py

示例7: send_mail_main

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def send_mail_main(subject, body, config=None):
    if config is None:
        config = current_app.config

    mail_to = config['ADMIN_EMAIL']
    mail_from = config['MAIL_FROM']
    msg = MIMEText(body, 'plain', 'UTF-8')

    msg['Subject'] = subject
    msg['To'] = mail_to
    msg['From'] = mail_from
    msg['Date'] = formatdate()
    msg['Message-ID'] = make_msgid()

    s = smtplib.SMTP(config['SMTP_HOST'])
    s.sendmail(mail_from, [mail_to], msg.as_string())
    s.quit() 
開發者ID:EdwardBetts,項目名稱:osm-wikidata,代碼行數:19,代碼來源:mail.py

示例8: WOSendMail

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def WOSendMail(send_from, send_to, subject, text, files, server="localhost",
               port=587, username='', password='', isTls=True):
    msg = MIMEMultipart()
    msg['From'] = send_from
    msg['To'] = send_to
    msg['Date'] = formatdate(localtime=True)
    msg['Subject'] = subject

    msg.attach(MIMEText(text))

    for f in files:
        part = MIMEBase('application', "octet-stream")
        part.set_payload(open(f, "rb").read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="{0}"'
                        .format(os.path.basename(f)))
        msg.attach(part)

    smtp = smtplib.SMTP(server, port)
    if isTls:
        smtp.starttls()

    smtp.sendmail(send_from, send_to, msg.as_string())
    smtp.quit() 
開發者ID:WordOps,項目名稱:WordOps,代碼行數:26,代碼來源:sendmail.py

示例9: test_authentication_timeout

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def test_authentication_timeout(self):
        def callback():
            blockchain = BtcTxStore()
            wif = blockchain.create_key()
            address = blockchain.get_address(wif)
            farmer = Farmer(address)

            timeout = farmer.get_server_authentication_timeout()

            date = datetime.now() - timedelta(seconds=timeout)
            header_date = formatdate(timeval=mktime(date.timetuple()),
                                     localtime=True, usegmt=True)
            message = farmer.get_server_address() + " " + header_date
            header_authorization = blockchain.sign_unicode(wif, message)
            headers = {"Date": header_date,
                       "Authorization": header_authorization}
            farmer.authenticate(headers)
        self.assertRaises(storjcore.auth.AuthError, callback) 
開發者ID:StorjOld,項目名稱:dataserv,代碼行數:20,代碼來源:test_Farmer.py

示例10: test_success

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def test_success(self):

        # create header date and authorization signature
        blockchain = BtcTxStore()
        wif = blockchain.create_key()
        address = blockchain.get_address(wif)
        header_date = formatdate(timeval=mktime(datetime.now().timetuple()),
                                 localtime=True, usegmt=True)
        message = app.config["ADDRESS"] + " " + header_date
        header_authorization = blockchain.sign_unicode(wif, message)
        headers = {"Date": header_date, "Authorization": header_authorization}
        url = '/api/register/{0}'.format(address)
        rv = self.app.get(url, headers=headers)
        data = json.loads(rv.data.decode("utf-8"))
        self.assertEqual(address, data["btc_addr"])
        self.assertEqual(rv.status_code, 200) 
開發者ID:StorjOld,項目名稱:dataserv,代碼行數:18,代碼來源:test_App.py

示例11: http_date

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def http_date(timeval=None):
    """返回符合HTTP標準的GMT時間字符串,用strftime的格式表示就是"%a, %d %b %Y %H:%M:%S GMT"。
    但不能使用strftime,因為strftime的結果是和locale相關的。
    """
    return formatdate(timeval, usegmt=True) 
開發者ID:jumpserver,項目名稱:jumpserver-python-sdk,代碼行數:7,代碼來源:utils.py

示例12: default

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def default(self, object_: Any) -> Any:
        if isinstance(object_, date):
            return formatdate(timeval=mktime((object_.timetuple())), localtime=False, usegmt=True)
        if isinstance(object_, UUID):
            return str(object_)
        if hasattr(object_, "__html__"):
            return str(object_.__html__())
        return super().default(object_) 
開發者ID:pgjones,項目名稱:quart,代碼行數:10,代碼來源:__init__.py

示例13: send_mail

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def send_mail(self, msg):
        if _mail.recip:
            # write message to temp file for rate limit
            with open(self.temp_msg, 'w+') as f:
                f.write(msg)

            self.current_time()

            message = MIMEMultipart()
            message['From'] = _mail.s_addr
            message['To'] = _mail.recip
            message['Subject'] = _mail.subject
            message['Date'] = formatdate(localtime=True)
            message.attach(MIMEText('{} {}'.format(self.time, msg), 'plain'))
            text = message.as_string()

            try:
                server = smtplib.SMTP(_mail.server, _mail.port)
            except socket.error as err:
                playout_logger.error(err)
                server = None

            if server is not None:
                server.starttls()
                try:
                    login = server.login(_mail.s_addr, _mail.s_pass)
                except smtplib.SMTPAuthenticationError as serr:
                    playout_logger.error(serr)
                    login = None

                if login is not None:
                    server.sendmail(_mail.s_addr, _mail.recip, text)
                    server.quit() 
開發者ID:ffplayout,項目名稱:ffplayout-engine,代碼行數:35,代碼來源:utils.py

示例14: _strtime_to_httpdate

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def _strtime_to_httpdate(dt):
        return email_utils.formatdate(calendar.timegm(
            iso8601.parse_date(dt).timetuple()), usegmt=True) 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:5,代碼來源:test_rest.py

示例15: datetime_to_header

# 需要導入模塊: from email import utils [as 別名]
# 或者: from email.utils import formatdate [as 別名]
def datetime_to_header(dt):
    return formatdate(calendar.timegm(dt.timetuple())) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:4,代碼來源:heuristics.py


注:本文中的email.utils.formatdate方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。