attachment
很多同学在进行编程学习时缺乏系统学习的资料。本页面基于attachment内容,从基础理论到综合实战,通过实用的知识类文章,标准的编程教程,丰富的视频课程,为您在attachment相关知识领域提供全面立体的资料补充。同时还包含 android、a href、abap 的知识内容,欢迎查阅!
attachment相关知识
-
web前端-CSS3属性学习(2)-背景属性(Background)W3C中第二部分为背景属性(Background),共列举9个属性:background、background-attachment、background-color、background-image、background-position、background-repeat、background-clip、background-origin、background-size。背景属性在CSS中运用广泛,目前各大浏览器都支持9个属性。详细学习: http://www.w3school.com.cn/cssref/index.asp。 下为简单介绍: - 兼容性 background、background-attachment、background-color、background-image、background-position、background
-
python Email 邮件发送模块""" AUTHOR: YOU VERSION: V1.0.00 DESC: 邮件操作模块 INTRO: 使用简介 # 创建邮件对象 mail = MailSender('smtp.163.com', 465, '填写邮箱登录账号', '填写邮箱授权密码') # 添加附件 mail.add_attachment('../attachment/py08tools-1.00.001.tar.gz') mail.add_attachment('../attachment
-
学习扁平化博客风格后的纪要消除板块之间的间隙 font-size:0; 背景图片的处理 background: url('/imgs/back.jpg') no-repeat top center; background-attachment: fixed; background-size: cover;
-
Docker运行参数详解Docker运行参数详解 docker search 参数:MacdeMacBook-Pro:~ mac$ docker network create --helpUsage: docker network create [OPTIONS] NETWORKCreate a networkOptions: --attachable Enable manual container attachment --aux-address map Auxiliary IPv4 or IPv6 addresses used by Network driver (default map[]) --config-from string The network from which copying the configuration --config-only Create a configuration only network -d
attachment相关课程
attachment相关教程
- 5.2 发送带有附件的邮件 import smtplibfrom email.header import Headerfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipart导入 smtplib 用于发送邮件导入类 Header 和 MIMEText 用于构造邮件导入类 MIMEMultipart 用于构造带有附件的邮件fromAddr ='zhangsan@qq.com'password = 'password for smtp'toAddr ='zhangsan@qq.com'subject = 'hello with attachment'content = '你好,请查收附件'fromAddr 为发送邮件地址toAddr 为目的邮件地址,设置成与发送邮件地址相同,表示向自己发送一封邮件password 是使用 SMTP 服务的密码,不是 QQ 邮箱的登录密码,请查看第 2 小节subject 是邮件标题content 是邮件内容def makeAttachment(filename): file = open(filename, 'rb') blob = file.read() attachment = MIMEText(blob, 'base64', 'utf-8') attachment["Content-Type"] = 'application/octet-stream' attachment["Content-Disposition"] = 'attachment; filename="%s"' % filename return attachment在第 1 行,函数 makeAttachment 构造一个附件在第 2 行到第 3 行,读取当前目录下的文件 filename 的内容在第 3 行,构造附件对象 attachment在第 4 行到第 5 行,设置附件属性def makeMail(): mail = MIMEMultipart() mail['From'] = Header(fromAddr, 'utf-8') mail['To'] = Header(toAddr, 'utf-8') mail['Subject'] = Header(subject, 'utf-8') mail.attach(MIMEText(content, 'plain', 'utf-8')) return mail在第 1 行,函数 makeMail() 根据 fromAddr、toAddr、subject、content 构造一封邮件在第 2 行,使用 MIMEMultipart 构造一个带有附件的邮件在第 3 行,构造邮件头 From在第 4 行,构造邮件头 To在第 5 行,构造邮件头 Subject在第 6 行,设置邮件的正文 contentdef sendMail(mail): server = smtplib.SMTP_SSL("smtp.qq.com") server.login(fromAddr, password) server.sendmail(fromAddr, toAddr, mail.as_string()) server.quit()在第 1 行,函数 sendMail 调用 SMTP 服务发送邮件 mail在第 2 行,获取 SMTP 服务器,使用 QQ 发送服务在第 3 行,登录 SMTP 服务在第 4 行,通过 SMTP 服务器发送服务mail = makeMail()attachment = makeAttachment('hello.c')mail.attach(attachment)sendMail(mail)print('发送邮件成功')在第 2 行,构造一个附件 hello.c在第 3 行,将附件加入到邮件中运行程序,在 QQ 邮箱中收到邮件:
- 4. 异步 I/O 操作说明 异步 Socket 编程的一个关键点是:AsynchronousServerSocketChannel 和 AsynchronousSocketChannel 提供的一组 I/O 操作是异步的,方法调用完后会立即返回,而不会关心操作是否完成,并不会阻塞调用线程。如果要想获取 I/O 操作的结果,可以通过 Future 的方式,或者是 CompletionHandler 的方式。下面列举的 connect、accept、read、write 四组 I/O 方法,返回值是 Future 对象的 I/O 方法,前面已经介绍。还有就是需要传入一个 attachment 参数和一个 CompletionHandler 参数,这是基于完成例程的方式。connect 异步操作public abstract Future<Void> connect(SocketAddress remote);public abstract <A> void connect(SocketAddress remote, A attachment, CompletionHandler<Void,? super A> handler);accept 异步操作public abstract Future<AsynchronousSocketChannel> accept();public abstract <A> void accept(A attachment, CompletionHandler<AsynchronousSocketChannel,? super A> handler);read 异步操作public abstract Future<Integer> read(ByteBuffer dst);public final <A> void read(ByteBuffer dst, A attachment, CompletionHandler<Integer,? super A> handler) write 异步操作public abstract Future<Integer> write(ByteBuffer src); public final <A> void write(ByteBuffer src, A attachment, CompletionHandler<Integer,? super A> handler) 通过 Future 实现异步客户端、服务器程序,尽管 I/O 相关方法调用是异步的,但是还得通过 Future 的 get 方法获取操作的结果,而 Future 的 get 调用是同步的,所以还是没有做到完全异步。而通过 CompletionHandler 获取 I/O 结果,所有 I/O 操作的执行结果都会通过 CompletionHandler 回调返回。
- 3.5 SelectionKey 介绍 SelectionKey 是由 AbstractSelectableChannel 的 register 方法返回的,主要包含一个事件类型和上下文对象。SelectionKey 提供了一组方法,用以识别 I/O 事件类型。声明如下:public final boolean isAcceptable()public final boolean isConnectable()public final boolean isReadable()public final boolean isWritable()可以通过 SelectionKey 的 channel 方法,获取关联的 Channel,声明如下:public abstract SelectableChannel channel()可以通过 SelectionKey 的 attachment 方法,获取关联的上下文对象。public final Object attachment()SelectionKey 的各个方法相对简单,容易理解,我们在前面小节多次提到,不再赘述。
- 4.浏览器下载导出 设置好文件名后,就可以下载导出 Excel 了: $file = "学生信息".date('YmdHis').".xlsx"; $writer = new Xlsx($spreadsheet); header('Content-Disposition: attachment;filename='.$file);//告诉浏览器将输出文件的名称 header('Cache-Control: max-age=0');//禁止缓存 $writer->save("php://output");;
- 5. 基于 CompletionHandler 编写服务器 基于 CompletionHandler 编写服务器,关键是两步:需要给每一个 I/O 操作传入一个 attachment 参数,这是用来记录用户上下文信息的。在示例代码中,我们抽象了一个类表示上下文信息。private static class AsyncIOOP { private int op_type; private ByteBuffer read_buffer; private AsynchronousSocketChannel client;}还需要传入一个 CompletionHandler 参数,这需要你自定义一个类并且实现 CompletionHandler 接口。由于 accept 操作和其他三个操作不同,所以我们定义了两个实现 CompletionHandler 接口的类。private static class AsyncIOOPCompletionHandler implements CompletionHandler<Integer, AsyncIOOP>{}private static class AsyncAcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, syncIOOP>{}每一个 I/O 操作完成,系统都会回调 CompletionHandler 的 completed 方法,你需要覆盖此方法,然后处理返回结果。示例代码实现的是一个 Echo 逻辑,关键步骤如下:服务器启动的时候,投递一个 accept 操作。当收到 accept 操作完成,首先投递一个 accept 操作,准备接收新客户端请求;然后为刚接收的客户端投递一个 read 操作,准备接收数据。当收到 read 操作完成,向客户端投递一个 write 操作,发送响应给客户端;然后再次投递一个 read 操作,准备接收新的消息。当收到 write 操作完成,我们没有处理逻辑,因为这是一个简单的 Echo 功能。完整代码如下:import java.io.IOException;import java.net.InetSocketAddress;import java.nio.ByteBuffer;import java.nio.channels.AsynchronousServerSocketChannel;import java.nio.channels.AsynchronousSocketChannel;import java.nio.channels.CompletionHandler;public class AsyncServerCompletionHandler { private static final int PORT =56002; private AsynchronousServerSocketChannel server = null; private static final int ASYNC_READ = 1; private static final int ASYNC_WRITE = 2; private static final int ASYNC_ACCEPT = 3; private static final int ASYNC_CONNECT = 4; private static class AsyncIOOP { private int op_type; private ByteBuffer read_buffer; private AsynchronousSocketChannel client; public int getOp_type() { return op_type; } public void setOp_type(int op_type) { this.op_type = op_type; } public ByteBuffer getRead_buffer() { return read_buffer; } public void setRead_buffer(ByteBuffer read_buffer) { this.read_buffer = read_buffer; } public AsynchronousSocketChannel getClient() { return client; } public void setClient(AsynchronousSocketChannel client) { this.client = client; } public AsyncIOOP(int op) { this(op, null, null); } public AsyncIOOP(int op, ByteBuffer b) { this(op, b, null); } public AsyncIOOP(int op, ByteBuffer b, AsynchronousSocketChannel ch) { this.op_type = op; this.read_buffer = b; this.client = ch; } } private static class AsyncIOOPCompletionHandler implements CompletionHandler<Integer, AsyncIOOP> { private AsyncServerCompletionHandler server; public AsyncIOOPCompletionHandler(AsyncServerCompletionHandler server){ this.server = server; } @Override public void completed(Integer result, AsyncIOOP attachment) { if (attachment.op_type == ASYNC_READ) { server.async_write(attachment.getClient(), "Hello Client!"); ByteBuffer inBuffer = attachment.getRead_buffer(); System.out.println("Recv message from client:" + new String(inBuffer.array()).trim()); server.async_read(attachment.getClient()); } else if (attachment.op_type == ASYNC_WRITE) { } } @Override public void failed(Throwable exc, AsyncIOOP attachment) { try { attachment.getClient().close(); } catch (IOException e) { e.printStackTrace(); } } } private static class AsyncAcceptCompletionHandler implements CompletionHandler<AsynchronousSocketChannel, AsyncIOOP> { private AsyncServerCompletionHandler server; public AsyncAcceptCompletionHandler(AsyncServerCompletionHandler server) { this.server = server; } @Override public void completed(AsynchronousSocketChannel result, AsyncIOOP attachment) { if (attachment.op_type == ASYNC_ACCEPT) { server.accept_new_client(); if (result != null && result.isOpen()) { server.async_read(result); } } } @Override public void failed(Throwable exc, AsyncIOOP attachment) { } } public void start() { try { server = AsynchronousServerSocketChannel.open(); server.bind(new InetSocketAddress("127.0.0.1", PORT)); accept_new_client(); } catch (Exception e) { e.printStackTrace(); stop(); } } public void accept_new_client() { server.accept(new AsyncIOOP(ASYNC_ACCEPT), new AsyncAcceptCompletionHandler(this)); } public void async_read(AsynchronousSocketChannel client){ ByteBuffer inBuffer = ByteBuffer.allocate(128); AsyncIOOP ioop = new AsyncIOOP(ASYNC_READ, inBuffer, client); client.read(inBuffer, ioop, new AsyncIOOPCompletionHandler(this)); } public void async_write(AsynchronousSocketChannel client, String message){ ByteBuffer outBuffer = ByteBuffer.wrap(message.getBytes()); AsyncIOOP ioop = new AsyncIOOP(ASYNC_WRITE, outBuffer, client); client.write(outBuffer, ioop, new AsyncIOOPCompletionHandler(this)); } public void stop(){ if (server != null){ try { server.close(); } catch (IOException e) { e.printStackTrace(); } } } public static void main(String[] args) { AsyncServerCompletionHandler server = new AsyncServerCompletionHandler(); server.start(); try { Thread.sleep(1000*1000); } catch (InterruptedException e) { e.printStackTrace(); } }}
- 4. 发送带附件的邮件 发送邮件如下代码所示:import smtplibfrom email.mime.text import MIMETextfrom email.mime.multipart import MIMEMultipartfrom email.mime.application import MIMEApplicationhost_server = 'smtp.qq.com' # 主机地址# 发件人邮箱sender = "389818529@qq.com"# 发件人邮箱授权码code = "xlogucqphohxcabi"# 收件人user = "yanwydxf@163.com"# 准备邮件数据# 邮件标题mail_title = "第三封邮件"# 邮件内容mail_content = "具体请查看附件!"# SMTPsmtp = smtplib.SMTP(host_server)# 登录smtp.login(sender, code)#构建附件attachment=MIMEApplication(open('newinfo.xlsx','rb').read())#为附件添加一个标题attachment.add_header('Content-Disposition','attachment',filename='data.xlsx')msg=MIMEMultipart()#构建带附件的实例#邮件标题msg['Subject'] = mail_title#发件人msg['From'] = sender#收件人msg['To'] = user# 发送smtp.sendmail(sender, user, msg.as_string())代码解释:在发送普通邮件的代码的基础上,导入 email 模块下 MIMEMultipart 与 MIMEApplication 用于构建附件。首先通过 MIMEApplication 封装附件,newinfo.xlsx 为本地文件名称, data.xlsx 为发送到对方邮箱后所显示的名称。通过 MIMEMultipart 构建带附件的实例,其他内容不变。执行完成后,打开收件邮件即可收到第三封邮件,如下图所示。
attachment相关搜索
-
ajax
android
a href
abap
abap开发
abort
absolutelayout
abstractmethoderror
abstracttablemodel
accept
access
access教程
accordion
accumulate
acess
action
actionform
actionlistener
activity
addeventlistener