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


Python Utils.formatdate方法代碼示例

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


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

示例1: send

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def send(self, data):
        """
        Publish some data

        @type	data: string
        @param	data: Data to publish
        """
        # Build Message Body
        msg = MIMEMultipart()
        msg['From'] = self.msgFrom
        msg['To'] = self.msgTo
        msg['Date'] = formatdate(localtime=True)
        msg['Subject'] = self.msgSubject
        msg.attach(MIMEText(self.msgText))
        # Attach file
        part = MIMEBase('application', 'pdf')
        part.set_payload(data)
        Encoders.encode_base64(part)
        part.add_header('Content-Disposition', 'attachment; filename="%s"' % self.fileName)
        msg.attach(part)
        # Send email
        smtp = smtplib.SMTP(self.server)
        smtp.sendmail(self.msgFrom, self.msgTo, msg.as_string())
        smtp.close() 
開發者ID:MozillaSecurity,項目名稱:peach,代碼行數:26,代碼來源:smtp.py

示例2: message

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def message(self):
        encoding = self.encoding or settings.DEFAULT_CHARSET
        msg = SafeMIMEText(smart_str(self.body, encoding),
                           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'] = ', '.join(self.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:
            msg['Message-ID'] = make_msgid()
        for name, value in self.extra_headers.items():
            if name.lower() == 'from':  # From is already handled
                continue
            msg[name] = value
        return msg 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:23,代碼來源:message.py

示例3: __next__

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def __next__(self):
        formatted = formatdate(self.time, True)
        self.time += 1
        return formatted 
開發者ID:Pagure,項目名稱:pagure,代碼行數:6,代碼來源:git_multimail_upstream.py

示例4: _get_msg_time

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def _get_msg_time():
    timestamp = time.mktime((2010, 12, 12, 1, 1, 1, 1, 1, 1))
    return formatdate(timestamp) 
開發者ID:leapcode,項目名稱:bitmask-dev,代碼行數:5,代碼來源:test_mail.py

示例5: test_formatdate

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def test_formatdate(self):
        now = time.time()
        self.assertEqual(Utils.parsedate(Utils.formatdate(now))[:6],
                         time.gmtime(now)[:6]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:6,代碼來源:test_email.py

示例6: test_formatdate_localtime

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def test_formatdate_localtime(self):
        now = time.time()
        self.assertEqual(
            Utils.parsedate(Utils.formatdate(now, localtime=True))[:6],
            time.localtime(now)[:6]) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:7,代碼來源:test_email.py

示例7: test_formatdate_usegmt

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def test_formatdate_usegmt(self):
        now = time.time()
        self.assertEqual(
            Utils.formatdate(now, localtime=False),
            time.strftime('%a, %d %b %Y %H:%M:%S -0000', time.gmtime(now)))
        self.assertEqual(
            Utils.formatdate(now, localtime=False, usegmt=True),
            time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.gmtime(now))) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_email.py

示例8: mail_headers

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def mail_headers(self, group, params):
    from email import Utils
    subject = self.make_subject(group, params)
    try:
      subject.encode('ascii')
    except UnicodeError:
      from email.Header import Header
      subject = Header(subject, 'utf-8').encode()
    hdrs = 'From: %s\n'    \
           'To: %s\n'      \
           'Subject: %s\n' \
           'Date: %s\n' \
           'Message-ID: %s\n' \
           'MIME-Version: 1.0\n' \
           'Content-Type: text/plain; charset=UTF-8\n' \
           'Content-Transfer-Encoding: 8bit\n' \
           'X-Svn-Commit-Project: %s\n' \
           'X-Svn-Commit-Author: %s\n' \
           'X-Svn-Commit-Revision: %d\n' \
           'X-Svn-Commit-Repository: %s\n' \
           % (self.from_addr, ', '.join(self.to_addrs), subject, 
              Utils.formatdate(), Utils.make_msgid(), group,
              self.repos.author or 'no_author', self.repos.rev,
              os.path.basename(self.repos.repos_dir))
    if self.reply_to:
      hdrs = '%sReply-To: %s\n' % (hdrs, self.reply_to)
    return hdrs + '\n' 
開發者ID:znick,項目名稱:anytask,代碼行數:29,代碼來源:mailer.py

示例9: _mail_recipient

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def _mail_recipient(recipient_name, recipient_email,
                    sender_name, sender_url, subject,
                    body, headers={}):
    mail_from = config.get('smtp.mail_from')
    msg = MIMEText(body.encode('utf-8'), 'plain', 'utf-8')
    for k, v in headers.items():
        msg[k] = v
    subject = Header(subject.encode('utf-8'), 'utf-8')
    msg['Subject'] = subject
    msg['From'] = _("%s <%s>") % (sender_name, mail_from)
    recipient = u"%s <%s>" % (recipient_name, recipient_email)
    msg['To'] = Header(recipient, 'utf-8')
    msg['Date'] = Utils.formatdate(time())
    msg['X-Mailer'] = "CKAN %s" % ckan.__version__

    # Send the email using Python's smtplib.
    smtp_connection = smtplib.SMTP()
    if 'smtp.test_server' in config:
        # If 'smtp.test_server' is configured we assume we're running tests,
        # and don't use the smtp.server, starttls, user, password etc. options.
        smtp_server = config['smtp.test_server']
        smtp_starttls = False
        smtp_user = None
        smtp_password = None
    else:
        smtp_server = config.get('smtp.server', 'localhost')
        smtp_starttls = paste.deploy.converters.asbool(
            config.get('smtp.starttls'))
        smtp_user = config.get('smtp.user')
        smtp_password = config.get('smtp.password')

    try:
        smtp_connection.connect(smtp_server)
    except socket.error, e:
        log.exception(e)
        raise MailerException('SMTP server could not be connected to: "%s" %s'
                              % (smtp_server, e)) 
開發者ID:italia,項目名稱:daf-recipes,代碼行數:39,代碼來源:mailer.py

示例10: cookie_date

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def cookie_date(epoch_seconds=None):
    """
    Formats the time to ensure compatibility with Netscape's cookie standard.

    Accepts a floating point number expressed in seconds since the epoch, in
    UTC - such as that outputted by time.time(). If set to None, defaults to
    the current time.

    Outputs a string in the format 'Wdy, DD-Mon-YYYY HH:MM:SS GMT'.
    """
    rfcdate = formatdate(epoch_seconds)
    return '%s-%s-%s GMT' % (rfcdate[:7], rfcdate[8:11], rfcdate[12:25]) 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:14,代碼來源:http.py

示例11: http_date

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def http_date(epoch_seconds=None):
    """
    Formats the time to match the RFC1123 date format as specified by HTTP
    RFC2616 section 3.3.1.

    Accepts a floating point number expressed in seconds since the epoch, in
    UTC - such as that outputted by time.time(). If set to None, defaults to
    the current time.

    Outputs a string in the format 'Wdy, DD Mon YYYY HH:MM:SS GMT'.
    """
    rfcdate = formatdate(epoch_seconds)
    return '%s GMT' % rfcdate[:25]

# Base 36 functions: useful for generating compact URLs 
開發者ID:GoogleCloudPlatform,項目名稱:python-compat-runtime,代碼行數:17,代碼來源:http.py

示例12: open_local_file

# 需要導入模塊: from email import Utils [as 別名]
# 或者: from email.Utils import formatdate [as 別名]
def open_local_file(self, req):
        try:
            import email.utils as emailutils
        except ImportError:
            # python 2.4
            import email.Utils as emailutils
        import mimetypes
        host = req.get_host()
        file = req.get_selector()
        localfile = url2pathname(file)
        try:
            stats = os.stat(localfile)
            size = stats.st_size
            modified = emailutils.formatdate(stats.st_mtime, usegmt=True)
            mtype = mimetypes.guess_type(file)[0]
            headers = mimetools.Message(StringIO(
                'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
                (mtype or 'text/plain', size, modified)))
            if host:
                host, port = splitport(host)
            if not host or \
                (not port and socket.gethostbyname(host) in self.get_names()):
                return addinfourl(open(localfile, 'rb'),
                                  headers, 'file:'+file)
        except OSError, msg:
            # urllib2 users shouldn't expect OSErrors coming from urlopen()
            raise URLError(msg) 
開發者ID:rajeshmajumdar,項目名稱:BruteXSS,代碼行數:29,代碼來源:_urllib2_fork.py


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