From d4c683c2dd47a2d3d6e6f57130ea198dcdd5ed4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 30 Jun 2015 21:43:52 +0800 Subject: [PATCH 001/116] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=87=A0=E5=A4=84?= =?UTF-8?q?=E7=AC=94=E8=AF=AF=EF=BC=8C=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 213 ++++++++++++++++++-------------------------------- 1 file changed, 77 insertions(+), 136 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 59fc4f7..8fd3597 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -6,12 +6,10 @@ 本页面汇总俺收集的各种 C 和 C++ 的开源代码库,不定期更新。 -如果你发现本页面的开源库有错漏之处,有 GitHub 帐号的同学,可以给俺发 issue;没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 - +如果你发现本页面的开源库有错漏之处,非常欢迎给俺提供反馈——有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 ---- - = 1 综合性的库 =

Boost

@@ -98,10 +96,8 @@ Wikipedia:[https://en.wikipedia.org/wiki/Crypto%2B%2B 英文] 虽然它以加密为主,但是也提供了其它一些辅助功能(比如:数据压缩、编码解码、计时器...) - ---- - = 2 数据结构 & 算法 = == 2.1 容器 == @@ -116,7 +112,7 @@ STL 标准库提供了如下: * 链表:list(双向)、forward_list(单向) -* 队列:deque、deque(双端队列) +* 队列:queue、deque(双端队列) * 栈:stack @@ -126,7 +122,7 @@ STL 标准库提供了如下: === 2.1.2 Lockfree 的容器 === -(“lock-free”翻译成“锁无关”会引发歧义,所以俺直接洋文) +(“lock-free”翻译成“锁无关”会引发歧义,所以俺直接用洋文)

Boost.Lockfree

@@ -155,7 +151,6 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ #include boost::circular_buffer cb(3); // Create with capacity for 3 integers - cb.push_back(1); cb.push_back(2); cb.push_back(3); @@ -214,11 +209,9 @@ Docs:[http://dlib.net/graph_tools.html] Dlib 前面已经介绍过。它提供了2个类(graph & directed_graph)封装“图”。 - == 2.2 对容器的操作 == (STL 标准库里面已经实现了很多算法用来操作容器,考虑到本页面已经很长,这里只列举第三方库实现的算法) -

Boost.Foreach

Docs:[http://boost.org/libs/foreach] @@ -227,21 +220,19 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了通 有了它,你在遍历时无需声明迭代器变量,也无需关心遍历的容器是何种类型。 -代码示例 +代码示例——遍历字符串 #include #include #include std::string test("Hello, world!"); // string 可以视为 char 的容器 - BOOST_FOREACH(char ch, test) { std::cout << ch; } - == 2.3 字符串处理 == === 2.3.1 字符集 === @@ -344,7 +335,6 @@ Docs:[http://doc.qt.io/qt-4.8/qregexp.html] Qt 前面已经介绍过。这是 Qt 中的一个类,提供了“正则式”的功能。 - === 2.3.4 (其它) ===

Boost.StringAlgorithms

@@ -361,7 +351,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了各 #include std::vector v; -// ... +// 此处填充 v std::cout << boost::algorithm::join(v, " ") << '\n'; @@ -386,7 +376,6 @@ double d = boost::lexical_cast(s); std::cout << d << '\n'; - == 2.4 内存相关 == === 2.4.1 智能指针 === @@ -421,7 +410,6 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了内存池的功能。 - == 2.5 时间 & 日期 ==

Boost.Date_Time

@@ -430,7 +418,6 @@ Docs:[http://boost.org/libs/date_time] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了针对“日期 和 时间”的各种处理。 - == 2.6 编码 & 解码 == === 2.6.1 序列化 === @@ -439,7 +426,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了针 Docs:[http://boost.org/libs/serialization] -Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了【可定制的】“序列化”功能。。 +Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了【可定制的】“序列化”功能。 === 2.6.2 Base64 === @@ -457,7 +444,6 @@ Docs:[http://www.cryptopp.com/docs/ref/annotated.html] Crypto++ 前面已经介绍过。它提供了6个类,分别用于 Base64、Base32、Base16 的编码/解码。 - == 2.7 (其它) == === 2.7.1 随机数 === @@ -528,13 +514,11 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了 UUID 的生成、格式化成字符串、解析 UUID 字符串。 - ---- - = 3 编程范式 = -(这一章节主要针对 C++——“支持多范式”是 C+ +的一大特色) +(这一章节主要针对 C++——“支持多范式”是 C++ 的一大特色) == 3.1 面向对象编程(OOP) == @@ -558,7 +542,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,用来辅助 注:Boost 的这个子库已经进入 C++ 11 标准。 -代码示例 +代码示例——封装标准 C 的函数 #include #include @@ -588,12 +572,11 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ #include std::vector v; -// ... +// 此处填充 v std::for_each(v.begin(), v.end(), std::cout << boost::lambda::_1 << "\n"); - == 3.4 元编程(Metaprogramming) == (不知道何为“元编程”,可以先看[https://zh.wikipedia.org/wiki/%E5%85%83%E7%BC%96%E7%A8%8B 维基百科]) @@ -610,13 +593,11 @@ Docs:[http://dlib.net/metaprogramming.html] Dlib 前面已经介绍过。它提供了“模板元编程”的辅助类。 - ---- - = 4 调试 & 测试 = -=== 4.1 调试日志 === +== 4.1 调试日志 ==

Boost.Log

@@ -668,8 +649,7 @@ Home:[http://log4cpp.sourceforge.net/] 如其名,这是一个模仿 log4j 的 C++ 库。支持多种操作系统(包括 Windows)。 - -=== 4.2 单元测试 === +== 4.2 单元测试 ==

Boost.Test

@@ -700,7 +680,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Check_%28unit_testing_framework%29 /* The basic unit test looks as follows: */ START_TEST (test_name) { - /* unit test code */ + /* unit test code */ } END_TEST /* The "START_TEST/END_TEST" pair are macros that setup basic structures to permit testing. @@ -708,8 +688,7 @@ END_TEST doing so produces all sorts of strange errors when the check is compiled. */ - -=== 4.3 检测内存泄漏 === +== 4.3 检测内存泄漏 ==

Boost.Test.ExecutionMonitor

@@ -717,13 +696,10 @@ Docs:[http://boost.org/libs/test/doc/html/execution-monitor.html] Boost 前面已经介绍过。这是 Boost 的其中一个子库,它除了提供“单元测试”,还提供“内存泄漏的检测”。 - ---- - = 5 操作系统相关 = - == 5.1 跨操作系统 == === 5.1.1 文件系统 === @@ -764,7 +740,6 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“文件信息、文件名匹配”等功能。 - === 5.1.2 线程 ===

Boost.Thread

@@ -815,7 +790,6 @@ Home:[http://www.gnu.org/software/commoncpp/] 由 GNU 提供的一套跨平台的线程并发框架。 - === 5.1.3 进程 ===

ACE

@@ -830,7 +804,6 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“进程管理”的功能。 - === 5.1.4 本地进程间通信(IPC) === (本章节列举的是【本地】IPC,跨主机的网络通讯,参见本页面后续的章节) @@ -853,7 +826,6 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“进程同步、共享内存、信号处理”等功能。 - == 5.2 特定于 Windows 系统 == === 5.2.1 注册表 === @@ -878,18 +850,15 @@ Docs:[http://pocoproject.org/docs/Poco.Util.html] POCO 前面已经介绍过。它提供了相应的封装类(WinService),可以用来操作 Service(注册、删除、启动、停止)。 - == 5.3 特定于 Linux & Unix 系统 == - - ---- -= 6 桌面 GUI 开发 = += 6 GUI 开发 = == 6.1 GUI 框架 == -=== 6.1.1 跨平台的 GUI 框架 === +=== 6.1.1 跨平台的 GUI 框架 ===

wxWidgets

@@ -931,7 +900,7 @@ bool MyApp::OnInit() } MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) - : wxFrame(NULL, wxID_ANY, title, pos, size) + : wxFrame(NULL, wxID_ANY, title, pos, size) { wxMenu* menuFile = new wxMenu(); menuFile->Append(wxID_EXIT); @@ -954,7 +923,7 @@ Qt 前面已经介绍过。下面给出一个 Hello world 的示例,让你看 #include #include - + int main(int argc, char* argv[]) { QApplication app(argc, argv); @@ -975,7 +944,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/GTK%2B 英文]、[https://zh.wikipedi 代码示例——Hello world #include - + int main(int argc, char* argv[]) { gtk_init(&argc, &argv); @@ -1014,7 +983,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/FLTK 英文]、[https://zh.wikipedia. #include #include #include - + int main(int argc, char **argv) { Fl_Window* window = new Fl_Window(300, 180); @@ -1030,7 +999,6 @@ int main(int argc, char **argv) } - === 6.1.2 特定于 Windows 的 GUI 框架 ===

WTL(Windows Template Library)

@@ -1041,8 +1009,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Windows_Template_Library 英文]、[h 这是微软雇员 Nenad Stefanovic 开发的开源 GUI 框架。开发 WTL 是为了提供一个轻量级的 MFC 替代品。 - -== 6.2 图表/Chart == +== 6.2 图表(Chart) ==

Qt

@@ -1106,10 +1073,8 @@ Home:[http://wxmathplot.sourceforge.net/] 看名称就知道它是跟 wxWidgets 搭配的。效果图参见“[http://wxmathplot.sourceforge.net/screenshot.shtml 这里]” - ---- - = 7 网络编程 = == 7.1 标准协议 == @@ -1132,7 +1097,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Pcap 英文] 它是 libpcap 在 Windows 系统下的移植。 - === 7.1.2 传输层 ===

socket

@@ -1159,7 +1123,6 @@ Docs:[http://pocoproject.org/docs/Poco.Net.html] POCO 前面已经介绍过。它提供了针对 TCP 服务端的封装类。 - === 7.1.3 应用层 ===

cURL & libcurl

@@ -1223,14 +1186,13 @@ Docs:[http://pocoproject.org/docs/Poco.Net.html] POCO 前面已经介绍过。它提供了几种常见应用层协议(HTTP、SMTP、POP3、FTP、NTP)的封装类。 - == 7.2 自定义协议 ==

Protocol Buffers

Home:[https://developers.google.com/protocol-buffers/] -Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers Protocol 英文] +Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] 它是 Google 开发的一个跨语言的库,用于传输业务数据时的“编码/解码”。其优点是:跨多种语言、高性能、向前兼容、向后兼容。 @@ -1349,10 +1311,8 @@ Docs:[http://dlib.net/network.html] Dlib 前面已经介绍过。它针对网络通讯,提供了比较高的抽象层。 - ---- - = 8 数据库 = == 8.1 开源数据库 == @@ -1365,7 +1325,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/MySQL 英文]、[https://zh.wikipedia 名气最大的开源数据库,诞生于1995年,采用 C 和 C++ 语言开发。如今隶属于 Oracle 公司。 -=== PostgreSQL === +

PostgreSQL

Home:[http://postgresql.org/] @@ -1373,7 +1333,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/PostgreSQL 英文]、[https://zh.wiki 名气仅次于 MySQL 的开源数据库,诞生于1996年。采用 C 语言开发。 -=== SQLite === +

SQLite

Home:[http://sqlite.org/] @@ -1391,7 +1351,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/MongoDB 英文] MongoDB 是近几年兴起的 NoSQL 数据库的一员。它本身是基于 C++ 和 C 开发的。 - == 8.2 数据库 API 的封装库 == === 8.2.1 综合性的封装库 === @@ -1406,7 +1365,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Oracle_Template_Library 英文] 它的特色是:全部代码都在一个头文件中。 -代码示例 +代码示例——操作 Oracle 数据库 #include #include @@ -1454,7 +1413,7 @@ Home:[http://dev.mysql.com/doc/connector-cpp/en/] 这是 MySQL 官方提供的 C++ 封装。 -代码示例 +代码示例——执行 SQL 语句 sql::mysql::MySQL_Driver* driver = sql::mysql::MySQL_Driver::get_mysql_driver_instance(); sql::Connection* conn = driver->connect("tcp://127.0.0.1:3306", "user", "password"); @@ -1510,7 +1469,7 @@ void update(const std::string& name) } int employee_id = r[0][0].as(); - std::cout << "Updating employee #" << employee_id << std::endl; + std::cout << "Updating employee #" << employee_id << std::endl; txn.exec( "UPDATE EMPLOYEE SET salary = salary + 1 " @@ -1535,6 +1494,7 @@ Home:[http://vrogier.github.io/ocilib/] #include using namespace ocilib; + int main() { try @@ -1568,7 +1528,7 @@ int main() Docs:[http://sqlite.org/c3ref/intro.html] -由于 sqlite 本身就是用 C 语言开发的,因此它直接提供了基于 C 的 API 接口。 +SQLite 前面已经介绍过。由于 SQLite 本身就是用 C 语言开发的,因此它直接提供了基于 C 的 API 接口。 代码示例 @@ -1627,6 +1587,8 @@ POCO 前面已经介绍过。它提供了 sqlite 的封装类 Docs:[https://api.mongodb.org/c/current/] +MongoDB 前面已经介绍过。这是其官方提供的 API。 + 代码示例 #include @@ -1667,7 +1629,6 @@ Docs:[http://pocoproject.org/docs/package-MongoDB.MongoDB.html] POCO 前面已经介绍过。它提供了 MongoDB 的封装类 - == 8.3 ODBC 相关 ==

unixODBC

@@ -1690,7 +1651,6 @@ Docs:[http://pocoproject.org/docs/package-ODBC.ODBC.html] POCO 前面已经介绍过。它提供了操作 ODBC 的封装类。 - == 8.4 ORM(Object-Relational Mapping) ==

ODB

@@ -1705,9 +1665,9 @@ Wikipedia:[https://en.wikipedia.org/wiki/ODB_%28C%2B%2B%29 英文] 代码示例——声明一个可持久化的类 -// 通过预处理语句“#pragma”来进行某些定制 +// 通过预处理语句“#pragma”来进行某些定制 -#pragma db object table("people") +#pragma db object table("people") class person { public: @@ -1716,14 +1676,14 @@ public: private: friend class odb::access; person(); - - #pragma db id auto + + #pragma db id auto unsigned long id_; - + string first_; string last_; - - #pragma type("INT UNSIGNED") + + #pragma type("INT UNSIGNED") unsigned short age_; }; @@ -1740,19 +1700,17 @@ for(result::iterator i(r.begin()); i!=r.end(); ++i) { cout << "Hello, " << i->first() << endl; } - + trans.commit(); - ---- - = 9 Web 相关 = == 9.1 HTTP Server == -

Apache Server

+

Apache HTTP Server

Home:[https://httpd.apache.org/] @@ -1780,7 +1738,6 @@ Docs:[http://dlib.net/network.html#server_http] Dlib 前面已经介绍过。它提供了一个简单的 HTTP Server 的类(server_http)。 - == 9.2 HTTP Client ==

cURL & libcurl

@@ -1793,17 +1750,17 @@ libcurl 前面已经介绍过。它提供了【完整的】HTTP 协议支持。 #include #include - + int main() { curl_global_init(CURL_GLOBAL_ALL); - + CURL* curl = curl_easy_init(); if(curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://post.example.com/foo.cgi"); curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "name=daniel&project=curl"); - + CURLcode res = curl_easy_perform(curl); if(res != CURLE_OK) // Check for errors { @@ -1824,7 +1781,6 @@ Docs:[http://pocoproject.org/docs/package-Net.HTTPClient.html] POCO 前面已经介绍过。它提供了 HTTP Client 的封装类。 - == 9.3 浏览器引擎 ==

WebKit

@@ -1843,7 +1799,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Gecko_(software) 英文]、[https://z 它是 Firefox 的渲染引擎,基于 C++ 开发,由 Mozilla 社区维护。 - == 9.4 浏览器整合 ==

CEF(Chromium Embedded Framework)

@@ -1857,11 +1812,17 @@ Wikipedia:[https://en.wikipedia.org/wiki/Chromium_Embedded_Framework 英文] 以下是其它开源项目针对 CEF 的扩展,提供了其它编程语言的绑定。 * dotNet - [https://github.com/chillitom/CefSharp] + * dotNet (CEF1) - [https://bitbucket.org/fddima/cefglue] + * dotNet/Mono (CEF3) - [https://bitbucket.org/xilium/xilium.cefglue] + * dotNet (CEF3) - [https://bitbucket.org/chromiumfx/chromiumfx] + * Java - [https://bitbucket.org/chromiumembedded/java-cef] + * Go - [https://github.com/CzarekTomczak/cef2go] + * Delphi (CEF3) - [https://github.com/hgourvest/dcef3]

PhantomJS

@@ -1874,10 +1835,8 @@ Wikipedia:[https://en.wikipedia.org/wiki/PhantomJS 英文] 它本身没有提供 GUI 界面。但是提供了 JavaScript 的 API,让你可以操纵 WebKit 引擎。可以利用它进行 Web 界面的单元测试。 - ---- - = 10 信息安全 = == 10.1 密码学 == @@ -1934,11 +1893,9 @@ Docs:[http://pocoproject.org/docs/Poco.Crypto.html] POCO 前面已经介绍过。它提供了常见的加密算法和哈希算法。 - ---- - -= 11 文件格式 = += 11 处理文件格式 = == 11.1 结构化数据格式 == @@ -2004,6 +1961,8 @@ Home:[https://github.com/miloyip/rapidjson] Home:[https://github.com/open-source-parsers/jsoncpp] +如其名,这是个 C++ 的 JSON 封装库。 + === 11.1.3 YAML === [https://en.wikipedia.org/wiki/YAML YAML] 是一种类似于 json 的结构化数据格式。它在确保可读性的基础上,提供了超越 json 的灵活性和扩展性。 @@ -2020,8 +1979,7 @@ Home:[http://pyyaml.org/wiki/LibYAML] C 语言实现的 YAML 解析器。 - -== 11.2 压缩文件 / 打包文件 == +== 11.2 压缩文件 & 打包文件 == === 11.2.1 综合性的库 === @@ -2041,7 +1999,7 @@ Home:[http://www.7-zip.org/sdk.html] 支持的格式:7z、LZMA、LZMA2、XZ -=== 11.2.2 处理 zip === +=== 11.2.2 zip === [https://en.wikipedia.org/wiki/Zip_%28file_format%29 格式说明] @@ -2051,7 +2009,9 @@ Home:[http://www.nih.at/libzip/] Wikipedia:[https://en.wikipedia.org/wiki/Libzip 英文] -=== 11.2.3 处理 bzip2(bz2) === +用 C 语言开发的库,基于 zlib 库。 + +=== 11.2.3 bzip2(bz2) === [https://en.wikipedia.org/wiki/Bzip2 格式说明] @@ -2061,7 +2021,7 @@ Home:[http://bzip.org/] 这是 bzip2 官方提供的库,C 语言实现。 -=== 11.2.4 处理 gzip(gz) === +=== 11.2.4 gzip(gz) ===

zlib

@@ -2069,15 +2029,17 @@ Home:[http://zlib.net/] Wikipedia:[https://en.wikipedia.org/wiki/Zlib 英文]、[https://zh.wikipedia.org/wiki/Zlib 中文] -C 语言实现,诞生于1995年,被大量的开源项目使用。 +C 语言实现,诞生于1995年,被大量的开源项目使用(OpenSSL、OpenSSH、Apache、PostgreSQL、Git、libpng......)。 -=== 11.2.5 处理 tar === +=== 11.2.5 tar ===

libtar

Home:[http://www.feep.net/libtar/] -=== 11.2.6 处理 rar === +基于 C 语言开发,可以对 tar 格式添加内容或读取内容。 + +=== 11.2.6 rar ===

unrarlib

@@ -2085,7 +2047,6 @@ Home:[http://www.unrarlib.org/] 该项目的开发已经停止。只支持对 RAR2 格式的解压缩。 - == 11.3 标记语言 == === 11.3.1 XML === @@ -2130,8 +2091,7 @@ Home:[http://libxmlplusplus.sourceforge.net/] Home:[http://htmlcxx.sourceforge.net/] -支持 HTML 和 CSS 的解析。 - +如其名,是基于 C++ 开发的。支持 HTML 和 CSS 的解析。 == 11.4 PDF == @@ -2180,7 +2140,6 @@ HPDF_SaveToFile(doc, "test.pdf"); HPDF_Free(doc); - == 11.5 MS Office 文档 ==

wvWare

@@ -2191,7 +2150,6 @@ Home:[http://wvware.sourceforge.net/] AbiWord 和 KWord 用到它。 - == 11.6 RTF ==

LibRTF

@@ -2200,7 +2158,6 @@ Home:[http://sourceforge.net/projects/librtf/] C 语言实现的库,可以解析 RTF 文件格式。 - == 11.7 CHM ==

CHMLIB

@@ -2217,10 +2174,8 @@ Home:[http://www.mare.ee/indrek/libchmxx/] 它就是基于 CHMLIB 的 C++ 封装库。 - ---- - = 12 图像 = == 12.1 图像处理 == @@ -2241,7 +2196,6 @@ Docs:[http://dlib.net/imaging.html] Dlib 前面已经介绍过。它提供了常见的图像处理功能(旋转、剪切、拉伸、过滤)。 - == 12.2 图像格式转换 ==

ImageMagick

@@ -2250,7 +2204,6 @@ ImageMagick 前面已经介绍过。它支持非常多的图片格式([http:// 在支持的格式中,它可以实现其中几十种格式的相互转换。 - == 12.3 图像渲染 ==

Cairo

@@ -2263,7 +2216,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Cairo_%28graphics%29 英文]、[https 基于 C 语言开发,提供多种语言绑定(C++、Java、C#、Python、Ruby、Perl、Scheme、Smalltalk)。 -

Cairo

+

cairomm

Home:[http://cairographics.org/cairomm/] @@ -2271,7 +2224,6 @@ Home:[http://cairographics.org/cairomm/] ---- - = 13 多媒体 = == 13.1 多媒体框架 == @@ -2304,7 +2256,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Libav 英文] 它是2011年从 FFmpeg 派生出来的。基于 C 语言开发,支持多种操作系统。 - == 13.2 视频库 ==

libavcodec

@@ -2315,7 +2266,6 @@ Home:[http://ffmpeg.org/] 由于 Libav 从 FFmpeg 分裂出来,Libav 下也带有一个同名的库。 - == 13.3 音频库 ==

PortMedia & PortAudio

@@ -2334,11 +2284,8 @@ Wikipedia:[https://en.wikipedia.org/wiki/OpenAL 英文]、[https://zh.wikipedi C 语言开发的 3D 音效库,跨平台。最初由 Loki Software 开发。Loki 倒闭以后,这个项目由开源社区继续维护。 - - ---- - = 14 游戏开发 = == 14.1 综合性的游戏引擎 == @@ -2354,9 +2301,13 @@ Wikipedia:[https://en.wikipedia.org/wiki/Id_Tech 英文] 原先基于 C 和 汇编开发,从 id Tech 4 开始改用 C++ 开发。 * id Tech 1——俗称:Doom 引擎 + * id Tech 2(Quake)——俗称:Quake 引擎 + * id Tech 2(Quake II)——俗称:Quake II 引擎 + * id Tech 3——俗称:Quake III 引擎 + * id Tech 4——俗称:Doom 3 引擎

Crystal Space

@@ -2383,7 +2334,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Panda3D 英文] 以 C++ 编写,用 Python 脚本扩展。虽然它的名字有“3D”,但它不仅仅是 3D 引擎,还包括了其它功能(碰撞检测、音效、关卡编辑器...)。 - == 14.2 3D 渲染引擎 ==

OGRE

@@ -2404,7 +2354,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Mesa_%28computer_graphics%29 英文] 使用 C 语言开发,它是针对 OpenGL 规范的【纯软件】实现(大部分 OpenGL 的实现都用到了显卡硬件)。 - == 14.3 物理引擎 ==

Bullet

@@ -2437,10 +2386,10 @@ Home:[http://www.newtondynamics.com/] Wikipedia:[https://en.wikipedia.org/wiki/Newton_Game_Dynamics 英文] +基于 C++ 开发。 ---- - = 15 数值运算 & 科学计算 = == 15.1 综合性的库 == @@ -2457,13 +2406,12 @@ Wikipedia:[https://en.wikipedia.org/wiki/GNU_Scientific_Library 英文] #include #include - + double x = 5.0; double y = gsl_sf_bessel_J0(x); printf("J0(%g) = %.18e\n", x, y); - == 15.2 有理数 ==

Boost.Rational

@@ -2472,7 +2420,6 @@ Docs:[http://boost.org/libs/rational] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“有理数”的功能。 - == 15.3 高精度数值运算 ==

GMP(GNU Multiple Precision)

@@ -2496,7 +2443,7 @@ mpz_init(result); mpz_mul(result, x, y); gmp_printf("%Zd\n", result); - + /* free used memory */ mpz_clear(x); mpz_clear(y); @@ -2509,7 +2456,6 @@ Docs:[http://boost.org/libs/multiprecision] Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了高精度数值运算。它还提供了针对 GMP 的数据类型的封装。 - == 15.4 矩阵 ==

Boost.uBLAS.Matrix

@@ -2539,7 +2485,6 @@ Docs:[http://dlib.net/linear_algebra.html#matrix] Dlib 前面已经介绍过。它提供了一个矩阵类。 - == 15.5 线性代数 ==

Boost.uBLAS

@@ -2554,7 +2499,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了 BLA #include #include #include - + using namespace boost::numeric::ublas; vector v(2); v(0) = 1; v(1) = 2; @@ -2607,12 +2552,10 @@ cout << "Least squares solution:" << endl << solve(m,v) << endl; Docs:[http://dlib.net/linear_algebra.html] -Dlib 前面已经介绍过。 - +Dlib 前面已经介绍过。它提供了线性代数相关的封装类。 ---- - = 16 跨语言编程 = == 16.1 整合多种语言的库 == @@ -2627,7 +2570,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] 整合之后,你的 C/C++ 程序就可以享受到其它这些语言的特性啦,非常爽! - == 16.2 整合单一语言的库 == === 16.2.1 整合 Python 语言 === @@ -2643,7 +2585,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了 C++ // 这是一个标准的 C 函数 const char* greet() { - return "Hello, world"; + return "Hello, world"; } // 使用如下代码对上述函数进行包装 @@ -2659,12 +2601,8 @@ BOOST_PYTHON_MODULE(hello_ext) // print(hello_ext.greet()) - ---- - - - = 17 (其它) = 一些不方便归类的,暂时放到这里。 @@ -2676,3 +2614,6 @@ BOOST_PYTHON_MODULE(hello_ext) Docs:[http://boost.org/libs/spirit] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“基于 EBNF 的解析器框架”。 + +---- + From cd4c50f92bb34a8f21ec7e7ede7d28f65c99203b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 30 Jun 2015 22:00:55 +0800 Subject: [PATCH 002/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20OpenCV=E3=80=81PBR?= =?UTF-8?q?T?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 8fd3597..c3ff49d 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2222,6 +2222,24 @@ Home:[http://cairographics.org/cairomm/] 这是针对 Cairo 的 C++ 封装库。 +

PBRT(Physically Based Rendering Toolkit)

+ +Home:[http://pbrt.org/] + +基于光线追踪的物理渲染系统,采用 C++ 开发。 + +== 12.4 计算机视觉 == + +

OpenCV

+ +Home:[http://opencv.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/OpenCV 英文]、[https://zh.wikipedia.org/wiki/OpenCV 中文] + +它是一个跨平台的计算机视觉库,由 Intel 发起并参与开发。开发语言是 C 和 C++。 + +提供其它编程语言(Python、Java、MATLAB/OCTAVE ...)的 API 绑定。 + ---- = 13 多媒体 = From 0bbcf77efdbcfc6904c9bc36c47eb00e5ea88488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 30 Jun 2015 22:19:39 +0800 Subject: [PATCH 003/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Oniguruma?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index c3ff49d..81b2b3b 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -329,6 +329,16 @@ string human_readable_card_number(const string& s) } +

Oniguruma(鬼车)

+ +Home:[http://www.geocities.jp/kosako3/oniguruma/] + +Wikipedia:[https://en.wikipedia.org/wiki/Oniguruma 英文] + +来自日本的正则式库,基于 C 语言。据说性能很高。 + +它被用在 Ruby、TextMate、Sublime Text、SubEthaEdit 等软件上。 +

Qt.QRegExp

Docs:[http://doc.qt.io/qt-4.8/qregexp.html] From 0929d2cd7a8a2b94ed151e4b5106bc9269ee7dea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 30 Jun 2015 22:51:37 +0800 Subject: [PATCH 004/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20NaCl=E3=80=81libso?= =?UTF-8?q?dium?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 81b2b3b..8214a9a 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1897,6 +1897,26 @@ Wikipedia:[https://en.wikipedia.org/wiki/GnuTLS 英文] 采用 C 语言开发,名气也挺大。如其名,主要提供 TLS/SSL 的相关功能。 +

NaCl

+ +Home:[http://nacl.cr.yp.to/] + +Wikipedia:[https://en.wikipedia.org/wiki/NaCl_%28software%29 英文] + +这个名称是“Networking and Cryptography library”的缩写。 + +它采用 C 语言开发,另有其它编程语言(Python、Ruby、PHP)的 API 绑定。 + +它的作者同时也是 [https://en.wikipedia.org/wiki/Qmail qmail] 和 [https://en.wikipedia.org/wiki/Curve25519 Curve25519] 的作者。 + +

libsodium

+ +Home:[https://github.com/jedisct1/libsodium] + +它派生自 NaCl,提供了跟 NaCl 兼容的 API。支持的操作系统平台更多。 + +shadowsocks 和 dnscrypt-proxy 用到它。 +

POCO::Crypto

Docs:[http://pocoproject.org/docs/Poco.Crypto.html] From 3a262e0e99b956fdb2955c0c3c044fcd1222a6dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 30 Jun 2015 23:12:38 +0800 Subject: [PATCH 005/116] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=87=A0=E5=A4=84?= =?UTF-8?q?=E7=AC=94=E8=AF=AF=EF=BC=8C=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= =?UTF-8?q?=E7=A9=BA=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 132 ++++++++++++++++------------------------------- 1 file changed, 44 insertions(+), 88 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index b244ab8..15e51bf 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -8,12 +8,10 @@ 本页面列出的各种 Python 库/模块,如果注明了官网的网址,说明这个库是第三方的;否则就是 Python 语言内置的标准库。 -如果你发现本页面的开源库有错漏之处,有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 - +如果你发现本页面的开源库有错漏之处,非常欢迎给俺提供反馈——有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 ---- - = 1 算法 = == 1.1 字符串 == @@ -48,7 +46,6 @@ print(chardet.detect(bytes)) cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现的,提供 Unicode 兼容性。 - == 1.2 编码 & 解码 == === 1.2.1 base64 === @@ -75,7 +72,6 @@ cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现 标准库,提供 BinHex 格式的编码和解码。 - == 1.3 数学类 ==

math

@@ -97,15 +93,12 @@ random.randint(0, 100) 这个标准库封装了跟有理数(分数)相关的运算 - ---- - = 2 跨语言编程 = Python 可以很容易地跟其它编程语言整合。整合之后,就可以在 Python 代码中使用其它编程语言的函数、模块、库,非常爽! - -== 2.1 整合 C / C++ 语言 == +== 2.1 整合 C & C++ ==

ctypes

@@ -162,7 +155,7 @@ Home:[http://ironpython.net/] Wikipedia:[https://en.wikipedia.org/wiki/IronPython 英文]、[https://zh.wikipedia.org/wiki/IronPython 中文] -通过 IronPython 可以让 Python 代码运行在 dotNET 平台上,并且可以调用其它的 dotNET 语言的代码(比如 C# F#) +通过 IronPython 可以让 Python 代码运行在 dotNET 平台上,并且可以调用其它的 dotNET 语言的代码(C#、F#、VB.Net ...) == 2.4 整合 Objective-C 语言 == @@ -172,21 +165,19 @@ Home:[http://pyobjc.sourceforge.net/] 这是用 Python 封装 Mac OS X 上的 Objective-C 库。 - ---- - = 3 操作系统相关 = -

os

+== 3.1 文件和目录操作 == -这是一个非常基本的标准库,提供了常见的操作系统相关操作。 +

os

-== 3.1 文件和目录操作 == +这是一个非常基本的标准库,提供了常见的操作系统相关功能,很多功能是针对文件系统。

shutil

-相对于 os 标准库,shutil 标准库提供了一些比较高级的文件和目录操作(目录递归复制、目录递归删除、目录压缩打包、等) +相对于 os 标准库,shutil 标准库提供了一些比较高级的文件和目录操作(目录递归复制、目录递归删除、目录压缩打包...) 代码示例——递归删除某个目录 @@ -196,19 +187,18 @@ shutil.rmtree(xxxx)

glob

-这个标准库用于查找文件(支持通配符) +这个标准库用于查找文件,【支持通配符】(* 和 ?) 代码示例——获取当前目录所有 txt 文件 import glob - for file in glob.glob("./*.txt") : print(file)

fnmatch

-这个标准库用于匹配文件名(支持通配符) +这个标准库用于匹配文件名(支持通配符,类似上面的 glob) 代码示例——列出当前目录所有 txt 文件 @@ -223,6 +213,8 @@ for file in os.listdir(".") : 使用这个标准库,可以安全地生成临时文件或临时目录。 + + == 3.2 本地进程间通信(IPC) ==

subprocess & multiprocessing

@@ -233,7 +225,7 @@ for file in os.listdir(".") :

signal

-用于进程信号处理的标准库。 +用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。

mmap

@@ -298,15 +290,11 @@ Home:[https://pypi.python.org/pypi/setuptools] 这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) - ---- - = 4 Web 开发 = -如今 Web 开发很火,俺把 Web 相关的单独分一类。 - -== 4.1 HTTP 协议 == +== 4.1 HTTP Client ==

httplib & httplib2 & http.request & urllib.parse

@@ -322,8 +310,7 @@ page = handle.read() handle.close() - -== 4.2 Web Server == +== 4.2 HTTP Server ==

SimpleHTTPServer & http.server

@@ -336,18 +323,16 @@ Python2 的模块名叫 SimpleHTTPServer;到 Python3 模块名改为 http.serv import SocketServer import SimpleHTTPServer -PORT = 8000 +PORT = 8080 Handler = SimpleHTTPServer.SimpleHTTPRequestHandler httpd = SocketServer.TCPServer(("", PORT), Handler) print("serving at port %d" % PORT) httpd.serve_forever() - == 4.3 Web 开发框架 == (Python 的 Web 框架数不胜数,俺只挑选几个代表性的) -

Django

Home:[https://www.djangoproject.com/] @@ -368,7 +353,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wiki 又一个重型的 Web 开发框架,名气仅次于 Django。 - == 4.4 Web前端 & JS整合 ==

Pyjamas & pyjs

@@ -428,10 +412,8 @@ Home:[https://github.com/jmalonzo/pywebkitgtk] PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 - ---- - = 5 网络 = == 5.1 标准协议 == @@ -537,7 +519,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] (在这个方面,它有点类似于 Google 的 Protocol Buffers) - == 5.3 网络开发框架 ==

Twisted

@@ -566,10 +547,8 @@ reactor.listenTCP(12345, EchoFactory()) reactor.run() - ---- - = 6 数据库 = 为了便于数据库开发,Python 社区制定了数据库的 API 规范([https://www.python.org/dev/peps/pep-0249/ PEP 249])。 @@ -589,6 +568,7 @@ pyODBC 封装了 ODBC API,通过它可以访问各种数据库(只要有 ODB 代码示例——查询某个 ODBC 数据源的某个表 import pyodbc + conn = pyodbc.connect("DSN=xxx;PWD=password") cursor = conn.cursor() cursor.execute("SELECT field1 FROM table1") @@ -613,18 +593,17 @@ Home:[http://ceodbc.sourceforge.net/]

Jython

-Jython 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Jdbc JDBC] 操作数据库。 +Jython 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/Jdbc JDBC] 操作数据库。 === 6.1.3 ADO & ADO.NET ===

PyWin32

-PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/ActiveX_Data_Objects ADO] 操作数据库。 +PyWin32 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/ActiveX_Data_Objects ADO] 操作数据库。

IronPython

-IronPython 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/ADO.NET ADO.NET] 操作数据库。 - +IronPython 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/ADO.NET ADO.NET] 操作数据库。 == 6.2 特定数据库 == @@ -639,6 +618,7 @@ Home:[http://mysql-python.sourceforge.net/] 代码示例——查询某个 MySQL 数据库的某个表 import MySQLdb + conn = MySQLdb.connect(db="test", passwd="password") cursor = conn.cursor() cursor.execute("SELECT field1 FROM table1") @@ -661,7 +641,7 @@ Home:[http://initd.org/psycopg/] 操作 PostgreSQL 的第三方库。 -

psycopg

+

PyGreSQL

Home:[http://www.pygresql.org/] @@ -691,7 +671,6 @@ Home:[https://pypi.python.org/pypi/ibm_db] 操作 DB2 的第三方库。 - === 6.2.6 SQLite ===

sqlite3

@@ -703,7 +682,7 @@ sqlite3 从 Python 2.5 版本开始加入到标准库中。通过它,你可以 代码示例——创建一个内存数据库,建表并插入记录 import sqlite3 -conn = sqlite3.connect(":memory:") +conn = sqlite3.connect(":memory:") # ":memory:" 表示这是一个内存数据库 cursor = conn.cursor() cursor.execute("CREATE TABLE person (name text, age int)") cursor.execute("INSERT INTO stocks VALUES ('TOM',20)") @@ -752,19 +731,19 @@ class Movie(Base) : def __repr__(self) : return "Movie(%r, %r, %r)" % (self.title, self.year, self.director) - + class Director(Base) : __tablename__ = "directors" - + id = Column(Integer, primary_key=True) name = Column(String(50), nullable=False, unique=True) - + def __init__(self, name=None) : self.name = name - + def __repr__(self) : return "Director(%r)" % (self.name) - + Base.metadata.create_all(create_engine("dbms://user:pwd@host/dbname")) @@ -788,11 +767,9 @@ class Person(SQLObject) : Person.createTable() - ---- - -= 7 桌面 GUI 开发 = += 7 GUI 开发 = == 7.1 GUI 框架 == @@ -800,7 +777,7 @@ Person.createTable() [https://en.wikipedia.org/wiki/Tk_(framework) Tk] 是一个跨平台的界面组件库。 -

Tkinter / tkinter

+

Tkinter & tkinter

这是 Python 内置的标准库,封装了 Tcl/Tk 界面库。 @@ -820,7 +797,6 @@ if __name__ == "__main__" : === 7.1.2 基于 wxWidgets === [https://en.wikipedia.org/wiki/WxWidgets wxWidgets] 是 C++ 开发的跨平台框架(不仅包括 GUI,还有其它功能)。 -

wxPython

Home:[http://www.wxpython.org/] @@ -859,7 +835,6 @@ Home:[http://pythoncard.sourceforge.net/] === 7.1.3 基于 GTK+ === [https://en.wikipedia.org/wiki/GTK%2B GTK+] 全称是(GIMP Toolkit),由 C 开发的跨平台界面组件库。 -

PyGTK

Home:[http://www.pygtk.org/] @@ -915,7 +890,7 @@ if __name__ == "__main__" : Home:[http://www.riverbankcomputing.com/software/pyqt/] -Wikipedia:[https://en.wikipedia.org/wiki/PyQt]、[https://zh.wikipedia.org/wiki/PyQt 中文] +Wikipedia:[https://en.wikipedia.org/wiki/PyQt 英文]、[https://zh.wikipedia.org/wiki/PyQt 中文] 这是 Python 对 Qt 的封装。 @@ -943,7 +918,6 @@ Home:[http://www.pyside.org/] === 7.1.5 基于 FLTK === [https://en.wikipedia.org/wiki/FLTK FLTK] 全称是(Fast Light Tool Kit),由 C++ 开发的跨平台、轻量级界面组件库。 -

PyFLTK

Home:[http://pyfltk.sourceforge.net/] @@ -994,7 +968,7 @@ Home:[http://ocemp.sourceforge.net/gui.html] 基于 PyGame 的一个跨平台 GUI 库(PyGame 下面会提到)。 -== 7.2 图表/报表 == +== 7.2 图表 & 报表 ==

matplotlib

@@ -1030,13 +1004,11 @@ Home:[http://code.enthought.com/chaco/] 这是一个商业公司维护的库,主要提供2维图表。效果图在“[http://docs.enthought.com/chaco/user_manual/annotated_examples.html 这里]”。 - ---- - = 8 信息安全 = -== 8.1 密码学 == +== 8.1 密码学 ==

hashlib

@@ -1064,10 +1036,8 @@ Home:[http://pyopenssl.sourceforge.net/] [https://en.wikipedia.org/wiki/OpenSSL OpenSSL] 在加密领域可是大名鼎鼎。这个库使用 Python 对 OpenSSL 进行很薄的封装。 - ---- - = 9 处理文件格式 = == 9.1 结构化数据格式 == @@ -1075,7 +1045,6 @@ Home:[http://pyopenssl.sourceforge.net/] === 9.1.1 CSV === [https://en.wikipedia.org/wiki/Comma-separated_values CSV] 是一种历史悠久的结构化数据存储格式。其效果类似于一张数据库二维表。 -

csv

标准库,提供 CSV 格式文件的读写。 @@ -1083,7 +1052,6 @@ Home:[http://pyopenssl.sourceforge.net/] === 9.1.2 JSON === JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。 -

json

标准库,提供 JSON 格式的编码和解码。 @@ -1094,27 +1062,25 @@ import json json.dumps(["foo", {"bar": ("baz", None, 1.0, 2)}]) # JSON 编码 -# 得到如下字符串 +# 得到如下【字符串】 # """["foo", {"bar": ["baz", null, 1.0, 2]}]""" json.loads("""["foo", {"bar":["baz", null, 1.0, 2]}]""") # JSON 解码 -# 得到如下对象 +# 得到如下【对象】 # [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] === 9.1.3 YAML === [https://en.wikipedia.org/wiki/YAML YAML] 是一种类似于 json 的结构化数据格式。它在确保可读性的基础上,提供了超越 json 的灵活性和扩展性。 -

PyYAML

Home:[http://pyyaml.org/] pyyaml 提供了 Python 对 YAML 的封装。 - -== 9.2 压缩文件 / 打包文件 == +== 9.2 压缩文件 & 打包文件 == === 9.2.1 zip === @@ -1166,7 +1132,6 @@ Home:[http://rarfile.berlios.de/] 处理 msi 格式的标准库,从 Python 2.5 版本开始提供。 - == 9.3 标记语言 == === 9.3.1 XML === @@ -1193,7 +1158,6 @@ Home:[http://lxml.de/] 以回调方式解析 HTML/XHTML 文件内容的标准库。 - == 9.4 图片 ==

Python Imaging Library(PIL)

@@ -1235,7 +1199,6 @@ with Image(filename="mona-lisa.png") as img : display(i) - == 9.5 PDF ==

pyfpdf

@@ -1257,13 +1220,13 @@ pdf.cell(40, 10, "Hello, World") pdf.output("test.pdf", "F") +代码示例——支持写入 HTML 语法(目前支持几种常见的 HTML tag) -# 支持写入 HTML 语法。目前支持几种常见的 HTML tag from pyfpdf import FPDF, HTMLMixin class MyFPDF(FPDF, HTMLMixin) : pass - + pdf = MyFPDF() pdf.add_page() pdf.write_html(html) @@ -1272,11 +1235,11 @@ pdf.output("test.pdf", "F")

pyPdf & PyPDF2

-Home:[http://pybrary.net/pyPdf/] & [http://knowah.github.com/PyPDF2/] +Home:[http://knowah.github.com/PyPDF2/] -pyPdf 目前已经不继续升级维护了。PyPDF2 是 pyPdf 的 fork 并继续增加新功能。 +pyPdf 目前已经不继续升级维护了。PyPDF2 是从 pyPdf 派生出来的,并继续增加新功能。 -除了可以提取文件属性,还可以切分/合并文档,加密/解密文档。 +它除了可以提取文件属性,还可以切分/合并文档,加密/解密文档。

PDFMiner

@@ -1284,7 +1247,6 @@ Home:[http://www.unixuser.org/~euske/python/pdfminer/] 它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 - == 9.6 MS Office 文档 == === 9.6.1 Word(doc、docx) === @@ -1317,7 +1279,6 @@ Home:[https://github.com/scanny/python-pptx] PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - == 9.7 RTF ==

PyRTF

@@ -1326,7 +1287,6 @@ Home:[http://pyrtf.sourceforge.net/] 它可以用来处理 RTF(富文本格式)文档。 - == 9.8 CHM ==

PyCHM

@@ -1335,10 +1295,8 @@ Home:[http://gnochm.sourceforge.net/pychm.html] 这是基于 [http://www.jedrea.com/chmlib/ chmlib] 的 Python 封装库。可以提取 CHM 文件的属性以及每个页面的内容。 - ---- - = 10 游戏开发 =

PyGame

@@ -1361,11 +1319,9 @@ Home:[http://www.python-ogre.org/] 封装 [https://en.wikipedia.org/wiki/OGRE OGRE](3D 渲染引擎)的 Python 第三方库。 - ---- - -= 11 数值计算 / 科学计算 = += 11 数值计算 & 科学计算 =

NumPy

@@ -1397,16 +1353,15 @@ Home:[http://www.scipy.org/] Wikipedia:[https://en.wikipedia.org/wiki/SciPy 英文]、[https://zh.wikipedia.org/wiki/SciPy 中文] -SciPy 依赖 NumPy 提供的多维数组。相比 NumPy,SciPy 提供了更高层的数学运算模块(统计、线性代数、积分、常微分方程求解、傅立叶变换、信号处理、等),被广泛用于科研和工程领域。 +它依赖 NumPy 提供的多维数组。相比 NumPy,它提供了更高层的数学运算模块(统计、线性代数、积分、常微分方程求解、傅立叶变换、信号处理 ...)。 +它被广泛用于科研和工程领域。 ---- - = 12 其它 = 一些不方便归类的,暂时放到这里。 -

PyPy

Home:[http://www.pypy.org/] @@ -1416,3 +1371,4 @@ Wikipedia:[https://en.wikipedia.org/wiki/PyPy 英文]、[https://zh.wikipedia. 它是一个用 Python 写的 Python 解释器(有点绕口令)。 PyPy 支持 JIT(Just-in-time compilation)和沙箱技术,可做到【比 CPython 更快的运行速度】。 + From e844aeeb6e8a4c3d796c3d2e2c9a9aea32dd106e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 30 Jun 2015 23:15:45 +0800 Subject: [PATCH 006/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20SymPy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 15e51bf..dabead1 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1357,6 +1357,16 @@ Wikipedia:[https://en.wikipedia.org/wiki/SciPy 英文]、[https://zh.wikipedia 它被广泛用于科研和工程领域。 +

SymPy

+ +Home:[http://sympy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia.org/wiki/SymPy 中文] + +它是用来做符号计算的,其目标是成为一个全功能的“计算机代数系统”。 + +它支持的功能包括:符号计算、高精度计算、模式匹配、绘图、解方程、微积分、组合数学、离散数学、几何学、概率与统计 ...... + ---- = 12 其它 = From b66ede72f4886173abb9b465aa58556c138fc3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 1 Jul 2015 23:49:43 +0800 Subject: [PATCH 007/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Boost.GIL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 8214a9a..6208202 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2220,6 +2220,31 @@ ImageMagick 可说是最强大的开源图片处理工具集,采用 C 语言 它提供许多编程语言的 API,对于 C++ 是 [http://www.imagemagick.org/Magick++/ Magick++],对于 C 是 [http://imagemagick.org/script/magick-wand.php MagickWand] +

Boost.GIL(Generic Image Library)

+ +Docs:[http://boost.org/libs/gil] + +Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了图像处理功能。 + +代码示例——调整图像尺寸 + +#include +#include +#include +#include +#include + +using namespace boost::gil; + +rgb8_image_t img; +jpeg_read_image("input.jpg", img); + +// Scale the image to 100x100 pixels using bilinear resampling +rgb8_image_t square(100, 100); +resize_view(const_view(img), view(square), bilinear_sampler()); +jpeg_write_view("output.jpg", const_view(square)); + +

Dlib

Docs:[http://dlib.net/imaging.html] @@ -2663,5 +2688,3 @@ Docs:[http://boost.org/libs/spirit] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“基于 EBNF 的解析器框架”。 ----- - From 55f68295f0a6074e3ae1ae7460cd591457dde509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Thu, 2 Jul 2015 00:33:53 +0800 Subject: [PATCH 008/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20libevent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 6208202..d4e74c2 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1222,7 +1222,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] (在这个方面,它有点类似于 Google 的 Protocol Buffers) -== 7.3 网络开发框架 == +== 7.3 网络库、框架、中间件 ==

Boost.Asio

@@ -1321,6 +1321,60 @@ Docs:[http://dlib.net/network.html] Dlib 前面已经介绍过。它针对网络通讯,提供了比较高的抽象层。 +

libevent

+ +Home:[http://libevent.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Libevent 英文]、[https://zh.wikipedia.org/wiki/Libevent 中文] + +它提供了异步事件处理机制。在网络开发中,可以用它替代传统的“event loop”,有助于简化代码。 + +它被一些知名的开源项目使用(比如:[https://zh.wikipedia.org/wiki/Tor Tor]、[https://zh.wikipedia.org/wiki/Memcached memcached])。 + +代码示例——HTTP Server(本示例基于 C++ 11 标准) + +#include +#include +#include +#include + +int main() +{ + if(!event_init()) + { + std::cerr << "Failed to init libevent." << std::endl; + return -1; + } + char const SrvAddress[] = "127.0.0.1"; + std::uint16_t SrvPort = 5555; + std::unique_ptr Server(evhttp_start(SrvAddress, SrvPort), &evhttp_free); + if(!Server) + { + std::cerr << "Failed to init http server." << std::endl; + return -1; + } + + void (*OnReq)(evhttp_request* req, void*) = [] (evhttp_request* req, void*) + { + auto* OutBuf = evhttp_request_get_output_buffer(req); + if(!OutBuf) + { + return; + } + evbuffer_add_printf(OutBuf, "

Hello, World!

"); + evhttp_send_reply(req, HTTP_OK, "", OutBuf); + }; + + evhttp_set_gencb(Server.get(), OnReq, nullptr); + if(event_dispatch() == -1) + { + std::cerr << "Failed to run messahe loop." << std::endl; + return -1; + } + return 0; +} + + ---- = 8 数据库 = From f3b04a2b8613e71e634addaddce41ffb4192f67b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Thu, 2 Jul 2015 23:57:36 +0800 Subject: [PATCH 009/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20PyGObject?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index dabead1..3521711 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -841,7 +841,7 @@ Home:[http://www.pygtk.org/] Wikipedia:[https://en.wikipedia.org/wiki/PyGTK 英文] -这是 Python 对 GTK 的封装。 +它是 Python 对 GTK+2 的封装。 代码示例——用 PyGTK 写 Hello world @@ -882,6 +882,33 @@ if __name__ == "__main__" : hello.main() +

PyGObject(PyGI)

+ +Home:[https://live.gnome.org/PyGObject] + +它是 Python 对 GTK+3 的封装。PyGTK 的官网也推荐它。 + +代码示例——用 PyGObject 写 Hello world + +from gi.repository import Gtk + +class MyWindow(Gtk.Window): + def __init__(self): + Gtk.Window.__init__(self, title="Hello World") + + self.button = Gtk.Button(label="Click Here") + self.button.connect("clicked", self.on_button_clicked) + self.add(self.button) + + def on_button_clicked(self, widget): + print("Hello, world!") + +win = MyWindow() +win.connect("delete-event", Gtk.main_quit) +win.show_all() +Gtk.main() + + === 7.1.4 基于 Qt === [https://en.wikipedia.org/wiki/Qt_(toolkit) Qt] 是 C++ 开发的跨平台框架(不仅包括 GUI,还有其它功能)。 @@ -1372,6 +1399,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia = 12 其它 = 一些不方便归类的,暂时放到这里。 +

PyPy

Home:[http://www.pypy.org/] From 13217f56a92046ac5d11da9b9b683e82f1f33c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Fri, 3 Jul 2015 11:16:38 +0800 Subject: [PATCH 010/116] =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=A0=87=E5=87=86?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E7=9A=84=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index d4e74c2..ce26f07 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -106,19 +106,35 @@ Wikipedia:[https://en.wikipedia.org/wiki/Crypto%2B%2B 英文]

std

-STL 标准库提供了如下: +C++ 98 标准内置的 STL 提供了如下容器: -* 数组:vector(动态)、array(固定) +* 数组:vector(动态数组)、valarray(针对数值类型特化的 vector)、bitset(储存比特的【固定】数组) -* 链表:list(双向)、forward_list(单向) +* 链表:list(双向) * 队列:queue、deque(双端队列) * 栈:stack -* 映射:map(键值无重复)、multimap(键值可重复)、hash_map、hash_multimap +* 映射:map(键值无重复)、multimap(键值可重复) -* 集合:set(元素无重复)、multiset(元素可重复)、hash_set、hash_multiset +* 集合:set(元素无重复)、multiset(元素可重复) + +[https://en.wikipedia.org/wiki/C%2B%2B11 C++ 11 标准]新增了如下容器: + +* 数组:array(相比 vector,它的 size 是编译时【固定】的) + +* 链表:forward_list(相比 list,它是【单向】的) + +* 映射:unordered_map、unordered_multimap(相比 map 和 multimap,这俩采用 hash 实现) + +* 集合:unordered_set、unordered_multiset(相比 set 和 multiset,这俩采用 hash 实现) + +下面几个容器,C++ 标准【没有】包含,但包含在某些知名的 STL 第三方库中(比如 SGI 的 STL): + +* 映射:hash_map、hash_multimap(与 unordered_map、unordered_multimap 相同) + +* 集合:hash_set、hash_multiset(与 unordered_set、unordered_multiset 相同) === 2.1.2 Lockfree 的容器 === From bcc2e029e4efcbfd68c46d626c4b385b35c9aeff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Fri, 3 Jul 2015 23:56:19 +0800 Subject: [PATCH 011/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E2=80=9D=E7=9A=84=E5=88=86=E7=B1=BB=E5=B1=82=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 1677 ++++++++-------------------------------------- 1 file changed, 265 insertions(+), 1412 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 3521711..e22070a 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1,1412 +1,265 @@ -

Python 开源库及示例代码

- -= = - -= 说明 = - -本页面汇总俺收集的各种 Python 代码库,不定期更新。 - -本页面列出的各种 Python 库/模块,如果注明了官网的网址,说明这个库是第三方的;否则就是 Python 语言内置的标准库。 - -如果你发现本页面的开源库有错漏之处,非常欢迎给俺提供反馈——有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 - ----- - -= 1 算法 = - -== 1.1 字符串 == - -=== 1.1.1 正则表达式 === - -

re

- -正则表达式的标准库,提供基于正则的匹配和替换。 - -=== 1.1.2 字符集 === - -

chardet

- -Home:[https://github.com/erikrose/chardet] - -chardet 可以猜测任意一段文本的字符集编码。对于编码类型未知的文本,它会很有用。 - -chardet 既可以作为模块来使用,也可以作为命令行工具来使用。 - -代码示例 - -import chardet -print(chardet.detect(bytes)) - - -=== 1.1.3 (其它) === - -

StringIO & cStringIO

- -以读写文件的方式来操作字符串(有点类似于内存文件)。 - -cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现的,提供 Unicode 兼容性。 - -== 1.2 编码 & 解码 == - -=== 1.2.1 base64 === - -[https://en.wikipedia.org/wiki/Base64 Base64] 是一组编码算法的总称。用于把二进制数据编码为文本。 - -

base64

- -标准库,提供 Base16、Base32、Base64 格式的编码和解码。 - -=== 1.2.2 UUencode === - -[https://en.wikipedia.org/wiki/Uuencode UUencode] 出现于早期的 Unix 系统。用于把二进制编码为文本,以便通过邮件系统发送。 - -

uu

- -标准库,提供 UUencode 格式的编码和解码。 - -=== 1.2.3 BinHex === - -[https://en.wikipedia.org/wiki/BinHex BinHex] 起先用于 Mac OS 系统,类似于 UUencode。 - -

binhex

- -标准库,提供 BinHex 格式的编码和解码。 - -== 1.3 数学类 == - -

math

- -顾名思义,这个标准库封装了常用的数学函数(开方、指数、对数、三角函数......)。 - -

random

- -顾名思义,这个标准库是用来进行随机数生成滴。 - -代码示例——生成 0-100 的随机数 - -import random -random.seed() -random.randint(0, 100) - - -

fractions

- -这个标准库封装了跟有理数(分数)相关的运算 - ----- - -= 2 跨语言编程 = - -Python 可以很容易地跟其它编程语言整合。整合之后,就可以在 Python 代码中使用其它编程语言的函数、模块、库,非常爽! -== 2.1 整合 C & C++ == - -

ctypes

- -ctypes 在 Python 2.5 版本加入到标准库中。 - -通过它,你可以很方便地调用 C/C++ 动态库导出的函数,可以在 Python 中使用各种 C/C++ 的数据类型(比如指针)。 - -代码示例——调用 Linux/Unix 系统的标准 C 函数,获取当前时间 - -from ctypes import * -libc = CDLL("libc.so.6") -time = libc.time(None) - -# 调用 Windows 系统 API,弹出消息提示框 -from ctypes import c_int, WINFUNCTYPE, windll -from ctypes.wintypes import HWND, LPCSTR, UINT -prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT) -paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) -MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) -MessageBox(text="Hello, world", flags=2) - - -

SWIG(Simplified Wrapper and Interface Generator)

- -Home:[http://swig.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] - -这是一个很老牌的、有名气的工具,它可以把多种语言(Java、Python、C#、Ruby、PHP、Perl、Lua、Go、等)整合到 C/C++ 中。 - -

Cython

- -Home:[http://cython.org/] - -这个工具可以让你用 Python 的语法写扩展模块的代码,然后它帮你把 Python 代码编译为本地动态库(机器码)。 - -用它编译出来的扩展模块,其性能跟 C/C++ 编写的扩展模块相当。 - -== 2.2 整合 JVM 平台 == - -

Jython

- -Home:[http://www.jython.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/Jython 英文]、[https://zh.wikipedia.org/wiki/Jython 中文] - -通过 Jython 可以让 Python 代码运行在 JVM 上,并且可以调用其它的 JVM 语言的代码(比如 Java、Scale) - -== 2.3 整合 dotNet 平台 == - -

IronPython

- -Home:[http://ironpython.net/] - -Wikipedia:[https://en.wikipedia.org/wiki/IronPython 英文]、[https://zh.wikipedia.org/wiki/IronPython 中文] - -通过 IronPython 可以让 Python 代码运行在 dotNET 平台上,并且可以调用其它的 dotNET 语言的代码(C#、F#、VB.Net ...) - -== 2.4 整合 Objective-C 语言 == - -

PyObjC

- -Home:[http://pyobjc.sourceforge.net/] - -这是用 Python 封装 Mac OS X 上的 Objective-C 库。 - ----- - -= 3 操作系统相关 = - -== 3.1 文件和目录操作 == - -

os

- -这是一个非常基本的标准库,提供了常见的操作系统相关功能,很多功能是针对文件系统。 - -

shutil

- -相对于 os 标准库,shutil 标准库提供了一些比较高级的文件和目录操作(目录递归复制、目录递归删除、目录压缩打包...) - -代码示例——递归删除某个目录 - -import shutil -shutil.rmtree(xxxx) - - -

glob

- -这个标准库用于查找文件,【支持通配符】(* 和 ?) - -代码示例——获取当前目录所有 txt 文件 - -import glob -for file in glob.glob("./*.txt") : - print(file) - - -

fnmatch

- -这个标准库用于匹配文件名(支持通配符,类似上面的 glob) - -代码示例——列出当前目录所有 txt 文件 - -import os, fnmatch - -for file in os.listdir(".") : - if fnmatch.fnmatch(file, "*.txt") : - print(file) - - -

tempfile

- -使用这个标准库,可以安全地生成临时文件或临时目录。 - - - -== 3.2 本地进程间通信(IPC) == - -

subprocess & multiprocessing

- -用于进程管理的标准库,可以启动子进程,通过标准输入输出跟子进程交互。 - -其中 multiprocessing 是 2.6 版本加入到标准库的。 - -

signal

- -用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 - -

mmap

- -提供了内存映射文件的支持。 - -代码示例——利用 mmap 在父子进程间交换数据 - -import os -import mmap - -map = mmap.mmap(-1, 13) -map.write("Hello, world") - -pid = os.fork() -if pid == 0: # 子进程 - map.seek(0) - print(map.readline()) - map.close() - - -== 3.3 Windows 系统相关 == - -

PyWin32

- -Home:[http://python.net/crew/mhammond/win32/] - -这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 - -== 3.4 Linux & Unix 系统相关 == - -

syslog

- -通过这个标准库,可以很方便地跟 POSIX 的 syslog 服务进行交互。 - -== 3.5 程序打包 == - -

PyInstaller

- -Home:[http://www.pyinstaller.org/] - -PyInstaller 可以把你的 Python 代码制作成独立运行的程序(不依赖 Python 环境就可以运行)。 - -该工具支持多种操作系统,包括:Windows、Linux、Mac OS X、Solaris、AIX、等。 - -

py2exe

- -Home:[http://www.py2exe.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/Py2exe 英文] - -py2exe 的功能类似 PyInstaller,但只支持 Windows 平台。 - -

py2app

- -Home:[https://bitbucket.org/ronaldoussoren/py2app] - -它很类似于 [http://www.py2exe.org/ py2exe],差别在于 [http://www.py2exe.org/ py2exe] 支持 Windows 平台,而 [https://bitbucket.org/ronaldoussoren/py2app py2app] 支持 Mac OS X 平台。 - -

EasyInstall & Setuptools

- -Home:[https://pypi.python.org/pypi/setuptools] - -这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) - ----- - -= 4 Web 开发 = - -== 4.1 HTTP Client == - -

httplib & httplib2 & http.request & urllib.parse

- -这几个库可以进行各种 HTTP 客户端请求(GET、POST、等)。 - -Python2 的模块名是 httplib 和 httplib2;到 Python3,模块名改为 http.request 和 urllib.parse - -代码示例——读取指定 URL 的网页内容 - -import urllib -handle = urllib.urlopen("http://www.google.com") -page = handle.read() -handle.close() - - -== 4.2 HTTP Server == - -

SimpleHTTPServer & http.server

- -提供轻量级 HTTP Server 的标准库。 - -Python2 的模块名叫 SimpleHTTPServer;到 Python3 模块名改为 http.server - -代码示例——一个极简单的 HTTP 服务 - -import SocketServer -import SimpleHTTPServer - -PORT = 8080 -Handler = SimpleHTTPServer.SimpleHTTPRequestHandler -httpd = SocketServer.TCPServer(("", PORT), Handler) -print("serving at port %d" % PORT) -httpd.serve_forever() - - -== 4.3 Web 开发框架 == - -(Python 的 Web 框架数不胜数,俺只挑选几个代表性的) -

Django

- -Home:[https://www.djangoproject.com/] - -Wikipedia:[https://en.wikipedia.org/wiki/Django_(web_framework) 英文]、[https://zh.wikipedia.org/wiki/Django 中文] - -在 Python 社区,Django 是目前最有影响力的 Web 开发框架。该框架很重型,内置了 Web 服务端开发常用的组件(比如:ORM、用户管理)。 - -Django 应用范围很广,比如 Google 的 Web 开发平台 GAE 就支持它。 - -而且它完全支持前面提到的 Jython 运行环境,可以运行在任何 J2EE 服务器上。 - -

TurboGears

- -Home:[http://www.turbogears.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wikipedia.org/wiki/TurboGears 中文] - -又一个重型的 Web 开发框架,名气仅次于 Django。 - -== 4.4 Web前端 & JS整合 == - -

Pyjamas & pyjs

- -Home:[http://pyjs.org/] - -这是从 GWT(Google Web Toolkit)移植的第三方库。提供了 Python 到 JS 的编译,AJAX 框架等功能。 - -Pyjamas 甚至能用来开发桌面 GUI 应用。 - -

pyjaco

- -Home:[https://github.com/chrivers/pyjaco] - -这也是一个 Python 到 JavaScript 的编译工具。 - -== 4.5 浏览器整合 == - -

webbrowser

- -操纵当前系统的默认浏览器,访问指定 URL 的页面。 - -代码示例——用默认浏览器打开 Google 主页 - -import webbrowser -webbrowser.open("http://www.google.com") - - -

pyv8

- -Home:[https://pypi.python.org/pypi/PyV8] - -[https://developers.google.com/v8/ v8] 是 Google 开发的 JavaScript 解释引擎。这是对 v8 引擎的 Python 封装。 - -代码示例 - -import PyV8 - -ctxt1 = PyV8.JSContext() -ctxt1.enter() -ctxt1.eval("1+2") # 对 JS 表达式求值 - -class Global(PyV8.JSClass) : # 定义一个兼容 JS 的类 - def hello(self) : - print("Hello, world") - -ctxt2 = PyV8.JSContext(Global()) # 创建一个 JS 上下文,传入 Global 类的对象 -ctxt2.enter() -ctxt2.eval("hello()") # 调用 hello() 函数 - - -

PyWebKitGtk

- -Home:[https://github.com/jmalonzo/pywebkitgtk] - -[http://webkitgtk.org/ WebKitGtk] 是一个基于 WebKit 的 Web 渲染引擎。 - -PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 - ----- - -= 5 网络 = - -== 5.1 标准协议 == - -=== 5.1.1 链路层 & 网络层 === - -

Scapy

- -Home:[http://www.secdev.org/projects/scapy/] - -Wikipedia:[https://en.wikipedia.org/wiki/Scapy 英文] - -这是一个底层的网络库,可以在不同协议层次构造网络数据包(包括链路层、网络层、传输层),还支持 Sniffer 抓包。 - -搞网络安全的网友应该会喜欢这个库。 - -代码示例 - -# 传统的 ping 扫描(网络层) -ans,unans = sr(IP(dst="192.168.1.1-254")/ICMP()) - -# 局域网内的 ARP 扫描(链路层) -ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2) - - -=== 5.1.2 传输层 === - -

socket

- -Python 标准库很早就提供了对 socket 编程的支持。 - -这个标准库是对伯克利套接字进行简单的封装,其 API 基本上跟 BSD SOCKET 一一对应。 - -

asyncore

- -这个标准库提供了异步 SOCKET 的支持。 - -

asynchat

- -这个标准库基于上述的 asyncore,提供更高层的 API,简化异步通讯编程。 - -=== 5.1.3 应用层 === - -

ftplib

- -封装 FTP 协议(文件传输)的标准库 - -

smtplib

- -封装 SMTP 协议(邮件发送)的标准库 - -

imaplib

- -封装 IMAP 协议(邮件接收)的标准库 - -

poplib

- -封装 POP3 协议(邮件接收)的标准库 - -

PycURL

- -Home:[http://pycurl.sourceforge.net/] - -[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。pycurl 提供了 Python 的封装。 - -关于 cURL,俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 - -

jabber.py

- -Home:[http://jabberpy.sourceforge.net/] - -Jabber(又称 XMPP)是IM(即时通信)协议的标准。这是用 Python 封装的第三方库。 - -

irclib

- -Home:[https://bitbucket.org/jaraco/irc] - -IRC 是 Internet Relay Chat 的缩写。这是用 Python 封装的第三方库。 - -== 5.2 自定义协议 == - -

Protocol Buffers

- -Home:[https://developers.google.com/protocol-buffers/] - -Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] - -这是 Google 开发的一个跨语言的库,用于网络传输业务数据时的“编码/解码”。 - -其优点是:跨多种语言、高性能、向前兼容、向后兼容。俺前几年写过一篇博文推荐 protobuf(在“[http://program-think.blogspot.com/2009/05/opensource-review-protocol-buffers.html 这里]”)。 - -作为 Protocol Buffers 的发明者,Google 默认实现了三种编程语言(C++、Java、Python)对它的支持。 - -

Apache Thrift

- -Home:[https://thrift.apache.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] - -来自于 Apache 社区,提供了一种跨语言的通讯机制。 - -程序员通过 Thrift 的“接口定义语言”定义通讯协议格式,然后 Thrift 根据协议格式自动帮你生成服务端和客户端代码。 - -(在这个方面,它有点类似于 Google 的 Protocol Buffers) - -== 5.3 网络开发框架 == - -

Twisted

- -Home:[http://twistedmatrix.com/] - -Wikipedia:[https://en.wikipedia.org/wiki/Twisted_%28software%29 英文] - -这是一个基于 Python 网络通讯开发框架,诞生于2002年,名气很大。 - -它的某些设计类似于 C++ 的 [https://en.wikipedia.org/wiki/Adaptive_Communication_Environment ACE] 框架。除了能用来进行传输层(TCP UDP)的开发,还提供了若干应用层协议(HTTP、XMPP、SSH、IRC、等)的支持。 - -代码示例——实现一个简单的 Echo 服务,监听在 12345 端口 - -from twisted.internet import protocol, reactor - -class Echo(protocol.Protocol) : - def dataReceived(self, data) : - self.transport.write(data) - -class EchoFactory(protocol.Factory) : - def buildProtocol(self, addr) : - return Echo() - -reactor.listenTCP(12345, EchoFactory()) -reactor.run() - - ----- - -= 6 数据库 = - -为了便于数据库开发,Python 社区制定了数据库的 API 规范([https://www.python.org/dev/peps/pep-0249/ PEP 249])。 - -只要是涉及到数据库操作,标准库和大部分第三方库都会遵循该规范(请看如下几个模块的示例代码)。 - -== 6.1 数据库中间件 == - -=== 6.1.1 ODBC === - -

pyODBC

- -Home:[https://github.com/mkleehammer/pyodbc] - -pyODBC 封装了 ODBC API,通过它可以访问各种数据库(只要有 ODBC 驱动即可)。 - -代码示例——查询某个 ODBC 数据源的某个表 - -import pyodbc - -conn = pyodbc.connect("DSN=xxx;PWD=password") -cursor = conn.cursor() -cursor.execute("SELECT field1 FROM table1") - -while True : - row = cursor.fetchone() - if not row : - break - print(row) - -cursor.close() -conn.close() - - -

ceODBC

- -Home:[http://ceodbc.sourceforge.net/] - -又一个封装 ODBC API 的第三方库 - -=== 6.1.2 JDBC === - -

Jython

- -Jython 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/Jdbc JDBC] 操作数据库。 - -=== 6.1.3 ADO & ADO.NET === - -

PyWin32

- -PyWin32 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/ActiveX_Data_Objects ADO] 操作数据库。 - -

IronPython

- -IronPython 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/ADO.NET ADO.NET] 操作数据库。 - -== 6.2 特定数据库 == - -=== 6.2.1 MySQL === - -

MySQL for Python

- -Home:[http://mysql-python.sourceforge.net/] - -操作 MySQL 的第三方库。 - -代码示例——查询某个 MySQL 数据库的某个表 - -import MySQLdb - -conn = MySQLdb.connect(db="test", passwd="password") -cursor = conn.cursor() -cursor.execute("SELECT field1 FROM table1") - -while True : - row = cursor.fetchone() - if not row : - break - print(row) - -cursor.close() -conn.close() - - -=== 6.2.2 PostgreSQL === - -

psycopg

- -Home:[http://initd.org/psycopg/] - -操作 PostgreSQL 的第三方库。 - -

PyGreSQL

- -Home:[http://www.pygresql.org/] - -操作 PostgreSQL 的第三方库。 - -=== 6.2.3 Oracle === - -

cx_Oracle

- -Home:[http://cx-oracle.sourceforge.net/] - -操作 Oracle 的第三方库。 - -=== 6.2.4 MS SQL Server === - -

pymssql

- -Home:[http://pymssql.org/] - -操作微软 SQL Server 的第三方库。 - -=== 6.2.5 IBM DB2 === - -

ibm-db

- -Home:[https://pypi.python.org/pypi/ibm_db] - -操作 DB2 的第三方库。 - -=== 6.2.6 SQLite === - -

sqlite3

- -sqlite3 从 Python 2.5 版本开始加入到标准库中。通过它,你可以很方便地操作 SQLite 数据库。 - -[https://en.wikipedia.org/wiki/SQLite SQLite] 是一个很优秀的轻量级数据库,俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/04/how-to-use-sqlite.html 这里]”)。 - -代码示例——创建一个内存数据库,建表并插入记录 - -import sqlite3 -conn = sqlite3.connect(":memory:") # ":memory:" 表示这是一个内存数据库 -cursor = conn.cursor() -cursor.execute("CREATE TABLE person (name text, age int)") -cursor.execute("INSERT INTO stocks VALUES ('TOM',20)") -conn.commit() -conn.close() - - -=== 6.2.7 Berkeley DB === - -

PyBSDDB

- -Home:[http://www.jcea.es/programacion/pybsddb.htm] - -操作 Berkeley DB 的第三方库。 - -== 6.3 ORM(Object-Relational Mapping) == - -

SQLAlchemy

- -Home:[http://www.sqlalchemy.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/SQLAlchemy 英文]、[https://zh.wikipedia.org/wiki/SQLAlchemy 中文] - -SQLAlchemy 支持的数据库有:MySQL、PostgreSQL、Sqlite、Oracle、MS SQL Server、Firebird、Sybase SQL Server、Informix、等。 - -代码示例——通过对象的方式创建两张依赖关系的表 - -from sqlalchemy import * -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy.orm import relation, sessionmaker - -Base = declarative_base() - -class Movie(Base) : - __tablename__ = "movies" - - id = Column(Integer, primary_key=True) - title = Column(String(255), nullable=False) - year = Column(Integer) - directed_by = Column(Integer, ForeignKey("directors.id")) - director = relation("Director", backref="movies", lazy=False) - - def __init__(self, title=None, year=None) : - self.title = title - self.year = year - - def __repr__(self) : - return "Movie(%r, %r, %r)" % (self.title, self.year, self.director) - -class Director(Base) : - __tablename__ = "directors" - - id = Column(Integer, primary_key=True) - name = Column(String(50), nullable=False, unique=True) - - def __init__(self, name=None) : - self.name = name - - def __repr__(self) : - return "Director(%r)" % (self.name) - -Base.metadata.create_all(create_engine("dbms://user:pwd@host/dbname")) - - -

SQLObject

- -Home:[http://sqlobject.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/SQLObject 英文] - -SQLObject 支持的数据库有:MySQL、PostgreSQL、Sqlite、MS SQL Server、Firebird、Sybase SQL Server、SAP DB、等。 - -代码示例——通过对象的方式创建表 - -from sqlobject import * -sqlhub.processConnection = connectionForURI("sqlite:/:memory:") - -class Person(SQLObject) : - first_name = StringCol() - last_name = StringCol() - -Person.createTable() - - ----- - -= 7 GUI 开发 = - -== 7.1 GUI 框架 == - -=== 7.1.1 基于 Tk === - -[https://en.wikipedia.org/wiki/Tk_(framework) Tk] 是一个跨平台的界面组件库。 - -

Tkinter & tkinter

- -这是 Python 内置的标准库,封装了 Tcl/Tk 界面库。 - -Python2 的模块名叫 Tkinter,到 Python3 模块名改为 tkinter - -代码示例——用 Tkinter 写 Hello world - -from Tkinter import * - -if __name__ == "__main__" : - root = Tk() - label = Label(root, text="Hello, world") - label.pack() - root.mainloop() - - -=== 7.1.2 基于 wxWidgets === - -[https://en.wikipedia.org/wiki/WxWidgets wxWidgets] 是 C++ 开发的跨平台框架(不仅包括 GUI,还有其它功能)。 -

wxPython

- -Home:[http://www.wxpython.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/WxPython 英文]、[https://zh.wikipedia.org/wiki/WxPython 中文] - -在所有的 wxWidgets 的 Python 封装库中,这个是名气最大的。 - -[https://github.com/limodou/ulipad Ulipad](知名的国产的 Python IDE)就是基于 wxPython 开发的。 - -代码示例——用 wxPython 写 Hello world - -import wx - -class Frame(wx.Frame) : - pass - -class App(wx.App) : - def OnInit(self) : - self.frame = Frame(parent=None, title="Hello, world") - self.frame.Show() - self.SetTopWindow(self.frame) - return True - -if __name__ == "__main__" : - app = App() - app.MainLoop() - - -

PythonCard

- -Home:[http://pythoncard.sourceforge.net/] - -又一个基于 wxWidgets 的 GUI 库。 - -=== 7.1.3 基于 GTK+ === - -[https://en.wikipedia.org/wiki/GTK%2B GTK+] 全称是(GIMP Toolkit),由 C 开发的跨平台界面组件库。 -

PyGTK

- -Home:[http://www.pygtk.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/PyGTK 英文] - -它是 Python 对 GTK+2 的封装。 - -代码示例——用 PyGTK 写 Hello world - -import pygtk -pygtk.require("2.0") -import gtk - -class HelloWorld : - def __init__(self) : - self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) - self.window.connect("delete_event", self.delete_event) - self.window.connect("destroy", self.destroy) - self.window.set_border_width(10) - - self.button = gtk.Button("Hello, world") - self.button.connect("clicked", self.hello, None) - self.button.connect_object("clicked", gtk.Widget.destroy, self.window) - self.window.add(self.button) - - self.button.show() - self.window.show() - - def main(self) : - gtk.main() - - def hello(self, widget, data=None) : - print("Hello, world") - - def delete_event(self, widget, event, data=None) : - print("delete event occurred") - return False - - def destroy(self, widget, data=None) : - gtk.main_quit() - -if __name__ == "__main__" : - hello = HelloWorld() - hello.main() - - -

PyGObject(PyGI)

- -Home:[https://live.gnome.org/PyGObject] - -它是 Python 对 GTK+3 的封装。PyGTK 的官网也推荐它。 - -代码示例——用 PyGObject 写 Hello world - -from gi.repository import Gtk - -class MyWindow(Gtk.Window): - def __init__(self): - Gtk.Window.__init__(self, title="Hello World") - - self.button = Gtk.Button(label="Click Here") - self.button.connect("clicked", self.on_button_clicked) - self.add(self.button) - - def on_button_clicked(self, widget): - print("Hello, world!") - -win = MyWindow() -win.connect("delete-event", Gtk.main_quit) -win.show_all() -Gtk.main() - - -=== 7.1.4 基于 Qt === - -[https://en.wikipedia.org/wiki/Qt_(toolkit) Qt] 是 C++ 开发的跨平台框架(不仅包括 GUI,还有其它功能)。 - -

PyQt

- -Home:[http://www.riverbankcomputing.com/software/pyqt/] - -Wikipedia:[https://en.wikipedia.org/wiki/PyQt 英文]、[https://zh.wikipedia.org/wiki/PyQt 中文] - -这是 Python 对 Qt 的封装。 - -代码示例——用 pyQt 写 Hello world - -import sys -from PyQt4.QtGui import * - -if __name__ == "__main__" : - app = QApplication(sys.argv) - window = QWidget() - - window.resize(320, 240) - window.setWindowTitle("Hello, world") - window.show() - sys.exit(app.exec_()) - - -

PySide

- -Home:[http://www.pyside.org/] - -这也是 Python 对 Qt 的封装。 - -=== 7.1.5 基于 FLTK === - -[https://en.wikipedia.org/wiki/FLTK FLTK] 全称是(Fast Light Tool Kit),由 C++ 开发的跨平台、轻量级界面组件库。 -

PyFLTK

- -Home:[http://pyfltk.sourceforge.net/] - -这是 Python 对 FLTK 的封装。 - -=== 7.1.6 基于 Windows 平台 === - -

PyWin32

- -PyWin32 前面已经介绍过。它可以提供原生的 Windows GUI 界面。 - -

IronPython

- -IronPython 前面已经介绍过。它可以提供 dotNET 的 GUI 界面。 - -=== 7.1.7 基于 JVM 平台 === - -

Jython

- -Jython 前面已经介绍过。它可以提供基于 Java 的 [https://en.wikipedia.org/wiki/Swing_%28Java%29 Swing] 界面。 - -=== 7.1.8 (其它) === - -

EasyGUI

- -Home:[http://easygui.sourceforge.net/] - -EasyGUI 这是一个很轻量级的库。跟其它 GUI 不同之处在于——它没有“事件驱动”。 - -

PyGUI

- -Home:[http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/] - -PyGUI 是一个更高层的 GUI 库,底层分别封装了 [http://python.net/crew/mhammond/win32/ PyWin32](Windows 平台)、[http://www.pygtk.org/ PyGTK](Linux 平台)、[http://pyobjc.sourceforge.net/ PyObjC](Mac OS X 平台)。 - -

Kivy

- -Home:[http://kivy.org/] - -跨平台的多媒体框架和界面库,用来开发比较炫的界面。 - -除了支持桌面操作系统,还支持 Android / iOS,支持多点触摸。 - -

OcempGUI

- -Home:[http://ocemp.sourceforge.net/gui.html] - -基于 PyGame 的一个跨平台 GUI 库(PyGame 下面会提到)。 - -== 7.2 图表 & 报表 == - -

matplotlib

- -Home:[http://matplotlib.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/Matplotlib 英文] - -这是一个有名的图形库,主要用来绘制数学相关的图形。 - -它跟后面提到的 [http://www.scipy.org/ SciPy] 整合可以起到类似 MATLAB 的效果。效果图在“[http://matplotlib.org/users/screenshots.html 这里]”。 - -

Gnuplot.py

- -Home:[http://gnuplot-py.sourceforge.net/] - -这是 Python 对 [http://www.gnuplot.info/ gnuplot] 的封装。gnuplot 的效果图在“[http://www.gnuplot.info/screenshots/index.html 这里]”。 - -

PyQtGraph

- -Home:[http://www.pyqtgraph.org/] - -这是一个纯 Python 的库,依赖于 PyQt4 / PySide。效果图在“[http://www.pyqtgraph.org/images/plotting_sm.png 这里]”。 - -

PyX

- -Home:[http://pyx.sourceforge.net/] - -这个库可以跟 TeX / LaTeX 无缝整合,支持导出为 PostScript / PDF 格式。适合用来制作报表。效果图在“[http://pyx.sourceforge.net/gallery/index.html 这里]”。 - -

Chaco

- -Home:[http://code.enthought.com/chaco/] - -这是一个商业公司维护的库,主要提供2维图表。效果图在“[http://docs.enthought.com/chaco/user_manual/annotated_examples.html 这里]”。 - ----- - -= 8 信息安全 = - -== 8.1 密码学 == - -

hashlib

- -在 Python 2.5 版本加入到标准库中。通过它,你可以很方便地计算各种散列值。 - -它支持的哈希算法有:MD5 SHA1 SHA224 SHA256 SHA384 SHA512 - -关于散列算法,俺写过一篇扫盲(在“[http://program-think.blogspot.com/2013/02/file-integrity-check.html 这里]”)。 - -代码示例——计算字符串的 SHA1 散列值 - -import hashlib -sha1 = hashlib.sha1("Hello, world").hexdigest() - - -

PyCrypto

- -Home:[http://www.dlitz.net/software/pycrypto/] - -这个库包含了常见的对称加密算法(DES、AES、IDEA 等)、公钥加密算法(RSA、DSA 等)、散列算法(MD5、SHA1、RIPEMD 等)。 - -

pyOpenSSL

- -Home:[http://pyopenssl.sourceforge.net/] - -[https://en.wikipedia.org/wiki/OpenSSL OpenSSL] 在加密领域可是大名鼎鼎。这个库使用 Python 对 OpenSSL 进行很薄的封装。 - ----- - -= 9 处理文件格式 = - -== 9.1 结构化数据格式 == - -=== 9.1.1 CSV === - -[https://en.wikipedia.org/wiki/Comma-separated_values CSV] 是一种历史悠久的结构化数据存储格式。其效果类似于一张数据库二维表。 -

csv

- -标准库,提供 CSV 格式文件的读写。 - -=== 9.1.2 JSON === - -JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。 -

json

- -标准库,提供 JSON 格式的编码和解码。 - -代码示例——编码/解码 JSON 字符串 - -import json - -json.dumps(["foo", {"bar": ("baz", None, 1.0, 2)}]) -# JSON 编码 -# 得到如下【字符串】 -# """["foo", {"bar": ["baz", null, 1.0, 2]}]""" - -json.loads("""["foo", {"bar":["baz", null, 1.0, 2]}]""") -# JSON 解码 -# 得到如下【对象】 -# [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] - - -=== 9.1.3 YAML === - -[https://en.wikipedia.org/wiki/YAML YAML] 是一种类似于 json 的结构化数据格式。它在确保可读性的基础上,提供了超越 json 的灵活性和扩展性。 -

PyYAML

- -Home:[http://pyyaml.org/] - -pyyaml 提供了 Python 对 YAML 的封装。 - -== 9.2 压缩文件 & 打包文件 == - -=== 9.2.1 zip === - -

zipfile

- -处理 zip 格式的标准库。 - -=== 9.2.2 bzip2(bz2) === - -

bz2

- -处理 bzip2 格式的标准库。 - -=== 9.2.3 gzip(gz) === - -

gzip

- -处理 gzip 格式的标准库。 - -

zlib

- -处理 gzip 格式的标准库。 - -=== 9.2.4 tar === - -

tarfile

- -处理 tar 格式的标准库。 - -=== 9.2.5 7zip(7z) === - -

PyLZMA

- -Home:[http://www.joachim-bauch.de/projects/pylzma/] - -处理 7zip 格式的第三方库。 - -=== 9.2.6 rar === - -

rarfile

- -Home:[http://rarfile.berlios.de/] - -处理 rar 格式的第三方库。 - -=== 9.2.7 msi === - -

msilib

- -处理 msi 格式的标准库,从 Python 2.5 版本开始提供。 - -== 9.3 标记语言 == - -=== 9.3.1 XML === - -

xml.dom & xml.miniDom & xml.etree.ElementTree

- -用 DOM(Document Object Model)方式处理 XML 文件的标准库。 - -

xml.sax & xml.parsers.expat

- -用 SAX(Simple API for XML)方式处理 XML 文件的标准库。 - -

lxml

- -Home:[http://lxml.de/] - -著名的 C 语言库 libxml 和 libxslt 的 Python 封装。 - -功能很强,支持 XPath 1.0、XSLT 1.0、扩展 EXSLT、等。还可以用来解析 HTML 格式。 - -=== 9.3.2 HTML === - -

HTMLParser

- -以回调方式解析 HTML/XHTML 文件内容的标准库。 - -== 9.4 图片 == - -

Python Imaging Library(PIL)

- -Home:[http://www.pythonware.com/products/pil/] - -Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] - -这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG、等)。 - -它可以对图像进行各种常见的处理(格式转换、旋转、缩放、剪切、等)。 - -代码示例——旋转某图片并显示 - -from PIL import Image -im = Image.open("xxx.jpg") -im = im.rotate(90) -im.show() - - -

Wand

- -Home:[http://docs.wand-py.org/] - -它通过前面提到 ctypes 实现了对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装(ImageMagick 是最强大的开源图片处理工具集)。 - -代码示例 - -from wand.image import Image -from wand.display import display - -with Image(filename="mona-lisa.png") as img : - print(img.size) - for r in 1, 2, 3 : - with img.clone() as i : - i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25)) - i.rotate(90 * r) - i.save(filename="mona-lisa-{0}.png".format(r)) - display(i) - - -== 9.5 PDF == - -

pyfpdf

- -Home:[https://github.com/reingart/pyfpdf] - -这是 [http://www.fpdf.org/ FPDF] 的 Python 移植库,用来生成 PDF 文档。 - -支持的功能比较全(嵌入字体、嵌入图片),文档也比较详细。 - -代码示例——简单的 Hello World 示例 - -from fpdf import FPDF - -pdf = FPDF() -pdf.add_page() -pdf.set_font("Arial", "B", 16) -pdf.cell(40, 10, "Hello, World") -pdf.output("test.pdf", "F") - - -代码示例——支持写入 HTML 语法(目前支持几种常见的 HTML tag) - -from pyfpdf import FPDF, HTMLMixin - -class MyFPDF(FPDF, HTMLMixin) : - pass - -pdf = MyFPDF() -pdf.add_page() -pdf.write_html(html) -pdf.output("test.pdf", "F") - - -

pyPdf & PyPDF2

- -Home:[http://knowah.github.com/PyPDF2/] - -pyPdf 目前已经不继续升级维护了。PyPDF2 是从 pyPdf 派生出来的,并继续增加新功能。 - -它除了可以提取文件属性,还可以切分/合并文档,加密/解密文档。 - -

PDFMiner

- -Home:[http://www.unixuser.org/~euske/python/pdfminer/] - -它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 - -== 9.6 MS Office 文档 == - -=== 9.6.1 Word(doc、docx) === - -

PyWin32

- -PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 - -=== 9.6.2 Excel(xls、xlsx) === - -

pyExcelerator

- -Home:[http://sourceforge.net/projects/pyexcelerator/] - -它可以支持 Office Excel(97/2000/XP/2003)以及 OpenOffice Calc 的文档。无需依赖外部软件。 - -

PyWin32

- -PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - -=== 9.6.3 Power Point(ppt、pptx) === - -

python-pptx

- -Home:[https://github.com/scanny/python-pptx] - -它可以用来生成 pptx(Open XML PowerPoint)格式的文档。 - -

PyWin32

- -PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - -== 9.7 RTF == - -

PyRTF

- -Home:[http://pyrtf.sourceforge.net/] - -它可以用来处理 RTF(富文本格式)文档。 - -== 9.8 CHM == - -

PyCHM

- -Home:[http://gnochm.sourceforge.net/pychm.html] - -这是基于 [http://www.jedrea.com/chmlib/ chmlib] 的 Python 封装库。可以提取 CHM 文件的属性以及每个页面的内容。 - ----- - -= 10 游戏开发 = - -

PyGame

- -Home:[http://www.pygame.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/Pygame 英文]、[https://zh.wikipedia.org/wiki/Pygame 中文] - -跨平台的 Python 第三方库,用来辅助游戏开发的,名气非常大。 - -

PyOpenGL

- -Home:[http://pyopengl.sourceforge.net/] - -封装 [https://en.wikipedia.org/wiki/OpenGL OpenGL] 的 Python 第三方库。 - -

Python-Ogre

- -Home:[http://www.python-ogre.org/] - -封装 [https://en.wikipedia.org/wiki/OGRE OGRE](3D 渲染引擎)的 Python 第三方库。 - ----- - -= 11 数值计算 & 科学计算 = - -

NumPy

- -Home:[http://www.numpy.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/NumPy 英文]、[https://zh.wikipedia.org/wiki/NumPy 中文] - -它提供了功能强大、性能很高的数值数组,可以用来进行各种数值计算(包括矩阵运算)。 - -代码示例 - -# 以下是传统 Python 写法,冗长且速度较慢 -a = range(10000000) -b = range(10000000) -c = [] -for i in range(len(a)) : - c.append(a[i] + b[i]) - -# 以下是 NumPy 的写法,简洁且速度飞快 -import numpy as np -a = np.arange(10000000) -b = np.arange(10000000) -c = a + b - - -

SciPy

- -Home:[http://www.scipy.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/SciPy 英文]、[https://zh.wikipedia.org/wiki/SciPy 中文] - -它依赖 NumPy 提供的多维数组。相比 NumPy,它提供了更高层的数学运算模块(统计、线性代数、积分、常微分方程求解、傅立叶变换、信号处理 ...)。 - -它被广泛用于科研和工程领域。 - -

SymPy

- -Home:[http://sympy.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia.org/wiki/SymPy 中文] - -它是用来做符号计算的,其目标是成为一个全功能的“计算机代数系统”。 - -它支持的功能包括:符号计算、高精度计算、模式匹配、绘图、解方程、微积分、组合数学、离散数学、几何学、概率与统计 ...... - ----- - -= 12 其它 = - -一些不方便归类的,暂时放到这里。 - -

PyPy

- -Home:[http://www.pypy.org/] - -Wikipedia:[https://en.wikipedia.org/wiki/PyPy 英文]、[https://zh.wikipedia.org/wiki/PyPy 中文] - -它是一个用 Python 写的 Python 解释器(有点绕口令)。 - -PyPy 支持 JIT(Just-in-time compilation)和沙箱技术,可做到【比 CPython 更快的运行速度】。 - +diff -c /home/browser/download/opensource.yaml/temp/old-python.wiki /home/browser/download/opensource.yaml/temp/python.wiki +*** /home/browser/download/opensource.yaml/temp/old-python.wiki 2015-07-03 15:16:20.702455188 +0800 +--- /home/browser/download/opensource.yaml/temp/python.wiki 2015-07-03 15:41:46.010487611 +0800 +*************** +*** 1185,1232 **** + + 以回调方式解析 HTML/XHTML 文件内容的标准库。 + +! == 9.4 图片 == +! +!

Python Imaging Library(PIL)

+! +! Home:[http://www.pythonware.com/products/pil/] +! +! Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] +! +! 这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG、等)。 +! +! 它可以对图像进行各种常见的处理(格式转换、旋转、缩放、剪切、等)。 +! +! 代码示例——旋转某图片并显示 +! +! from PIL import Image +! im = Image.open("xxx.jpg") +! im = im.rotate(90) +! im.show() +! +! +!

Wand

+! +! Home:[http://docs.wand-py.org/] +! +! 它通过前面提到 ctypes 实现了对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装(ImageMagick 是最强大的开源图片处理工具集)。 +! +! 代码示例 +! +! from wand.image import Image +! from wand.display import display +! +! with Image(filename="mona-lisa.png") as img : +! print(img.size) +! for r in 1, 2, 3 : +! with img.clone() as i : +! i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25)) +! i.rotate(90 * r) +! i.save(filename="mona-lisa-{0}.png".format(r)) +! display(i) +! +! +! == 9.5 PDF == + +

pyfpdf

+ +--- 1185,1191 ---- + + 以回调方式解析 HTML/XHTML 文件内容的标准库。 + +! == 9.4 PDF == + +

pyfpdf

+ +*************** +*** 1274,1288 **** + + 它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 + +! == 9.6 MS Office 文档 == + +! === 9.6.1 Word(doc、docx) === + +

PyWin32

+ + PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 + +! === 9.6.2 Excel(xls、xlsx) === + +

pyExcelerator

+ +--- 1233,1247 ---- + + 它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 + +! == 9.5 MS Office 文档 == + +! === 9.5.1 Word(doc、docx) === + +

PyWin32

+ + PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 + +! === 9.5.2 Excel(xls、xlsx) === + +

pyExcelerator

+ +*************** +*** 1294,1300 **** + + PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 + +! === 9.6.3 Power Point(ppt、pptx) === + +

python-pptx

+ +--- 1253,1259 ---- + + PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 + +! === 9.5.3 Power Point(ppt、pptx) === + +

python-pptx

+ +*************** +*** 1306,1312 **** + + PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 + +! == 9.7 RTF == + +

PyRTF

+ +--- 1265,1271 ---- + + PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 + +! == 9.6 RTF == + +

PyRTF

+ +*************** +*** 1314,1320 **** + + 它可以用来处理 RTF(富文本格式)文档。 + +! == 9.8 CHM == + +

PyCHM

+ +--- 1273,1279 ---- + + 它可以用来处理 RTF(富文本格式)文档。 + +! == 9.7 CHM == + +

PyCHM

+ +*************** +*** 1324,1330 **** + + ---- + +! = 10 游戏开发 = + +

PyGame

+ +--- 1283,1356 ---- + + ---- + +! = 10 图像 = +! +! == 10.1 图像处理 == +! +!

Python Imaging Library(PIL)

+! +! Home:[http://www.pythonware.com/products/pil/] +! +! Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] +! +! 这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG ...)。 +! +! 它可以对图像进行各种常见的处理(旋转、缩放、剪切 ...)。 +! +! 代码示例——为某个目录下所有 JPEG 创建缩略图 +! +! import os, glob +! from PIL import Image +! +! size = 128, 128 +! for file in glob.glob("*.jpg"): +! name, ext = os.path.splitext(file) +! img = Image.open(file) +! img.thumbnail(size) +! img.save(name+".thumbnail", "JPEG") +! +! +! 代码示例——旋转某图片并显示 +! +! from PIL import Image +! +! img = Image.open("xxx.jpg") +! img = img.rotate(90) +! img.show() +! +! +!

Wand

+! +! Home:[http://docs.wand-py.org/] +! +! 它通过前面提到 ctypes 实现了对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装(ImageMagick 是最强大的开源图片处理工具集)。 +! +! 代码示例——旋转并缩放某图片 +! +! from wand.image import Image +! from wand.display import display +! +! with Image(filename="mona-lisa.png") as img : +! print(img.size) +! for r in 1, 2, 3 : +! with img.clone() as new_img : +! new_img.resize(int(new_img.width/2), int(new_img.height/2)) +! new_img.rotate(90 * r) +! new_img.save(filename="mona-lisa-{0}.png".format(r)) +! display(new_img) +! +! +! == 10.2 图像格式转换 == +! +!

Python Imaging Library(PIL)

+! +! PIL 前面已经介绍过。它支持常见图像文件格式(BMP、JPG、GIF、PNG ...)之间的相互转换。 +! +!

Wand

+! +! Wand 前面已经介绍过。由于它是针对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装。只要 ImageMagick 能转换的格式,它也可以转换。 +! +! = 11 游戏开发 = + +

PyGame

+ +*************** +*** 1348,1354 **** + + ---- + +! = 11 数值计算 & 科学计算 = + +

NumPy

+ +--- 1374,1380 ---- + + ---- + +! = 12 数值计算 & 科学计算 = + +

NumPy

+ +*************** +*** 1396,1402 **** + + ---- + +! = 12 其它 = + + 一些不方便归类的,暂时放到这里。 + +--- 1422,1428 ---- + + ---- + +! = 13 其它 = + + 一些不方便归类的,暂时放到这里。 + + +Diff finished. Fri Jul 3 16:55:45 2015 From e60998dca5be63fcc3734cfa4e5939d47c596a1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 4 Jul 2015 00:08:39 +0800 Subject: [PATCH 012/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E2=80=9D=E7=9A=84=E5=88=86=E7=B1=BB=E5=B1=82=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 1703 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 1438 insertions(+), 265 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index e22070a..3cde56d 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1,265 +1,1438 @@ -diff -c /home/browser/download/opensource.yaml/temp/old-python.wiki /home/browser/download/opensource.yaml/temp/python.wiki -*** /home/browser/download/opensource.yaml/temp/old-python.wiki 2015-07-03 15:16:20.702455188 +0800 ---- /home/browser/download/opensource.yaml/temp/python.wiki 2015-07-03 15:41:46.010487611 +0800 -*************** -*** 1185,1232 **** - - 以回调方式解析 HTML/XHTML 文件内容的标准库。 - -! == 9.4 图片 == -! -!

Python Imaging Library(PIL)

-! -! Home:[http://www.pythonware.com/products/pil/] -! -! Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] -! -! 这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG、等)。 -! -! 它可以对图像进行各种常见的处理(格式转换、旋转、缩放、剪切、等)。 -! -! 代码示例——旋转某图片并显示 -! -! from PIL import Image -! im = Image.open("xxx.jpg") -! im = im.rotate(90) -! im.show() -! -! -!

Wand

-! -! Home:[http://docs.wand-py.org/] -! -! 它通过前面提到 ctypes 实现了对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装(ImageMagick 是最强大的开源图片处理工具集)。 -! -! 代码示例 -! -! from wand.image import Image -! from wand.display import display -! -! with Image(filename="mona-lisa.png") as img : -! print(img.size) -! for r in 1, 2, 3 : -! with img.clone() as i : -! i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25)) -! i.rotate(90 * r) -! i.save(filename="mona-lisa-{0}.png".format(r)) -! display(i) -! -! -! == 9.5 PDF == - -

pyfpdf

- ---- 1185,1191 ---- - - 以回调方式解析 HTML/XHTML 文件内容的标准库。 - -! == 9.4 PDF == - -

pyfpdf

- -*************** -*** 1274,1288 **** - - 它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 - -! == 9.6 MS Office 文档 == - -! === 9.6.1 Word(doc、docx) === - -

PyWin32

- - PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 - -! === 9.6.2 Excel(xls、xlsx) === - -

pyExcelerator

- ---- 1233,1247 ---- - - 它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 - -! == 9.5 MS Office 文档 == - -! === 9.5.1 Word(doc、docx) === - -

PyWin32

- - PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 - -! === 9.5.2 Excel(xls、xlsx) === - -

pyExcelerator

- -*************** -*** 1294,1300 **** - - PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - -! === 9.6.3 Power Point(ppt、pptx) === - -

python-pptx

- ---- 1253,1259 ---- - - PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - -! === 9.5.3 Power Point(ppt、pptx) === - -

python-pptx

- -*************** -*** 1306,1312 **** - - PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - -! == 9.7 RTF == - -

PyRTF

- ---- 1265,1271 ---- - - PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 - -! == 9.6 RTF == - -

PyRTF

- -*************** -*** 1314,1320 **** - - 它可以用来处理 RTF(富文本格式)文档。 - -! == 9.8 CHM == - -

PyCHM

- ---- 1273,1279 ---- - - 它可以用来处理 RTF(富文本格式)文档。 - -! == 9.7 CHM == - -

PyCHM

- -*************** -*** 1324,1330 **** - - ---- - -! = 10 游戏开发 = - -

PyGame

- ---- 1283,1356 ---- - - ---- - -! = 10 图像 = -! -! == 10.1 图像处理 == -! -!

Python Imaging Library(PIL)

-! -! Home:[http://www.pythonware.com/products/pil/] -! -! Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] -! -! 这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG ...)。 -! -! 它可以对图像进行各种常见的处理(旋转、缩放、剪切 ...)。 -! -! 代码示例——为某个目录下所有 JPEG 创建缩略图 -! -! import os, glob -! from PIL import Image -! -! size = 128, 128 -! for file in glob.glob("*.jpg"): -! name, ext = os.path.splitext(file) -! img = Image.open(file) -! img.thumbnail(size) -! img.save(name+".thumbnail", "JPEG") -! -! -! 代码示例——旋转某图片并显示 -! -! from PIL import Image -! -! img = Image.open("xxx.jpg") -! img = img.rotate(90) -! img.show() -! -! -!

Wand

-! -! Home:[http://docs.wand-py.org/] -! -! 它通过前面提到 ctypes 实现了对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装(ImageMagick 是最强大的开源图片处理工具集)。 -! -! 代码示例——旋转并缩放某图片 -! -! from wand.image import Image -! from wand.display import display -! -! with Image(filename="mona-lisa.png") as img : -! print(img.size) -! for r in 1, 2, 3 : -! with img.clone() as new_img : -! new_img.resize(int(new_img.width/2), int(new_img.height/2)) -! new_img.rotate(90 * r) -! new_img.save(filename="mona-lisa-{0}.png".format(r)) -! display(new_img) -! -! -! == 10.2 图像格式转换 == -! -!

Python Imaging Library(PIL)

-! -! PIL 前面已经介绍过。它支持常见图像文件格式(BMP、JPG、GIF、PNG ...)之间的相互转换。 -! -!

Wand

-! -! Wand 前面已经介绍过。由于它是针对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装。只要 ImageMagick 能转换的格式,它也可以转换。 -! -! = 11 游戏开发 = - -

PyGame

- -*************** -*** 1348,1354 **** - - ---- - -! = 11 数值计算 & 科学计算 = - -

NumPy

- ---- 1374,1380 ---- - - ---- - -! = 12 数值计算 & 科学计算 = - -

NumPy

- -*************** -*** 1396,1402 **** - - ---- - -! = 12 其它 = - - 一些不方便归类的,暂时放到这里。 - ---- 1422,1428 ---- - - ---- - -! = 13 其它 = - - 一些不方便归类的,暂时放到这里。 - - -Diff finished. Fri Jul 3 16:55:45 2015 +

Python 开源库及示例代码

+ += = + += 说明 = + +本页面汇总俺收集的各种 Python 代码库,不定期更新。 + +本页面列出的各种 Python 库/模块,如果注明了官网的网址,说明这个库是第三方的;否则就是 Python 语言内置的标准库。 + +如果你发现本页面的开源库有错漏之处,非常欢迎给俺提供反馈——有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 + +---- + += 1 算法 = + +== 1.1 字符串 == + +=== 1.1.1 正则表达式 === + +

re

+ +正则表达式的标准库,提供基于正则的匹配和替换。 + +=== 1.1.2 字符集 === + +

chardet

+ +Home:[https://github.com/erikrose/chardet] + +chardet 可以猜测任意一段文本的字符集编码。对于编码类型未知的文本,它会很有用。 + +chardet 既可以作为模块来使用,也可以作为命令行工具来使用。 + +代码示例 + +import chardet +print(chardet.detect(bytes)) + + +=== 1.1.3 (其它) === + +

StringIO & cStringIO

+ +以读写文件的方式来操作字符串(有点类似于内存文件)。 + +cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现的,提供 Unicode 兼容性。 + +== 1.2 编码 & 解码 == + +=== 1.2.1 base64 === + +[https://en.wikipedia.org/wiki/Base64 Base64] 是一组编码算法的总称。用于把二进制数据编码为文本。 + +

base64

+ +标准库,提供 Base16、Base32、Base64 格式的编码和解码。 + +=== 1.2.2 UUencode === + +[https://en.wikipedia.org/wiki/Uuencode UUencode] 出现于早期的 Unix 系统。用于把二进制编码为文本,以便通过邮件系统发送。 + +

uu

+ +标准库,提供 UUencode 格式的编码和解码。 + +=== 1.2.3 BinHex === + +[https://en.wikipedia.org/wiki/BinHex BinHex] 起先用于 Mac OS 系统,类似于 UUencode。 + +

binhex

+ +标准库,提供 BinHex 格式的编码和解码。 + +== 1.3 数学类 == + +

math

+ +顾名思义,这个标准库封装了常用的数学函数(开方、指数、对数、三角函数......)。 + +

random

+ +顾名思义,这个标准库是用来进行随机数生成滴。 + +代码示例——生成 0-100 的随机数 + +import random +random.seed() +random.randint(0, 100) + + +

fractions

+ +这个标准库封装了跟有理数(分数)相关的运算 + +---- + += 2 跨语言编程 = + +Python 可以很容易地跟其它编程语言整合。整合之后,就可以在 Python 代码中使用其它编程语言的函数、模块、库,非常爽! +== 2.1 整合 C & C++ == + +

ctypes

+ +ctypes 在 Python 2.5 版本加入到标准库中。 + +通过它,你可以很方便地调用 C/C++ 动态库导出的函数,可以在 Python 中使用各种 C/C++ 的数据类型(比如指针)。 + +代码示例——调用 Linux/Unix 系统的标准 C 函数,获取当前时间 + +from ctypes import * +libc = CDLL("libc.so.6") +time = libc.time(None) + +# 调用 Windows 系统 API,弹出消息提示框 +from ctypes import c_int, WINFUNCTYPE, windll +from ctypes.wintypes import HWND, LPCSTR, UINT +prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT) +paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) +MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) +MessageBox(text="Hello, world", flags=2) + + +

SWIG(Simplified Wrapper and Interface Generator)

+ +Home:[http://swig.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] + +这是一个很老牌的、有名气的工具,它可以把多种语言(Java、Python、C#、Ruby、PHP、Perl、Lua、Go、等)整合到 C/C++ 中。 + +

Cython

+ +Home:[http://cython.org/] + +这个工具可以让你用 Python 的语法写扩展模块的代码,然后它帮你把 Python 代码编译为本地动态库(机器码)。 + +用它编译出来的扩展模块,其性能跟 C/C++ 编写的扩展模块相当。 + +== 2.2 整合 JVM 平台 == + +

Jython

+ +Home:[http://www.jython.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Jython 英文]、[https://zh.wikipedia.org/wiki/Jython 中文] + +通过 Jython 可以让 Python 代码运行在 JVM 上,并且可以调用其它的 JVM 语言的代码(比如 Java、Scale) + +== 2.3 整合 dotNet 平台 == + +

IronPython

+ +Home:[http://ironpython.net/] + +Wikipedia:[https://en.wikipedia.org/wiki/IronPython 英文]、[https://zh.wikipedia.org/wiki/IronPython 中文] + +通过 IronPython 可以让 Python 代码运行在 dotNET 平台上,并且可以调用其它的 dotNET 语言的代码(C#、F#、VB.Net ...) + +== 2.4 整合 Objective-C 语言 == + +

PyObjC

+ +Home:[http://pyobjc.sourceforge.net/] + +这是用 Python 封装 Mac OS X 上的 Objective-C 库。 + +---- + += 3 操作系统相关 = + +== 3.1 文件和目录操作 == + +

os

+ +这是一个非常基本的标准库,提供了常见的操作系统相关功能,很多功能是针对文件系统。 + +

shutil

+ +相对于 os 标准库,shutil 标准库提供了一些比较高级的文件和目录操作(目录递归复制、目录递归删除、目录压缩打包...) + +代码示例——递归删除某个目录 + +import shutil +shutil.rmtree(xxxx) + + +

glob

+ +这个标准库用于查找文件,【支持通配符】(* 和 ?) + +代码示例——获取当前目录所有 txt 文件 + +import glob +for file in glob.glob("./*.txt") : + print(file) + + +

fnmatch

+ +这个标准库用于匹配文件名(支持通配符,类似上面的 glob) + +代码示例——列出当前目录所有 txt 文件 + +import os, fnmatch + +for file in os.listdir(".") : + if fnmatch.fnmatch(file, "*.txt") : + print(file) + + +

tempfile

+ +使用这个标准库,可以安全地生成临时文件或临时目录。 + + + +== 3.2 本地进程间通信(IPC) == + +

subprocess & multiprocessing

+ +用于进程管理的标准库,可以启动子进程,通过标准输入输出跟子进程交互。 + +其中 multiprocessing 是 2.6 版本加入到标准库的。 + +

signal

+ +用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 + +

mmap

+ +提供了内存映射文件的支持。 + +代码示例——利用 mmap 在父子进程间交换数据 + +import os +import mmap + +map = mmap.mmap(-1, 13) +map.write("Hello, world") + +pid = os.fork() +if pid == 0: # 子进程 + map.seek(0) + print(map.readline()) + map.close() + + +== 3.3 Windows 系统相关 == + +

PyWin32

+ +Home:[http://python.net/crew/mhammond/win32/] + +这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 + +== 3.4 Linux & Unix 系统相关 == + +

syslog

+ +通过这个标准库,可以很方便地跟 POSIX 的 syslog 服务进行交互。 + +== 3.5 程序打包 == + +

PyInstaller

+ +Home:[http://www.pyinstaller.org/] + +PyInstaller 可以把你的 Python 代码制作成独立运行的程序(不依赖 Python 环境就可以运行)。 + +该工具支持多种操作系统,包括:Windows、Linux、Mac OS X、Solaris、AIX、等。 + +

py2exe

+ +Home:[http://www.py2exe.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Py2exe 英文] + +py2exe 的功能类似 PyInstaller,但只支持 Windows 平台。 + +

py2app

+ +Home:[https://bitbucket.org/ronaldoussoren/py2app] + +它很类似于 [http://www.py2exe.org/ py2exe],差别在于 [http://www.py2exe.org/ py2exe] 支持 Windows 平台,而 [https://bitbucket.org/ronaldoussoren/py2app py2app] 支持 Mac OS X 平台。 + +

EasyInstall & Setuptools

+ +Home:[https://pypi.python.org/pypi/setuptools] + +这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) + +---- + += 4 Web 开发 = + +== 4.1 HTTP Client == + +

httplib & httplib2 & http.request & urllib.parse

+ +这几个库可以进行各种 HTTP 客户端请求(GET、POST、等)。 + +Python2 的模块名是 httplib 和 httplib2;到 Python3,模块名改为 http.request 和 urllib.parse + +代码示例——读取指定 URL 的网页内容 + +import urllib +handle = urllib.urlopen("http://www.google.com") +page = handle.read() +handle.close() + + +== 4.2 HTTP Server == + +

SimpleHTTPServer & http.server

+ +提供轻量级 HTTP Server 的标准库。 + +Python2 的模块名叫 SimpleHTTPServer;到 Python3 模块名改为 http.server + +代码示例——一个极简单的 HTTP 服务 + +import SocketServer +import SimpleHTTPServer + +PORT = 8080 +Handler = SimpleHTTPServer.SimpleHTTPRequestHandler +httpd = SocketServer.TCPServer(("", PORT), Handler) +print("serving at port %d" % PORT) +httpd.serve_forever() + + +== 4.3 Web 开发框架 == + +(Python 的 Web 框架数不胜数,俺只挑选几个代表性的) +

Django

+ +Home:[https://www.djangoproject.com/] + +Wikipedia:[https://en.wikipedia.org/wiki/Django_(web_framework) 英文]、[https://zh.wikipedia.org/wiki/Django 中文] + +在 Python 社区,Django 是目前最有影响力的 Web 开发框架。该框架很重型,内置了 Web 服务端开发常用的组件(比如:ORM、用户管理)。 + +Django 应用范围很广,比如 Google 的 Web 开发平台 GAE 就支持它。 + +而且它完全支持前面提到的 Jython 运行环境,可以运行在任何 J2EE 服务器上。 + +

TurboGears

+ +Home:[http://www.turbogears.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wikipedia.org/wiki/TurboGears 中文] + +又一个重型的 Web 开发框架,名气仅次于 Django。 + +== 4.4 Web前端 & JS整合 == + +

Pyjamas & pyjs

+ +Home:[http://pyjs.org/] + +这是从 GWT(Google Web Toolkit)移植的第三方库。提供了 Python 到 JS 的编译,AJAX 框架等功能。 + +Pyjamas 甚至能用来开发桌面 GUI 应用。 + +

pyjaco

+ +Home:[https://github.com/chrivers/pyjaco] + +这也是一个 Python 到 JavaScript 的编译工具。 + +== 4.5 浏览器整合 == + +

webbrowser

+ +操纵当前系统的默认浏览器,访问指定 URL 的页面。 + +代码示例——用默认浏览器打开 Google 主页 + +import webbrowser +webbrowser.open("http://www.google.com") + + +

pyv8

+ +Home:[https://pypi.python.org/pypi/PyV8] + +[https://developers.google.com/v8/ v8] 是 Google 开发的 JavaScript 解释引擎。这是对 v8 引擎的 Python 封装。 + +代码示例 + +import PyV8 + +ctxt1 = PyV8.JSContext() +ctxt1.enter() +ctxt1.eval("1+2") # 对 JS 表达式求值 + +class Global(PyV8.JSClass) : # 定义一个兼容 JS 的类 + def hello(self) : + print("Hello, world") + +ctxt2 = PyV8.JSContext(Global()) # 创建一个 JS 上下文,传入 Global 类的对象 +ctxt2.enter() +ctxt2.eval("hello()") # 调用 hello() 函数 + + +

PyWebKitGtk

+ +Home:[https://github.com/jmalonzo/pywebkitgtk] + +[http://webkitgtk.org/ WebKitGtk] 是一个基于 WebKit 的 Web 渲染引擎。 + +PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 + +---- + += 5 网络 = + +== 5.1 标准协议 == + +=== 5.1.1 链路层 & 网络层 === + +

Scapy

+ +Home:[http://www.secdev.org/projects/scapy/] + +Wikipedia:[https://en.wikipedia.org/wiki/Scapy 英文] + +这是一个底层的网络库,可以在不同协议层次构造网络数据包(包括链路层、网络层、传输层),还支持 Sniffer 抓包。 + +搞网络安全的网友应该会喜欢这个库。 + +代码示例 + +# 传统的 ping 扫描(网络层) +ans,unans = sr(IP(dst="192.168.1.1-254")/ICMP()) + +# 局域网内的 ARP 扫描(链路层) +ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2) + + +=== 5.1.2 传输层 === + +

socket

+ +Python 标准库很早就提供了对 socket 编程的支持。 + +这个标准库是对伯克利套接字进行简单的封装,其 API 基本上跟 BSD SOCKET 一一对应。 + +

asyncore

+ +这个标准库提供了异步 SOCKET 的支持。 + +

asynchat

+ +这个标准库基于上述的 asyncore,提供更高层的 API,简化异步通讯编程。 + +=== 5.1.3 应用层 === + +

ftplib

+ +封装 FTP 协议(文件传输)的标准库 + +

smtplib

+ +封装 SMTP 协议(邮件发送)的标准库 + +

imaplib

+ +封装 IMAP 协议(邮件接收)的标准库 + +

poplib

+ +封装 POP3 协议(邮件接收)的标准库 + +

PycURL

+ +Home:[http://pycurl.sourceforge.net/] + +[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。pycurl 提供了 Python 的封装。 + +关于 cURL,俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 + +

jabber.py

+ +Home:[http://jabberpy.sourceforge.net/] + +Jabber(又称 XMPP)是IM(即时通信)协议的标准。这是用 Python 封装的第三方库。 + +

irclib

+ +Home:[https://bitbucket.org/jaraco/irc] + +IRC 是 Internet Relay Chat 的缩写。这是用 Python 封装的第三方库。 + +== 5.2 自定义协议 == + +

Protocol Buffers

+ +Home:[https://developers.google.com/protocol-buffers/] + +Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] + +这是 Google 开发的一个跨语言的库,用于网络传输业务数据时的“编码/解码”。 + +其优点是:跨多种语言、高性能、向前兼容、向后兼容。俺前几年写过一篇博文推荐 protobuf(在“[http://program-think.blogspot.com/2009/05/opensource-review-protocol-buffers.html 这里]”)。 + +作为 Protocol Buffers 的发明者,Google 默认实现了三种编程语言(C++、Java、Python)对它的支持。 + +

Apache Thrift

+ +Home:[https://thrift.apache.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] + +来自于 Apache 社区,提供了一种跨语言的通讯机制。 + +程序员通过 Thrift 的“接口定义语言”定义通讯协议格式,然后 Thrift 根据协议格式自动帮你生成服务端和客户端代码。 + +(在这个方面,它有点类似于 Google 的 Protocol Buffers) + +== 5.3 网络开发框架 == + +

Twisted

+ +Home:[http://twistedmatrix.com/] + +Wikipedia:[https://en.wikipedia.org/wiki/Twisted_%28software%29 英文] + +这是一个基于 Python 网络通讯开发框架,诞生于2002年,名气很大。 + +它的某些设计类似于 C++ 的 [https://en.wikipedia.org/wiki/Adaptive_Communication_Environment ACE] 框架。除了能用来进行传输层(TCP UDP)的开发,还提供了若干应用层协议(HTTP、XMPP、SSH、IRC、等)的支持。 + +代码示例——实现一个简单的 Echo 服务,监听在 12345 端口 + +from twisted.internet import protocol, reactor + +class Echo(protocol.Protocol) : + def dataReceived(self, data) : + self.transport.write(data) + +class EchoFactory(protocol.Factory) : + def buildProtocol(self, addr) : + return Echo() + +reactor.listenTCP(12345, EchoFactory()) +reactor.run() + + +---- + += 6 数据库 = + +为了便于数据库开发,Python 社区制定了数据库的 API 规范([https://www.python.org/dev/peps/pep-0249/ PEP 249])。 + +只要是涉及到数据库操作,标准库和大部分第三方库都会遵循该规范(请看如下几个模块的示例代码)。 + +== 6.1 数据库中间件 == + +=== 6.1.1 ODBC === + +

pyODBC

+ +Home:[https://github.com/mkleehammer/pyodbc] + +pyODBC 封装了 ODBC API,通过它可以访问各种数据库(只要有 ODBC 驱动即可)。 + +代码示例——查询某个 ODBC 数据源的某个表 + +import pyodbc + +conn = pyodbc.connect("DSN=xxx;PWD=password") +cursor = conn.cursor() +cursor.execute("SELECT field1 FROM table1") + +while True : + row = cursor.fetchone() + if not row : + break + print(row) + +cursor.close() +conn.close() + + +

ceODBC

+ +Home:[http://ceodbc.sourceforge.net/] + +又一个封装 ODBC API 的第三方库 + +=== 6.1.2 JDBC === + +

Jython

+ +Jython 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/Jdbc JDBC] 操作数据库。 + +=== 6.1.3 ADO & ADO.NET === + +

PyWin32

+ +PyWin32 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/ActiveX_Data_Objects ADO] 操作数据库。 + +

IronPython

+ +IronPython 前面已经介绍过。有了它,你可以基于 [https://en.wikipedia.org/wiki/ADO.NET ADO.NET] 操作数据库。 + +== 6.2 特定数据库 == + +=== 6.2.1 MySQL === + +

MySQL for Python

+ +Home:[http://mysql-python.sourceforge.net/] + +操作 MySQL 的第三方库。 + +代码示例——查询某个 MySQL 数据库的某个表 + +import MySQLdb + +conn = MySQLdb.connect(db="test", passwd="password") +cursor = conn.cursor() +cursor.execute("SELECT field1 FROM table1") + +while True : + row = cursor.fetchone() + if not row : + break + print(row) + +cursor.close() +conn.close() + + +=== 6.2.2 PostgreSQL === + +

psycopg

+ +Home:[http://initd.org/psycopg/] + +操作 PostgreSQL 的第三方库。 + +

PyGreSQL

+ +Home:[http://www.pygresql.org/] + +操作 PostgreSQL 的第三方库。 + +=== 6.2.3 Oracle === + +

cx_Oracle

+ +Home:[http://cx-oracle.sourceforge.net/] + +操作 Oracle 的第三方库。 + +=== 6.2.4 MS SQL Server === + +

pymssql

+ +Home:[http://pymssql.org/] + +操作微软 SQL Server 的第三方库。 + +=== 6.2.5 IBM DB2 === + +

ibm-db

+ +Home:[https://pypi.python.org/pypi/ibm_db] + +操作 DB2 的第三方库。 + +=== 6.2.6 SQLite === + +

sqlite3

+ +sqlite3 从 Python 2.5 版本开始加入到标准库中。通过它,你可以很方便地操作 SQLite 数据库。 + +[https://en.wikipedia.org/wiki/SQLite SQLite] 是一个很优秀的轻量级数据库,俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/04/how-to-use-sqlite.html 这里]”)。 + +代码示例——创建一个内存数据库,建表并插入记录 + +import sqlite3 +conn = sqlite3.connect(":memory:") # ":memory:" 表示这是一个内存数据库 +cursor = conn.cursor() +cursor.execute("CREATE TABLE person (name text, age int)") +cursor.execute("INSERT INTO stocks VALUES ('TOM',20)") +conn.commit() +conn.close() + + +=== 6.2.7 Berkeley DB === + +

PyBSDDB

+ +Home:[http://www.jcea.es/programacion/pybsddb.htm] + +操作 Berkeley DB 的第三方库。 + +== 6.3 ORM(Object-Relational Mapping) == + +

SQLAlchemy

+ +Home:[http://www.sqlalchemy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/SQLAlchemy 英文]、[https://zh.wikipedia.org/wiki/SQLAlchemy 中文] + +SQLAlchemy 支持的数据库有:MySQL、PostgreSQL、Sqlite、Oracle、MS SQL Server、Firebird、Sybase SQL Server、Informix、等。 + +代码示例——通过对象的方式创建两张依赖关系的表 + +from sqlalchemy import * +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import relation, sessionmaker + +Base = declarative_base() + +class Movie(Base) : + __tablename__ = "movies" + + id = Column(Integer, primary_key=True) + title = Column(String(255), nullable=False) + year = Column(Integer) + directed_by = Column(Integer, ForeignKey("directors.id")) + director = relation("Director", backref="movies", lazy=False) + + def __init__(self, title=None, year=None) : + self.title = title + self.year = year + + def __repr__(self) : + return "Movie(%r, %r, %r)" % (self.title, self.year, self.director) + +class Director(Base) : + __tablename__ = "directors" + + id = Column(Integer, primary_key=True) + name = Column(String(50), nullable=False, unique=True) + + def __init__(self, name=None) : + self.name = name + + def __repr__(self) : + return "Director(%r)" % (self.name) + +Base.metadata.create_all(create_engine("dbms://user:pwd@host/dbname")) + + +

SQLObject

+ +Home:[http://sqlobject.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/SQLObject 英文] + +SQLObject 支持的数据库有:MySQL、PostgreSQL、Sqlite、MS SQL Server、Firebird、Sybase SQL Server、SAP DB、等。 + +代码示例——通过对象的方式创建表 + +from sqlobject import * +sqlhub.processConnection = connectionForURI("sqlite:/:memory:") + +class Person(SQLObject) : + first_name = StringCol() + last_name = StringCol() + +Person.createTable() + + +---- + += 7 GUI 开发 = + +== 7.1 GUI 框架 == + +=== 7.1.1 基于 Tk === + +[https://en.wikipedia.org/wiki/Tk_(framework) Tk] 是一个跨平台的界面组件库。 + +

Tkinter & tkinter

+ +这是 Python 内置的标准库,封装了 Tcl/Tk 界面库。 + +Python2 的模块名叫 Tkinter,到 Python3 模块名改为 tkinter + +代码示例——用 Tkinter 写 Hello world + +from Tkinter import * + +if __name__ == "__main__" : + root = Tk() + label = Label(root, text="Hello, world") + label.pack() + root.mainloop() + + +=== 7.1.2 基于 wxWidgets === + +[https://en.wikipedia.org/wiki/WxWidgets wxWidgets] 是 C++ 开发的跨平台框架(不仅包括 GUI,还有其它功能)。 +

wxPython

+ +Home:[http://www.wxpython.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/WxPython 英文]、[https://zh.wikipedia.org/wiki/WxPython 中文] + +在所有的 wxWidgets 的 Python 封装库中,这个是名气最大的。 + +[https://github.com/limodou/ulipad Ulipad](知名的国产的 Python IDE)就是基于 wxPython 开发的。 + +代码示例——用 wxPython 写 Hello world + +import wx + +class Frame(wx.Frame) : + pass + +class App(wx.App) : + def OnInit(self) : + self.frame = Frame(parent=None, title="Hello, world") + self.frame.Show() + self.SetTopWindow(self.frame) + return True + +if __name__ == "__main__" : + app = App() + app.MainLoop() + + +

PythonCard

+ +Home:[http://pythoncard.sourceforge.net/] + +又一个基于 wxWidgets 的 GUI 库。 + +=== 7.1.3 基于 GTK+ === + +[https://en.wikipedia.org/wiki/GTK%2B GTK+] 全称是(GIMP Toolkit),由 C 开发的跨平台界面组件库。 +

PyGTK

+ +Home:[http://www.pygtk.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/PyGTK 英文] + +它是 Python 对 GTK+2 的封装。 + +代码示例——用 PyGTK 写 Hello world + +import pygtk +pygtk.require("2.0") +import gtk + +class HelloWorld : + def __init__(self) : + self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) + self.window.connect("delete_event", self.delete_event) + self.window.connect("destroy", self.destroy) + self.window.set_border_width(10) + + self.button = gtk.Button("Hello, world") + self.button.connect("clicked", self.hello, None) + self.button.connect_object("clicked", gtk.Widget.destroy, self.window) + self.window.add(self.button) + + self.button.show() + self.window.show() + + def main(self) : + gtk.main() + + def hello(self, widget, data=None) : + print("Hello, world") + + def delete_event(self, widget, event, data=None) : + print("delete event occurred") + return False + + def destroy(self, widget, data=None) : + gtk.main_quit() + +if __name__ == "__main__" : + hello = HelloWorld() + hello.main() + + +

PyGObject(PyGI)

+ +Home:[https://live.gnome.org/PyGObject] + +它是 Python 对 GTK+3 的封装。PyGTK 的官网也推荐它。 + +代码示例——用 PyGObject 写 Hello world + +from gi.repository import Gtk + +class MyWindow(Gtk.Window): + def __init__(self): + Gtk.Window.__init__(self, title="Hello World") + + self.button = Gtk.Button(label="Click Here") + self.button.connect("clicked", self.on_button_clicked) + self.add(self.button) + + def on_button_clicked(self, widget): + print("Hello, world!") + +win = MyWindow() +win.connect("delete-event", Gtk.main_quit) +win.show_all() +Gtk.main() + + +=== 7.1.4 基于 Qt === + +[https://en.wikipedia.org/wiki/Qt_(toolkit) Qt] 是 C++ 开发的跨平台框架(不仅包括 GUI,还有其它功能)。 + +

PyQt

+ +Home:[http://www.riverbankcomputing.com/software/pyqt/] + +Wikipedia:[https://en.wikipedia.org/wiki/PyQt 英文]、[https://zh.wikipedia.org/wiki/PyQt 中文] + +这是 Python 对 Qt 的封装。 + +代码示例——用 pyQt 写 Hello world + +import sys +from PyQt4.QtGui import * + +if __name__ == "__main__" : + app = QApplication(sys.argv) + window = QWidget() + + window.resize(320, 240) + window.setWindowTitle("Hello, world") + window.show() + sys.exit(app.exec_()) + + +

PySide

+ +Home:[http://www.pyside.org/] + +这也是 Python 对 Qt 的封装。 + +=== 7.1.5 基于 FLTK === + +[https://en.wikipedia.org/wiki/FLTK FLTK] 全称是(Fast Light Tool Kit),由 C++ 开发的跨平台、轻量级界面组件库。 +

PyFLTK

+ +Home:[http://pyfltk.sourceforge.net/] + +这是 Python 对 FLTK 的封装。 + +=== 7.1.6 基于 Windows 平台 === + +

PyWin32

+ +PyWin32 前面已经介绍过。它可以提供原生的 Windows GUI 界面。 + +

IronPython

+ +IronPython 前面已经介绍过。它可以提供 dotNET 的 GUI 界面。 + +=== 7.1.7 基于 JVM 平台 === + +

Jython

+ +Jython 前面已经介绍过。它可以提供基于 Java 的 [https://en.wikipedia.org/wiki/Swing_%28Java%29 Swing] 界面。 + +=== 7.1.8 (其它) === + +

EasyGUI

+ +Home:[http://easygui.sourceforge.net/] + +EasyGUI 这是一个很轻量级的库。跟其它 GUI 不同之处在于——它没有“事件驱动”。 + +

PyGUI

+ +Home:[http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/] + +PyGUI 是一个更高层的 GUI 库,底层分别封装了 [http://python.net/crew/mhammond/win32/ PyWin32](Windows 平台)、[http://www.pygtk.org/ PyGTK](Linux 平台)、[http://pyobjc.sourceforge.net/ PyObjC](Mac OS X 平台)。 + +

Kivy

+ +Home:[http://kivy.org/] + +跨平台的多媒体框架和界面库,用来开发比较炫的界面。 + +除了支持桌面操作系统,还支持 Android / iOS,支持多点触摸。 + +

OcempGUI

+ +Home:[http://ocemp.sourceforge.net/gui.html] + +基于 PyGame 的一个跨平台 GUI 库(PyGame 下面会提到)。 + +== 7.2 图表 & 报表 == + +

matplotlib

+ +Home:[http://matplotlib.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Matplotlib 英文] + +这是一个有名的图形库,主要用来绘制数学相关的图形。 + +它跟后面提到的 [http://www.scipy.org/ SciPy] 整合可以起到类似 MATLAB 的效果。效果图在“[http://matplotlib.org/users/screenshots.html 这里]”。 + +

Gnuplot.py

+ +Home:[http://gnuplot-py.sourceforge.net/] + +这是 Python 对 [http://www.gnuplot.info/ gnuplot] 的封装。gnuplot 的效果图在“[http://www.gnuplot.info/screenshots/index.html 这里]”。 + +

PyQtGraph

+ +Home:[http://www.pyqtgraph.org/] + +这是一个纯 Python 的库,依赖于 PyQt4 / PySide。效果图在“[http://www.pyqtgraph.org/images/plotting_sm.png 这里]”。 + +

PyX

+ +Home:[http://pyx.sourceforge.net/] + +这个库可以跟 TeX / LaTeX 无缝整合,支持导出为 PostScript / PDF 格式。适合用来制作报表。效果图在“[http://pyx.sourceforge.net/gallery/index.html 这里]”。 + +

Chaco

+ +Home:[http://code.enthought.com/chaco/] + +这是一个商业公司维护的库,主要提供2维图表。效果图在“[http://docs.enthought.com/chaco/user_manual/annotated_examples.html 这里]”。 + +---- + += 8 信息安全 = + +== 8.1 密码学 == + +

hashlib

+ +在 Python 2.5 版本加入到标准库中。通过它,你可以很方便地计算各种散列值。 + +它支持的哈希算法有:MD5 SHA1 SHA224 SHA256 SHA384 SHA512 + +关于散列算法,俺写过一篇扫盲(在“[http://program-think.blogspot.com/2013/02/file-integrity-check.html 这里]”)。 + +代码示例——计算字符串的 SHA1 散列值 + +import hashlib +sha1 = hashlib.sha1("Hello, world").hexdigest() + + +

PyCrypto

+ +Home:[http://www.dlitz.net/software/pycrypto/] + +这个库包含了常见的对称加密算法(DES、AES、IDEA 等)、公钥加密算法(RSA、DSA 等)、散列算法(MD5、SHA1、RIPEMD 等)。 + +

pyOpenSSL

+ +Home:[http://pyopenssl.sourceforge.net/] + +[https://en.wikipedia.org/wiki/OpenSSL OpenSSL] 在加密领域可是大名鼎鼎。这个库使用 Python 对 OpenSSL 进行很薄的封装。 + +---- + += 9 处理文件格式 = + +== 9.1 结构化数据格式 == + +=== 9.1.1 CSV === + +[https://en.wikipedia.org/wiki/Comma-separated_values CSV] 是一种历史悠久的结构化数据存储格式。其效果类似于一张数据库二维表。 +

csv

+ +标准库,提供 CSV 格式文件的读写。 + +=== 9.1.2 JSON === + +JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。 +

json

+ +标准库,提供 JSON 格式的编码和解码。 + +代码示例——编码/解码 JSON 字符串 + +import json + +json.dumps(["foo", {"bar": ("baz", None, 1.0, 2)}]) +# JSON 编码 +# 得到如下【字符串】 +# """["foo", {"bar": ["baz", null, 1.0, 2]}]""" + +json.loads("""["foo", {"bar":["baz", null, 1.0, 2]}]""") +# JSON 解码 +# 得到如下【对象】 +# [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] + + +=== 9.1.3 YAML === + +[https://en.wikipedia.org/wiki/YAML YAML] 是一种类似于 json 的结构化数据格式。它在确保可读性的基础上,提供了超越 json 的灵活性和扩展性。 +

PyYAML

+ +Home:[http://pyyaml.org/] + +pyyaml 提供了 Python 对 YAML 的封装。 + +== 9.2 压缩文件 & 打包文件 == + +=== 9.2.1 zip === + +

zipfile

+ +处理 zip 格式的标准库。 + +=== 9.2.2 bzip2(bz2) === + +

bz2

+ +处理 bzip2 格式的标准库。 + +=== 9.2.3 gzip(gz) === + +

gzip

+ +处理 gzip 格式的标准库。 + +

zlib

+ +处理 gzip 格式的标准库。 + +=== 9.2.4 tar === + +

tarfile

+ +处理 tar 格式的标准库。 + +=== 9.2.5 7zip(7z) === + +

PyLZMA

+ +Home:[http://www.joachim-bauch.de/projects/pylzma/] + +处理 7zip 格式的第三方库。 + +=== 9.2.6 rar === + +

rarfile

+ +Home:[http://rarfile.berlios.de/] + +处理 rar 格式的第三方库。 + +=== 9.2.7 msi === + +

msilib

+ +处理 msi 格式的标准库,从 Python 2.5 版本开始提供。 + +== 9.3 标记语言 == + +=== 9.3.1 XML === + +

xml.dom & xml.miniDom & xml.etree.ElementTree

+ +用 DOM(Document Object Model)方式处理 XML 文件的标准库。 + +

xml.sax & xml.parsers.expat

+ +用 SAX(Simple API for XML)方式处理 XML 文件的标准库。 + +

lxml

+ +Home:[http://lxml.de/] + +著名的 C 语言库 libxml 和 libxslt 的 Python 封装。 + +功能很强,支持 XPath 1.0、XSLT 1.0、扩展 EXSLT、等。还可以用来解析 HTML 格式。 + +=== 9.3.2 HTML === + +

HTMLParser

+ +以回调方式解析 HTML/XHTML 文件内容的标准库。 + +== 9.4 PDF == + +

pyfpdf

+ +Home:[https://github.com/reingart/pyfpdf] + +这是 [http://www.fpdf.org/ FPDF] 的 Python 移植库,用来生成 PDF 文档。 + +支持的功能比较全(嵌入字体、嵌入图片),文档也比较详细。 + +代码示例——简单的 Hello World 示例 + +from fpdf import FPDF + +pdf = FPDF() +pdf.add_page() +pdf.set_font("Arial", "B", 16) +pdf.cell(40, 10, "Hello, World") +pdf.output("test.pdf", "F") + + +代码示例——支持写入 HTML 语法(目前支持几种常见的 HTML tag) + +from pyfpdf import FPDF, HTMLMixin + +class MyFPDF(FPDF, HTMLMixin) : + pass + +pdf = MyFPDF() +pdf.add_page() +pdf.write_html(html) +pdf.output("test.pdf", "F") + + +

pyPdf & PyPDF2

+ +Home:[http://knowah.github.com/PyPDF2/] + +pyPdf 目前已经不继续升级维护了。PyPDF2 是从 pyPdf 派生出来的,并继续增加新功能。 + +它除了可以提取文件属性,还可以切分/合并文档,加密/解密文档。 + +

PDFMiner

+ +Home:[http://www.unixuser.org/~euske/python/pdfminer/] + +它可以提取 PDF 文件属性以及每页的文本,支持把内容输出为 HTML 格式。 + +== 9.5 MS Office 文档 == + +=== 9.5.1 Word(doc、docx) === + +

PyWin32

+ +PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 + +=== 9.5.2 Excel(xls、xlsx) === + +

pyExcelerator

+ +Home:[http://sourceforge.net/projects/pyexcelerator/] + +它可以支持 Office Excel(97/2000/XP/2003)以及 OpenOffice Calc 的文档。无需依赖外部软件。 + +

PyWin32

+ +PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 + +=== 9.5.3 Power Point(ppt、pptx) === + +

python-pptx

+ +Home:[https://github.com/scanny/python-pptx] + +它可以用来生成 pptx(Open XML PowerPoint)格式的文档。 + +

PyWin32

+ +PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 + +== 9.6 RTF == + +

PyRTF

+ +Home:[http://pyrtf.sourceforge.net/] + +它可以用来处理 RTF(富文本格式)文档。 + +== 9.7 CHM == + +

PyCHM

+ +Home:[http://gnochm.sourceforge.net/pychm.html] + +这是基于 [http://www.jedrea.com/chmlib/ chmlib] 的 Python 封装库。可以提取 CHM 文件的属性以及每个页面的内容。 + +---- + += 10 图像 = + +== 10.1 图像处理 == + +

Python Imaging Library(PIL)

+ +Home:[http://www.pythonware.com/products/pil/] + +Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] + +这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG ...)。 + +它可以对图像进行各种常见的处理(旋转、缩放、剪切 ...)。 + +代码示例——为某个目录下所有 JPEG 创建缩略图 + +import os, glob +from PIL import Image + +size = 128, 128 +for file in glob.glob("*.jpg"): + name, ext = os.path.splitext(file) + img = Image.open(file) + img.thumbnail(size) + img.save(name+".thumbnail", "JPEG") + + +代码示例——旋转某图片并显示 + +from PIL import Image + +img = Image.open("xxx.jpg") +img = img.rotate(90) +img.show() + + +

Wand

+ +Home:[http://docs.wand-py.org/] + +它通过前面提到 ctypes 实现了对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装(ImageMagick 是最强大的开源图片处理工具集)。 + +代码示例——旋转并缩放某图片 + +from wand.image import Image +from wand.display import display + +with Image(filename="mona-lisa.png") as img : + print(img.size) + for r in 1, 2, 3 : + with img.clone() as new_img : + new_img.resize(int(new_img.width/2), int(new_img.height/2)) + new_img.rotate(90 * r) + new_img.save(filename="mona-lisa-{0}.png".format(r)) + display(new_img) + + +== 10.2 图像格式转换 == + +

Python Imaging Library(PIL)

+ +PIL 前面已经介绍过。它支持常见图像文件格式(BMP、JPG、GIF、PNG ...)之间的相互转换。 + +

Wand

+ +Wand 前面已经介绍过。由于它是针对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装。只要 ImageMagick 能转换的格式,它也可以转换。 + += 11 游戏开发 = + +

PyGame

+ +Home:[http://www.pygame.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Pygame 英文]、[https://zh.wikipedia.org/wiki/Pygame 中文] + +跨平台的 Python 第三方库,用来辅助游戏开发的,名气非常大。 + +

PyOpenGL

+ +Home:[http://pyopengl.sourceforge.net/] + +封装 [https://en.wikipedia.org/wiki/OpenGL OpenGL] 的 Python 第三方库。 + +

Python-Ogre

+ +Home:[http://www.python-ogre.org/] + +封装 [https://en.wikipedia.org/wiki/OGRE OGRE](3D 渲染引擎)的 Python 第三方库。 + +---- + += 12 数值计算 & 科学计算 = + +

NumPy

+ +Home:[http://www.numpy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/NumPy 英文]、[https://zh.wikipedia.org/wiki/NumPy 中文] + +它提供了功能强大、性能很高的数值数组,可以用来进行各种数值计算(包括矩阵运算)。 + +代码示例 + +# 以下是传统 Python 写法,冗长且速度较慢 +a = range(10000000) +b = range(10000000) +c = [] +for i in range(len(a)) : + c.append(a[i] + b[i]) + +# 以下是 NumPy 的写法,简洁且速度飞快 +import numpy as np +a = np.arange(10000000) +b = np.arange(10000000) +c = a + b + + +

SciPy

+ +Home:[http://www.scipy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/SciPy 英文]、[https://zh.wikipedia.org/wiki/SciPy 中文] + +它依赖 NumPy 提供的多维数组。相比 NumPy,它提供了更高层的数学运算模块(统计、线性代数、积分、常微分方程求解、傅立叶变换、信号处理 ...)。 + +它被广泛用于科研和工程领域。 + +

SymPy

+ +Home:[http://sympy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia.org/wiki/SymPy 中文] + +它是用来做符号计算的,其目标是成为一个全功能的“计算机代数系统”。 + +它支持的功能包括:符号计算、高精度计算、模式匹配、绘图、解方程、微积分、组合数学、离散数学、几何学、概率与统计 ...... + +---- + += 13 其它 = + +一些不方便归类的,暂时放到这里。 + +

PyPy

+ +Home:[http://www.pypy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/PyPy 英文]、[https://zh.wikipedia.org/wiki/PyPy 中文] + +它是一个用 Python 写的 Python 解释器(有点绕口令)。 + +PyPy 支持 JIT(Just-in-time compilation)和沙箱技术,可做到【比 CPython 更快的运行速度】。 + From 31ec1ea1e27c8a0c59ada12959cb2e0d31eb604c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 4 Jul 2015 00:18:40 +0800 Subject: [PATCH 013/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Pycairo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 3cde56d..90238e1 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1350,6 +1350,16 @@ PIL 前面已经介绍过。它支持常见图像文件格式(BMP、JPG、GIF Wand 前面已经介绍过。由于它是针对 [https://en.wikipedia.org/wiki/ImageMagick ImageMagick] 的封装。只要 ImageMagick 能转换的格式,它也可以转换。 +== 10.3 图像渲染 == + +

Pycairo

+ +Home:[http://cairographics.org/pycairo/] + +[https://en.wikipedia.org/wiki/Cairo_%28graphics%29 Cairo] 是一个图像渲染引擎,提供了矢量图像的渲染功能。支持多种后端输出(包括:Win32 GDI、OpenGL、Xlib、XCB、PDF、PNG、SVG......)。 + +Pycairo 是 Cairo 官方提供 Python 封装。 + = 11 游戏开发 =

PyGame

From 155ddf76f15d68673d6c794fdd6c764b281e71fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 4 Jul 2015 00:41:51 +0800 Subject: [PATCH 014/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E5=BC=80=E5=8F=91=E2=80=9D=E7=9A=84=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=B1=82=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 90238e1..14c9e7b 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1362,25 +1362,31 @@ Pycairo 是 Cairo 官方提供 Python 封装。 = 11 游戏开发 = +== 11.1 综合性的游戏引擎 == +

PyGame

Home:[http://www.pygame.org/] Wikipedia:[https://en.wikipedia.org/wiki/Pygame 英文]、[https://zh.wikipedia.org/wiki/Pygame 中文] -跨平台的 Python 第三方库,用来辅助游戏开发的,名气非常大。 +这是名气很大的跨平台游戏引擎,构建于 SDL(Simple DirectMedia Layer)之上。 + +它起先是用来替代终止开发的 pySDL,包含了图像和音频的库。 + +== 11.2 3D 渲染引擎 ==

PyOpenGL

Home:[http://pyopengl.sourceforge.net/] -封装 [https://en.wikipedia.org/wiki/OpenGL OpenGL] 的 Python 第三方库。 +封装 [https://en.wikipedia.org/wiki/OpenGL OpenGL] 的 Python 库。

Python-Ogre

Home:[http://www.python-ogre.org/] -封装 [https://en.wikipedia.org/wiki/OGRE OGRE](3D 渲染引擎)的 Python 第三方库。 +封装 [https://en.wikipedia.org/wiki/OGRE OGRE] 的 Python 库。 ---- From 77589933cf8212c692d1fb6a01aab943f4543ebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 4 Jul 2015 00:59:34 +0800 Subject: [PATCH 015/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Cocos2d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 14c9e7b..70d63ed 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1370,10 +1370,18 @@ Home:[http://www.pygame.org/] Wikipedia:[https://en.wikipedia.org/wiki/Pygame 英文]、[https://zh.wikipedia.org/wiki/Pygame 中文] -这是名气很大的跨平台游戏引擎,构建于 SDL(Simple DirectMedia Layer)之上。 +这是名气很大的跨平台游戏引擎,构建于 [https://zh.wikipedia.org/wiki/SDL SDL](Simple DirectMedia Layer)之上。 它起先是用来替代终止开发的 pySDL,包含了图像和音频的库。 +

Cocos2d

+ +Home:[http://cocos2d.org/] + +它是一个开源的 2D 游戏框架,最初使用 Python 编写的。后来该框架已经被移植到了多种语言和平台上。 + +很多手机游戏是基于 Cocos2d 的衍生框架开发的。 + == 11.2 3D 渲染引擎 ==

PyOpenGL

From 0a7e8506778546ecd84154b9b9f40e98bba5a484 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 4 Jul 2015 01:23:38 +0800 Subject: [PATCH 016/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Blender=20Game=20E?= =?UTF-8?q?ngine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 70d63ed..554b05a 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1380,8 +1380,20 @@ Home:[http://cocos2d.org/] 它是一个开源的 2D 游戏框架,最初使用 Python 编写的。后来该框架已经被移植到了多种语言和平台上。 +其功能包括了:GUI 组件、音效、物理引擎、脚本语言绑定、场景编辑器 ... + 很多手机游戏是基于 Cocos2d 的衍生框架开发的。 +

Blender Game Engine

+ +Home:[http://www.blender.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Game_Blender 英文]、[https://zh.wikipedia.org/wiki/Game_Blender 中文] + +它是 [https://en.wikipedia.org/wiki/Blender_%28software%29 Blender] 的组成部分,虽然是以 C++ 编写,但内置了 Python 脚本的扩展。 + +其功能包括:3D 渲染、碰撞检测、角色编辑器、音效、网络通讯、AI ... + == 11.2 3D 渲染引擎 ==

PyOpenGL

From 8efb05802369ab56c7dad00e4d879a08cbd1ec78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sun, 5 Jul 2015 17:04:37 +0800 Subject: [PATCH 017/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20libev?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index ce26f07..b21f641 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1347,6 +1347,42 @@ Wikipedia:[https://en.wikipedia.org/wiki/Libevent 英文]、[https://zh.wikipe 它被一些知名的开源项目使用(比如:[https://zh.wikipedia.org/wiki/Tor Tor]、[https://zh.wikipedia.org/wiki/Memcached memcached])。 +代码示例——HTTP Server(本示例基于 ANSI C) + +#include +#include +#include +#include + +#include +#include + +void generic_request_handler(struct evhttp_request* req, void* arg) +{ + struct evbuffer* return_buffer = evbuffer_new(); + + evbuffer_add_printf(return_buffer, "Thanks for the request!"); + evhttp_send_reply(req, HTTP_OK, "Client", return_buffer); + evbuffer_free(return_buffer); +} + +int main(int argc, char** argv) +{ + short http_port = 8080; + char* http_addr = "127.0.0.1"; + struct evhttp* http_server = NULL; + + event_init(); + http_server = evhttp_start(http_addr, http_port); + evhttp_set_gencb(http_server, generic_request_handler, NULL); + + fprintf(stderr, "Server started on port %d\n", http_port); + event_dispatch(); + + return 0; +} + + 代码示例——HTTP Server(本示例基于 C++ 11 标准) #include @@ -1362,7 +1398,7 @@ int main() return -1; } char const SrvAddress[] = "127.0.0.1"; - std::uint16_t SrvPort = 5555; + std::uint16_t SrvPort = 8080; std::unique_ptr Server(evhttp_start(SrvAddress, SrvPort), &evhttp_free); if(!Server) { @@ -1391,6 +1427,14 @@ int main() } +

libev

+ +Home:[http://libev.schmorp.de/] + +看名称就能猜到它跟 libevent 很像。实际上,你可以把 libev 视为 libevent 的竞争性替代品。 + +[http://www.gevent.org/ gevent] 官方博客的[http://blog.gevent.org/2011/04/28/libev-and-libevent/ 一篇文章]对比了这俩库的优缺点。 + ---- = 8 数据库 = From 6642599c25f76040cdb4fc1c845b48852b8f8d23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sun, 5 Jul 2015 17:17:23 +0800 Subject: [PATCH 018/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20gevent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 554b05a..cd37244 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -519,7 +519,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] (在这个方面,它有点类似于 Google 的 Protocol Buffers) -== 5.3 网络开发框架 == +== 5.3 网络库、框架、中间件 ==

Twisted

@@ -547,6 +547,14 @@ reactor.listenTCP(12345, EchoFactory()) reactor.run() +

gevent

+ +Home:[http://www.gevent.org/] + +这是一个基于[https://zh.wikipedia.org/wiki/%E5%8D%8F%E7%A8%8B 协程]的网络库,原先其底层依赖于 libevent,后来改为 libev。 + +很多开源项目用到了 gevent,具体参见 [https://github.com/gevent/gevent/wiki/Projects gevent 官方的 wiki]。 + ---- = 6 数据库 = From 61e16a20f7d8d1d5da6248c93fee3995d3eb1ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sun, 5 Jul 2015 23:18:45 +0800 Subject: [PATCH 019/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8B=A5=E5=B9=B2?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 64 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 7 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index cd37244..e32ece9 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -104,17 +104,21 @@ Python 可以很容易地跟其它编程语言整合。整合之后,就可以 ctypes 在 Python 2.5 版本加入到标准库中。 -通过它,你可以很方便地调用 C/C++ 动态库导出的函数,可以在 Python 中使用各种 C/C++ 的数据类型(比如指针)。 +通过它,你可以很方便地调用 C/C++ 动态库导出的函数,可以在 Python 中使用各种 C/C++ 的数据类型(包括“指针”和“引用”)。 代码示例——调用 Linux/Unix 系统的标准 C 函数,获取当前时间 from ctypes import * + libc = CDLL("libc.so.6") time = libc.time(None) + -# 调用 Windows 系统 API,弹出消息提示框 +代码示例——调用 Windows 系统的 API,弹出消息提示框 + from ctypes import c_int, WINFUNCTYPE, windll from ctypes.wintypes import HWND, LPCSTR, UINT + prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT) paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0) MessageBox = prototype(("MessageBoxA", windll.user32), paramflags) @@ -127,7 +131,7 @@ Home:[http://swig.org/] Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] -这是一个很老牌的、有名气的工具,它可以把多种语言(Java、Python、C#、Ruby、PHP、Perl、Lua、Go、等)整合到 C/C++ 中。 +这是一个很老牌的、有名气的工具,它可以把多种语言(Java、Python、C#、Ruby、PHP、Perl、Lua、Go ...)整合到 C/C++ 中。

Cython

@@ -223,6 +227,13 @@ for file in os.listdir(".") : 其中 multiprocessing 是 2.6 版本加入到标准库的。 +代码示例——启动命令行进程,并获取该进程的标准输出 + +import subprocess +output = subprocess.check_output(["dir"]) # 获取当前目录的内容 +output = subprocess.check_output(["netstat", "-an"]) # 获取当前网络链接 + +

signal

用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 @@ -240,7 +251,7 @@ map = mmap.mmap(-1, 13) map.write("Hello, world") pid = os.fork() -if pid == 0: # 子进程 +if pid == 0 : # 子进程 map.seek(0) print(map.readline()) map.close() @@ -461,6 +472,17 @@ Python 标准库很早就提供了对 socket 编程的支持。 封装 FTP 协议(文件传输)的标准库 +代码示例——列出 FTP 服务器上某目录的内容 + +from ftplib import FTP + +ftp = FTP("ftp.debian.org") # 连接服务器(如果不指定端口号,则用默认端口号 21) +ftp.login() # 登录(如果不指定用户名和密码,则用匿名登录) +ftp.cwd("debian") # 切换到 "debian" 目录 +ftp.retrlines("LIST") # 列出当前目录的内容 +ftp.quit() + +

smtplib

封装 SMTP 协议(邮件发送)的标准库 @@ -477,9 +499,26 @@ Python 标准库很早就提供了对 socket 编程的支持。 Home:[http://pycurl.sourceforge.net/] -[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。pycurl 提供了 Python 的封装。 +[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。俺在前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 + +看名称就能猜到——PycURL 是 cURL 的 Python 封装。 -关于 cURL,俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 +代码示例——发起 HTTP GET 请求 + +import pycurl +try : + from io import BytesIO +except ImportError : + from StringIO import StringIO as BytesIO + +buffer = BytesIO() +curl = pycurl.Curl() +curl.setopt(curl.URL, "http://pycurl.sourceforge.net/") +curl.setopt(curl.WRITEDATA, buffer) +curl.perform() +curl.close() +body = buffer.getvalue() +

jabber.py

@@ -529,7 +568,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Twisted_%28software%29 英文] 这是一个基于 Python 网络通讯开发框架,诞生于2002年,名气很大。 -它的某些设计类似于 C++ 的 [https://en.wikipedia.org/wiki/Adaptive_Communication_Environment ACE] 框架。除了能用来进行传输层(TCP UDP)的开发,还提供了若干应用层协议(HTTP、XMPP、SSH、IRC、等)的支持。 +它的某些设计类似于 C++ 的 [https://en.wikipedia.org/wiki/Adaptive_Communication_Environment ACE] 框架。除了能用来进行传输层(TCP UDP)的开发,还提供了若干应用层协议(HTTP、XMPP、SSH、IRC ...)的支持。 代码示例——实现一个简单的 Echo 服务,监听在 12345 端口 @@ -555,6 +594,17 @@ Home:[http://www.gevent.org/] 很多开源项目用到了 gevent,具体参见 [https://github.com/gevent/gevent/wiki/Projects gevent 官方的 wiki]。 +代码示例——并发执行网络请求 + +from gevent import socket +import gevent + +hosts = ["google.com", "github.com", "program-think.blogspot.com"] +jobs = [gevent.spawn(socket.gethostbyname, host) for host in hosts] +gevent.joinall(jobs, timeout=2) +print([job.value for job in jobs]) + + ---- = 6 数据库 = From 928c0760b2eb84f3c5dca607fa744e4388b486b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sun, 5 Jul 2015 23:50:12 +0800 Subject: [PATCH 020/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20c-ares?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index b21f641..99ee84f 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1210,7 +1210,15 @@ Home:[http://www.curlpp.org/] Docs:[http://pocoproject.org/docs/Poco.Net.html] -POCO 前面已经介绍过。它提供了几种常见应用层协议(HTTP、SMTP、POP3、FTP、NTP)的封装类。 +POCO 前面已经介绍过。它提供了几种常见应用层协议(HTTP、SMTP、POP3、FTP、NTP ...)的封装类。 + +

c-ares

+ +Home:[http://c-ares.haxx.se/] + +这是一个 C 语言开发的 DNS 封装库,支持异步 DNS 请求,跨多种操作系统。 + +对比官网域名可知,它跟 cURL 是一家子。除了 cURL/libcurl 用到它,还有一些知名开源项目(比如:Wireshark、node.js ...)用到它。 == 7.2 自定义协议 == From f7860bde85eb1211bcebf92990e07b0f9102fa2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 6 Jul 2015 00:38:17 +0800 Subject: [PATCH 021/116] =?UTF-8?q?=E8=A1=A5=E5=85=85=20POCO=20=E7=9A=84?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=9C=BA=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 99ee84f..8337ee3 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -444,6 +444,12 @@ Docs:[http://boost.org/libs/date_time] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了针对“日期 和 时间”的各种处理。 +

POCO

+ +Docs:[http://pocoproject.org/docs/Poco.html] + +POCO 前面已经介绍过。它提供了若干个日期和时间的封装类(时区转换、格式化字符串、解析时间字符串)。 + == 2.6 编码 & 解码 == === 2.6.1 序列化 === @@ -470,6 +476,12 @@ Docs:[http://www.cryptopp.com/docs/ref/annotated.html] Crypto++ 前面已经介绍过。它提供了6个类,分别用于 Base64、Base32、Base16 的编码/解码。 +

POCO

+ +Docs:[http://pocoproject.org/docs/Poco.html] + +POCO 前面已经介绍过。它提供了 Base64 和 Base32 的编码/解码。 + == 2.7 (其它) == === 2.7.1 随机数 === @@ -540,6 +552,12 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了 UUID 的生成、格式化成字符串、解析 UUID 字符串。 +

POCO

+ +Docs:[http://pocoproject.org/docs/Poco.UUIDGenerator.html] + +POCO 前面已经介绍过。它提供了 UUID 的生成。 + ---- = 3 编程范式 = @@ -754,11 +772,17 @@ int main(int argc, char* argv[]) } +

POCO

+ +Docs:[http://pocoproject.org/docs/Poco.html] + +POCO 前面已经介绍过。它提供了文件系统相关的封装类(遍历目录和文件、临时文件、文件变化通知...)。 +

wxWidgets

Docs:[http://docs.wxwidgets.org/trunk/group__group__class__file.html] -wxWidgets 前面已经介绍过。它提供了比较多这方面的功能(比如:监视文件系统变化、遍历目录、临时文件)。 +wxWidgets 前面已经介绍过。它提供了文件系统相关的封装类(遍历目录和文件、临时文件、文件变化通知...)。

APR

@@ -804,6 +828,12 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“线程池、线程同步/互斥”等功能,以及一些线程安全的数据结构。 +

POCO

+ +Docs:[http://pocoproject.org/docs/Poco.html] + +POCO 前面已经介绍过。它提供了线程、线程池以及线程同步/互斥的封装类。 +

wxWidgets

Docs:[http://docs.wxwidgets.org/trunk/group__group__class__threading.html] @@ -1339,12 +1369,6 @@ Wikipedia:[https://en.wikipedia.org/wiki/Internet_Communications_Engine 英文 它的设计借鉴了 CORBA,好在没有 CORBA 那么复杂。 -

Dlib

- -Docs:[http://dlib.net/network.html] - -Dlib 前面已经介绍过。它针对网络通讯,提供了比较高的抽象层。 -

libevent

Home:[http://libevent.org/] @@ -1443,6 +1467,12 @@ Home:[http://libev.schmorp.de/] [http://www.gevent.org/ gevent] 官方博客的[http://blog.gevent.org/2011/04/28/libev-and-libevent/ 一篇文章]对比了这俩库的优缺点。 +

Dlib

+ +Docs:[http://dlib.net/network.html] + +Dlib 前面已经介绍过。它针对网络通讯,提供了比较高的抽象层。 + ---- = 8 数据库 = From 0db60bf5ce69936f4159cab39a542eeac2424ac6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 6 Jul 2015 23:47:21 +0800 Subject: [PATCH 022/116] =?UTF-8?q?=E8=A1=A5=E5=85=85=20POCO=20=E7=9A=84?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=9C=BA=E5=90=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 62 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 12 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 8337ee3..c064a13 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -272,6 +272,12 @@ file.open("hello.txt"); file << L"שלום!"; +

POCO.Text

+ +Docs:[http://pocoproject.org/docs/package-Foundation.Text.html] + +POCO 前面已经介绍过。它提供了 UTF8/UTF16/UTF32 的转换。 + === 2.3.2 字符串格式化 ===

Boost.Format

@@ -355,6 +361,12 @@ Wikipedia:[https://en.wikipedia.org/wiki/Oniguruma 英文] 它被用在 Ruby、TextMate、Sublime Text、SubEthaEdit 等软件上。 +

POCO.RegExp

+ +Docs:[http://pocoproject.org/docs/package-Foundation.RegExp.html] + +POCO 前面已经介绍过。它提供了正则表达式的封装类。 +

Qt.QRegExp

Docs:[http://doc.qt.io/qt-4.8/qregexp.html] @@ -444,9 +456,9 @@ Docs:[http://boost.org/libs/date_time] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了针对“日期 和 时间”的各种处理。 -

POCO

+

POCO.DateTime

-Docs:[http://pocoproject.org/docs/Poco.html] +Docs:[http://pocoproject.org/docs/package-Foundation.DateTime.html] POCO 前面已经介绍过。它提供了若干个日期和时间的封装类(时区转换、格式化字符串、解析时间字符串)。 @@ -476,9 +488,9 @@ Docs:[http://www.cryptopp.com/docs/ref/annotated.html] Crypto++ 前面已经介绍过。它提供了6个类,分别用于 Base64、Base32、Base16 的编码/解码。 -

POCO

+

POCO.Streams

-Docs:[http://pocoproject.org/docs/Poco.html] +Docs:[http://pocoproject.org/docs/package-Foundation.Streams.html] POCO 前面已经介绍过。它提供了 Base64 和 Base32 的编码/解码。 @@ -552,11 +564,11 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了 UUID 的生成、格式化成字符串、解析 UUID 字符串。 -

POCO

+

POCO.UUID

-Docs:[http://pocoproject.org/docs/Poco.UUIDGenerator.html] +Docs:[http://pocoproject.org/docs/package-Foundation.UUID.html] -POCO 前面已经介绍过。它提供了 UUID 的生成。 +POCO 前面已经介绍过。它提供了 UUID 的生成、格式转换。 ---- @@ -659,6 +671,14 @@ BOOST_LOG_TRIVIAL(debug) << "A debug severity message"; BOOST_LOG_TRIVIAL(info) << "An informational severity message"; +

POCO.Logging

+ +Docs:[http://pocoproject.org/docs/package-Foundation.Logging.html] + +POCO 前面已经介绍过。它提供了好几个用于调试日志的封装类(包括特定于 Windows 平台和特定于 POSIX 平台的类)。 + +它还支持日志文件的循环存储。 +

Dlib

Docs:[http://dlib.net/other.html#logger] @@ -772,11 +792,11 @@ int main(int argc, char* argv[]) } -

POCO

+

POCO.Filesystem

-Docs:[http://pocoproject.org/docs/Poco.html] +Docs:[http://pocoproject.org/docs/package-Foundation.Filesystem.html] -POCO 前面已经介绍过。它提供了文件系统相关的封装类(遍历目录和文件、临时文件、文件变化通知...)。 +POCO 前面已经介绍过。它提供了文件系统相关的封装类(遍历目录和文件、通配符匹配、临时文件、文件变化通知...)。

wxWidgets

@@ -828,9 +848,9 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“线程池、线程同步/互斥”等功能,以及一些线程安全的数据结构。 -

POCO

+

POCO.Threading

-Docs:[http://pocoproject.org/docs/Poco.html] +Docs:[http://pocoproject.org/docs/package-Foundation.Threading.html] POCO 前面已经介绍过。它提供了线程、线程池以及线程同步/互斥的封装类。 @@ -860,6 +880,12 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“进程管理”的功能。 +

POCO.Processes

+ +Docs:[http://pocoproject.org/docs/Poco.Process.html] + +POCO 前面已经介绍过。它提供了“进程”的封装类。 + === 5.1.4 本地进程间通信(IPC) === (本章节列举的是【本地】IPC,跨主机的网络通讯,参见本页面后续的章节) @@ -882,6 +908,12 @@ Docs:[https://apr.apache.org/docs/apr/trunk/modules.html] APR 前面已经介绍过。它提供了“进程同步、共享内存、信号处理”等功能。 +

POCO.Processes

+ +Docs:[http://pocoproject.org/docs/package-Foundation.Processes.html] + +POCO 前面已经介绍过。它提供了 IPC 相关的封装类(“共享内存”和“管道”)。 + == 5.2 特定于 Windows 系统 == === 5.2.1 注册表 === @@ -2193,6 +2225,12 @@ Wikipedia:[https://en.wikipedia.org/wiki/Libzip 英文] 用 C 语言开发的库,基于 zlib 库。 +

Poco::Zip

+ +Docs:[http://pocoproject.org/docs/Poco.Zip.html] + +POCO 前面已经介绍过。它提供了若干封装类,用于 zip 格式的压缩和解压。 + === 11.2.3 bzip2(bz2) === [https://en.wikipedia.org/wiki/Bzip2 格式说明] From 97edd39dfb75f4ee10dc87b04b856fffcb77756a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 7 Jul 2015 00:05:10 +0800 Subject: [PATCH 023/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20web.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index e32ece9..28f992d 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -364,6 +364,33 @@ Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wiki 又一个重型的 Web 开发框架,名气仅次于 Django。 +

web.py

+ +Home:[http://webpy.org/] + +与前两个(Django、TurboGears)不同,这是一个轻量级的框架。甚至被称为“It's the anti-framework framework.” + +其作者是大名鼎鼎的黑客 [https://en.wikipedia.org/wiki/Aaron_Swartz Aaron Swartz]。(俺在[http://program-think.blogspot.nl/2013/01/weekly-share-37.html 某篇博文]中悼念过他)。 + +当年 Aaron Swartz 用 web.py 来搭建同样大名鼎鼎的网站 [https://en.wikipedia.org/wiki/Reddit reddit](该网站是 Web 2.0 的标杆)。 + +代码示例——Hello world + +import web + +urls = ( + "/", "index" +) + +class index: + def GET(self): + return "Hello, world!" + +if __name__ == "__main__" : + app = web.application(urls, globals()) + app.run() + + == 4.4 Web前端 & JS整合 ==

Pyjamas & pyjs

From 5442ac364e87a917e982d8040e45f8fbbc17d8d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 7 Jul 2015 00:26:04 +0800 Subject: [PATCH 024/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20CherryPy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 28f992d..9638901 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -364,6 +364,28 @@ Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wiki 又一个重型的 Web 开发框架,名气仅次于 Django。 +它跟 Django 一样,都是“Full-Stack Frameworks”。 + +

CherryPy

+ +Home:[http://www.cherrypy.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/CherryPy 英文] + +轻量级的 Web 框架。某些 Web 框架(比如前面提到的 TurboGears)使用它作为底层。 + +代码示例——Hello world + +import cherrypy + +class HelloWorld(object): + def index(self): + return "Hello World!" + index.exposed = True + +cherrypy.quickstart(HelloWorld()) + +

web.py

Home:[http://webpy.org/] From 05c79af79b286d2c03b532674763c767fe4687d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Fri, 10 Jul 2015 23:50:01 +0800 Subject: [PATCH 025/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Berkeley=20DB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index c064a13..b284cd5 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1533,7 +1533,7 @@ Home:[http://sqlite.org/] Wikipedia:[https://en.wikipedia.org/wiki/SQLite 英文]、[https://zh.wikipedia.org/wiki/SQLite 中文] -SQLite 是一个很优秀的文件型数据库,非常轻量级,支持各种作系统平台。采用 C 语言开发。 +它是一个很优秀的嵌入式(进程内)数据库,非常轻量级,支持各种作系统平台。采用 C 语言开发。 俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/04/how-to-use-sqlite.html 这里]”)。 @@ -1543,7 +1543,17 @@ Home:[https://www.mongodb.org/] Wikipedia:[https://en.wikipedia.org/wiki/MongoDB 英文] -MongoDB 是近几年兴起的 NoSQL 数据库的一员。它本身是基于 C++ 和 C 开发的。 +这是近几年兴起的 NoSQL 数据库的一员。它本身是基于 C++ 和 C 开发的。 + +

Berkeley DB(BDB)

+ +Home:[http://www.oracle.com/us/products/database/berkeley-db/] + +Wikipedia:[https://en.wikipedia.org/wiki/Berkeley_DB 英文]、[https://zh.wikipedia.org/wiki/Berkeley_DB 中文] + +诞生于1994年,是一个很老牌的嵌入式(进程内)数据库,基于 C 语言开发。开发 BDB 的公司于2006年被 Oracle 收购。 + +很多开源项目用到它。甚至 MySQL 也包含了一个基于 BDB 的存储后端。 == 8.2 数据库 API 的封装库 == From 0c135b3158dea7409863d96144b03311caca1c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 11 Jul 2015 00:04:12 +0800 Subject: [PATCH 026/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Firebird?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index b284cd5..c5b2ce4 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1555,6 +1555,18 @@ Wikipedia:[https://en.wikipedia.org/wiki/Berkeley_DB 英文]、[https://zh.wik 很多开源项目用到它。甚至 MySQL 也包含了一个基于 BDB 的存储后端。 +

Firebird

+ +Home:[http://www.firebirdsql.org/] + +Wikipedia:[https://en.wikipedia.org/wiki/Firebird_%28database_server%29 英文]、[https://zh.wikipedia.org/wiki/Firebird_(%E6%95%B0%E6%8D%AE%E5%BA%93) 中文] + +它是2000年的时候,从 [https://en.wikipedia.org/wiki/Borland Borland] 公司的 InterBase 数据库派生出来的。 + +基于 C++ 开发,支持多种操作系统平台。 + +关于它有个插曲:Firefox 浏览器曾经用过“Firebird”这个名称,因为跟 Firebird 数据库同名,后来才改用 Firefox 这个名称。 + == 8.2 数据库 API 的封装库 == === 8.2.1 综合性的封装库 === From 271649643665c3ef834d74ff99e2b8c452f9a78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 11 Jul 2015 00:21:54 +0800 Subject: [PATCH 027/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20difflib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 9638901..8f05114 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -46,6 +46,12 @@ print(chardet.detect(bytes)) cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现的,提供 Unicode 兼容性。 +

difflib

+ +可以对两个字符串进行“按行”比较,其功能类似于命令行的 diff。 + +另外还支持“最佳匹配”功能——对给定的字符串 s 和字符串列表 l,在 l 里面找到最接近 s 的字符串。 + == 1.2 编码 & 解码 == === 1.2.1 base64 === From 01e530d41e62aa4ced4b3f58eb6a7bbbc0f0fc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 11 Jul 2015 23:27:02 +0800 Subject: [PATCH 028/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=B3=BB=E7=BB=9F=E2=80=9D=E7=9A=84=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=B1=82=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 87 ++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 73 insertions(+), 14 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 8f05114..7182b76 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -225,13 +225,49 @@ for file in os.listdir(".") : -== 3.2 本地进程间通信(IPC) == +== 3.2 线程 == -

subprocess & multiprocessing

+

threading

-用于进程管理的标准库,可以启动子进程,通过标准输入输出跟子进程交互。 +这个模块提供了比较高层的线程封装 API。它本身包含了线程同步/互斥的机制。 + +代码示例——基于“函数”的线程 + +import threading +import time + +def my_thread() : + print("Thread started!") + time.sleep(3) + print("Thread finished!") + +threading.Thread(target=my_thread).start() + + +代码示例——基于“类”的线程 + +import threading +import time +from __future__ import print_function + +class MyThread(threading.Thread) : + def run(self) : + print("{} started!".format(self.getName())) + time.sleep(3) + print("{} finished!".format(self.getName())) + +if __name__ == "__main__" : + for n in range(10) : + mythread = MyThread(name = "Thread-{}".format(n + 1)) + mythread.start() + time.sleep(1) + + +== 3.3 进程 == -其中 multiprocessing 是 2.6 版本加入到标准库的。 +

subprocess

+ +用于进程管理的标准库,可以启动子进程,通过标准输入输出跟子进程交互。 代码示例——启动命令行进程,并获取该进程的标准输出 @@ -240,9 +276,28 @@ output = subprocess.check_output(["dir"]) # 获取当前目录的内容 output = subprocess.check_output(["netstat", "-an"]) # 获取当前网络链接 -

signal

+

multiprocessing

-用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 +它是 2.6 版本加入到标准库的,其 API 接口的风格类似于 threading 模块。 + +它本身包含了进程同步/互斥的机制。 + +代码示例——利用其 Lock 机制,确保多个子进程的标准输出不会混杂(每次只有一个进程调用 print)。 + +from multiprocessing import Process, Lock + +def f(lock, n) : + lock.acquire() + print("hello world %d" % n) + lock.release() + +if __name__ == "__main__" : + lock = Lock() + for num in range(10): + Process(target=f, args=(lock, num)).start() + + +== 3.4 本地进程间通信(IPC) ==

mmap

@@ -263,21 +318,25 @@ if pid == 0 : # 子进程 map.close() -== 3.3 Windows 系统相关 == - -

PyWin32

- -Home:[http://python.net/crew/mhammond/win32/] +

signal

-这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 +用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 -== 3.4 Linux & Unix 系统相关 == +== 3.5 Linux & Unix 系统相关 ==

syslog

通过这个标准库,可以很方便地跟 POSIX 的 syslog 服务进行交互。 -== 3.5 程序打包 == +== 3.6 Windows 系统相关 == + +

PyWin32

+ +Home:[http://python.net/crew/mhammond/win32/] + +这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 + +== 3.7 程序打包 ==

PyInstaller

From 2d069c2d2d341f76a5652ddde8b7abbc62ea05ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 15 Jul 2015 00:13:15 +0800 Subject: [PATCH 029/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20MySQL++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index c5b2ce4..6ad4e43 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1646,6 +1646,45 @@ delete conn; conn = NULL; +

MySQL++

+ +Home:[http://www.tangentsoft.net/mysql%2B%2B/] + +这是个老牌的库,诞生于1998年,提供了 MySQL API 的 C++ 封装。 + +代码示例——执行 SQL 语句 + +#include +#include + +void query(db_name, server_name, user, password) +{ + using namespace std; + + mysqlpp::Connection conn(false); + if(!conn.connect(db_name, server_name, user, password)) + { + cerr << "DB connection failed: " << conn.error() << endl; + return; + } + + mysqlpp::Query query = conn.query("select item from table1"); + mysqlpp::StoreQueryResult sqr = query.store() + if(!sqr) + { + cerr << "Failed to get item list: " << query.error() << endl; + return; + } + + mysqlpp::StoreQueryResult::const_iterator iter; + for(iter=sqr.begin(); iter!=sqr.end(); ++iter) + { + mysqlpp::Row row = *iter; + cout << '\t' << row[0] << endl; + } +} + +

POCO::Data::MySQL

Docs:[http://pocoproject.org/docs/package-MySQL.MySQL.html] From 3190b9f94d527b067df18b04c9201e88b1074b26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Thu, 23 Jul 2015 23:56:08 +0800 Subject: [PATCH 030/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20pcap=20=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 6ad4e43..2e9815b 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1177,6 +1177,63 @@ Wikipedia:[https://en.wikipedia.org/wiki/Pcap 英文] 很著名的 Sniffer 抓包库,基于 C 语言开发。 +代码示例——一个简单的抓包示例 + +#include +#include + +int main(int argc, char* argv[]) +{ + pcap_t* handle; /* Session handle */ + char* dev; /* The device to sniff on */ + char errbuf[PCAP_ERRBUF_SIZE]; /* Error string */ + struct bpf_program fp; /* The compiled filter */ + char filter_exp[] = "port 23"; /* The filter expression */ + bpf_u_int32 mask; /* Our netmask */ + bpf_u_int32 net; /* Our IP */ + struct pcap_pkthdr header; /* The header that pcap gives us */ + const u_char* packet; /* The actual packet */ + + /* Define the device */ + dev = pcap_lookupdev(errbuf); + if(dev == NULL) + { + fprintf(stderr, "Couldn't find default device: %s\n", errbuf); + return 2; + } + /* Find the properties for the device */ + if(pcap_lookupnet(dev, &net, &mask, errbuf) == -1) + { + fprintf(stderr, "Couldn't get netmask for device %s: %s\n", dev, errbuf); + net = 0; + mask = 0; + } + /* Open the session in promiscuous mode */ + handle = pcap_open_live(dev, BUFSIZ, 1, 1000, errbuf); + if(handle == NULL) + { + fprintf(stderr, "Couldn't open device %s: %s\n", dev, errbuf); + return 2; + } + /* Compile and apply the filter */ + if(pcap_compile(handle, &fp, filter_exp, 0, net) == -1) + { + fprintf(stderr, "Couldn't parse filter %s: %s\n", filter_exp, pcap_geterr(handle)); + return 2; + } + if(pcap_setfilter(handle, &fp) == -1) + { + fprintf(stderr, "Couldn't install filter %s: %s\n", filter_exp, pcap_geterr(handle)); + return 2; + } + + packet = pcap_next(handle, &header); /* Grab a packet */ + printf("Jacked a packet with length of [%d]\n", header.len); + pcap_close(handle); /* Close the session */ + return 0; +} + +

WinPcap

Home:[http://www.winpcap.org/] From 6f6375fbd405b535f9e14bc9b032b6c5b3a48f2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Fri, 24 Jul 2015 22:56:52 +0800 Subject: [PATCH 031/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Redis=20=E5=8F=8A?= =?UTF-8?q?=E5=85=B6=E5=AE=A2=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 88 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 2 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 2e9815b..2c51cb0 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1602,13 +1602,25 @@ Wikipedia:[https://en.wikipedia.org/wiki/MongoDB 英文] 这是近几年兴起的 NoSQL 数据库的一员。它本身是基于 C++ 和 C 开发的。 +

Redis

+ +Home:[http://redis.io/] + +Wikipedia:[https://zh.wikipedia.org/wiki/Redis 中文]、[https://en.wikipedia.org/wiki/Redis 英文] + +诞生于2009年,是目前(2014~2015)最流行的键值存储数据库,基于 C 语言开发。 + +以性能高而著称,很多大型网站用到它(Twitter、GitHub、Flickr、Instagram、百度、新浪、腾讯、搜狐) +

Berkeley DB(BDB)

Home:[http://www.oracle.com/us/products/database/berkeley-db/] Wikipedia:[https://en.wikipedia.org/wiki/Berkeley_DB 英文]、[https://zh.wikipedia.org/wiki/Berkeley_DB 中文] -诞生于1994年,是一个很老牌的嵌入式(进程内)数据库,基于 C 语言开发。开发 BDB 的公司于2006年被 Oracle 收购。 +诞生于1994年,是一个很老牌的嵌入式(进程内)数据库,提供“键值存储”的功能,基于 C 语言开发。 + +开发 BDB 的公司于2006年被 Oracle 收购。 很多开源项目用到它。甚至 MySQL 也包含了一个基于 BDB 的存储后端。 @@ -1893,7 +1905,79 @@ Docs:[http://pocoproject.org/docs/package-SQLite.SQLite.html] POCO 前面已经介绍过。它提供了 sqlite 的封装类 -=== 8.2.7 MongoDB 封装库 === +=== 8.2.7 Redis === + +

Hiredis

+ +Home:[https://github.com/redis/hiredis] + +这是 Redis 官方提供的 C 客户端,很轻量级,支持“异步 API”。 + +代码示例——结合 libev 进行异步调用 + +#include +#include +#include +#include + +#include +#include +#include + +void getCallback(redisAsyncContext* context, void* r, void* privdata) +{ + redisReply* reply = r; + if(reply == NULL) + { + return; + } + printf("argv[%s]: %s\n", (char*)privdata, reply->str); + redisAsyncDisconnect(context); /* Disconnect after receiv reply */ +} + +void connectCallback(const redisAsyncContext* context, int status) +{ + if(status != REDIS_OK) + { + printf("Error: %s\n", context->errstr); + return; + } + printf("Connected...\n"); +} + +void disconnectCallback(const redisAsyncContext* context, int status) +{ + if(status != REDIS_OK) + { + printf("Error: %s\n", context->errstr); + return; + } + printf("Disconnected...\n"); +} + +int main(int argc, char* argv[]) +{ + signal(SIGPIPE, SIG_IGN); + + redisAsyncContext* context = redisAsyncConnect("127.0.0.1", 6379); + if(context->err) + { + printf("Error: %s\n", context->errstr); + return 1; /* Let *context leak for now... */ + } + + redisLibevAttach(EV_DEFAULT_ context); + redisAsyncSetConnectCallback(context, connectCallback); + redisAsyncSetDisconnectCallback(context, disconnectCallback); + redisAsyncCommand(context, NULL, NULL, + "SET key %b", argv[argc-1], strlen(argv[argc-1])); + redisAsyncCommand(context, getCallback, (char*)"end-1", "GET key"); + ev_loop(EV_DEFAULT_ 0); + return 0; +} + + +=== 8.2.8 MongoDB 封装库 ===

官方的 C API

From 6b7b614b9b1b25447b94419a171d5c11bf26e8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Fri, 24 Jul 2015 23:11:50 +0800 Subject: [PATCH 032/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Redis=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 7182b76..2550880 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -862,7 +862,23 @@ conn.commit() conn.close() -=== 6.2.7 Berkeley DB === +=== 6.2.7 Redis === + +

redis-py

+ +Home:[https://github.com/andymccurdy/redis-py] + +操作 Redis 的第三方 Python 客户端。 + +代码示例——简单的 set/get + +import redis +r = redis.StrictRedis(host="localhost", port=6379, db=0) +r.set("foo", "bar") +print(r.get("foo")) + + +=== 6.2.8 Berkeley DB ===

PyBSDDB

From 4515647959525947b23fc965a8fcecbfac7b70e8 Mon Sep 17 00:00:00 2001 From: Jiang Zhu Date: Wed, 30 Sep 2015 19:37:05 +0800 Subject: [PATCH 033/116] python.wiki: fix typo --- libs/python.wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 2550880..669e514 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -155,7 +155,7 @@ Home:[http://www.jython.org/] Wikipedia:[https://en.wikipedia.org/wiki/Jython 英文]、[https://zh.wikipedia.org/wiki/Jython 中文] -通过 Jython 可以让 Python 代码运行在 JVM 上,并且可以调用其它的 JVM 语言的代码(比如 Java、Scale) +通过 Jython 可以让 Python 代码运行在 JVM 上,并且可以调用其它的 JVM 语言的代码(比如 Java、Scala) == 2.3 整合 dotNet 平台 == From e013722b9c5c95a091c48a1aed9d5759ee96384b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 5 Oct 2015 23:48:31 +0800 Subject: [PATCH 034/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20zopfli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 2c51cb0..79aa42c 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2405,7 +2405,9 @@ Home:[http://www.libarchive.org/] C 语言实现,支持的格式: -可创建/解开:zip、tar、7z、cpio、ar、xar;可解开:gzip、bzip2、xz、lzma、rpm、lz4、lzop +可读写的格式:zip、gzip、bzip2、xz、lzma、tar、ISO、cpio、ar、pax、mtree; + +只读的格式:7z、rar、cab、rpm、lzh、lzop、raw、xar

LZMA SDK

@@ -2415,6 +2417,14 @@ Home:[http://www.7-zip.org/sdk.html] 支持的格式:7z、LZMA、LZMA2、XZ +

zopfli

+ +Home:[https://github.com/google/zopfli] + +这是由 Google 开发的 C 库,提供对 zip 和 gzip 格式的压缩(不提供解压)。 + +压缩的速度比较慢,但是可以得到更高的压缩率。 + === 11.2.2 zip === [https://en.wikipedia.org/wiki/Zip_%28file_format%29 格式说明] From ca08483def0229b948e53f74fc20e418356e725b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 6 Oct 2015 00:19:40 +0800 Subject: [PATCH 035/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Google=20Test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 79aa42c..57061bf 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -721,6 +721,16 @@ Docs:[http://boost.org/libs/test] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了与测试相关的各种辅助工具(包括单元测试)。 +

Google Test

+ +Home:[https://github.com/google/googletest] + +Wikipedia:[https://en.wikipedia.org/wiki/Google_Test 英文] + +这是 Google 提供的单元测试框架。从 Google Code 迁移到 GitHub 之后,又整合了 GoogleMock 项目。 + +一些知名的开源项目(Chromium、LLVM、OpenCV)用到了它。 +

CppUnit

Home:[http://freedesktop.org/wiki/Software/cppunit/] From 56f10386a7f4a49e1ecb844992652bce169c9c2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 6 Oct 2015 00:38:04 +0800 Subject: [PATCH 036/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20benchmark?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 57061bf..c13cdf0 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -762,7 +762,7 @@ END_TEST doing so produces all sorts of strange errors when the check is compiled. */ -== 4.3 检测内存泄漏 == +== 4.3 健壮性测试 ==

Boost.Test.ExecutionMonitor

@@ -770,6 +770,16 @@ Docs:[http://boost.org/libs/test/doc/html/execution-monitor.html] Boost 前面已经介绍过。这是 Boost 的其中一个子库,它除了提供“单元测试”,还提供“内存泄漏的检测”。 +== 4.4 性能测试 == + +

benchmark

+ +Home:[https://github.com/google/benchmark] + +这是 Google 提供的性能测试辅助工具,用来测试指定函数的执行时间。 + +它可以把测试结果导出为 CSV 或 JSON 格式。 + ---- = 5 操作系统相关 = From e092b051830ca8964164d1a93c08ab43818d4404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 6 Oct 2015 01:13:20 +0800 Subject: [PATCH 037/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20re2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index c13cdf0..2a4ded5 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -351,6 +351,24 @@ string human_readable_card_number(const string& s) } +

re2

+ +Home:[https://github.com/google/re2] + +这是 Google 提供的正则式库,基于 C++。其 API 使用起来很简洁。 + +有多种脚本语言(Python、Ruby、Perl、Node.js、Erlang、OCaml)提供了对它的封装。 + +代码示例——基于正则式进行匹配 + +#include +int i; +string s; +assert(RE2::FullMatch("test:1234", "(\\w+):(\\d+)", &s, &i)); +assert(s == "test"); +assert(i == 1234); + +

Oniguruma(鬼车)

Home:[http://www.geocities.jp/kosako3/oniguruma/] From a72914465beb2334fc5d982cdc66b71b3d532b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 7 Oct 2015 00:21:56 +0800 Subject: [PATCH 038/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Keyczar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 2a4ded5..ae74c9c 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2341,6 +2341,46 @@ Home:[https://github.com/jedisct1/libsodium] shadowsocks 和 dnscrypt-proxy 用到它。 +

Keyczar

+ +Home:[https://github.com/google/keyczar] + +这是 Google 提供的加密库,同时提供 C++、Java、Python 三种语言的实现。 + +它提供了比较高层的 API, 使用者无需关心太多的细节。 + +代码示例——加密/解密文本 + +#include +#include +#include +#include + +void test(const std::string& key_location) +{ + keyczar::Keyczar* crypter = keyczar::Crypter::Read(key_location); + if(!crypter) + { + return; + } + + std::string plain = "Secret message"; + std::cout << "Plain text: " << plain << std::endl; + + std::string cipher; + if(crypter->Encrypt(plain, &cipher)) + { + std::cout << "Cipher text (Base64w): " << cipher << std::endl; + std::string decrypted; + if(crypter->Decrypt(cipher, &decrypted)) + { + assert(plain == decrypted); + } + } + delete crypter; +} + +

POCO::Crypto

Docs:[http://pocoproject.org/docs/Poco.Crypto.html] From e6109cd9d502b0693e5e85e2f0a0748d7c3e0ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 7 Oct 2015 00:34:28 +0800 Subject: [PATCH 039/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Keyczar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 2550880..5959b0f 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1251,6 +1251,14 @@ Home:[http://pyopenssl.sourceforge.net/] [https://en.wikipedia.org/wiki/OpenSSL OpenSSL] 在加密领域可是大名鼎鼎。这个库使用 Python 对 OpenSSL 进行很薄的封装。 +

Keyczar

+ +Home:[https://github.com/google/keyczar] + +这是 Google 提供的加密库,同时提供 C++、Java、Python 三种语言的实现。 + +它提供了比较高层的 API, 使用者无需关心太多的细节。 + ---- = 9 处理文件格式 = From 6c8be8c31a180afc28394f96b3547a24fe3a7dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 7 Oct 2015 01:00:23 +0800 Subject: [PATCH 040/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20LevelDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index ae74c9c..5e1e84b 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1662,6 +1662,18 @@ Wikipedia:[https://en.wikipedia.org/wiki/Berkeley_DB 英文]、[https://zh.wik 很多开源项目用到它。甚至 MySQL 也包含了一个基于 BDB 的存储后端。 +

LevelDB

+ +Home:[https://github.com/google/leveldb] + +Wikipedia:[https://en.wikipedia.org/wiki/LevelDB 英文]、[https://zh.wikipedia.org/wiki/LevelDB 中文] + +它是 Google 基于 C++ 开发的 NoSQL 数据库,提供“键值存储”的功能。 + +号称速度很快,内置数据压缩(基于 [https://en.wikipedia.org/wiki/Snappy_(software) Snappy] 库)。 + +比特币项目用到它。Facebook 基于它开发出 RocksDB 数据库。 +

Firebird

Home:[http://www.firebirdsql.org/] From 63293d0a2b97fae07710d91a6d5ce09555004dab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 7 Oct 2015 01:17:40 +0800 Subject: [PATCH 041/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Skia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 5e1e84b..78daa02 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2759,7 +2759,7 @@ Home:[http://cairographics.org/] Wikipedia:[https://en.wikipedia.org/wiki/Cairo_%28graphics%29 英文]、[https://zh.wikipedia.org/wiki/Cairo_(%E7%B9%AA%E5%9C%96) 中文] -它提供了矢量图像的渲染功能。支持多种后端输出(包括:Win32 GDI、OpenGL、Xlib、XCB、PDF、PNG、SVG......)。 +它提供了矢量图像的渲染功能。支持多种后端输出(Win32 GDI、OpenGL、Xlib、XCB、PDF、PNG、SVG ......)。 基于 C 语言开发,提供多种语言绑定(C++、Java、C#、Python、Ruby、Perl、Scheme、Smalltalk)。 @@ -2769,6 +2769,16 @@ Home:[http://cairographics.org/cairomm/] 这是针对 Cairo 的 C++ 封装库。 +

Skia

+ +Home:[https://github.com/google/skia] + +Wikipedia:[https://en.wikipedia.org/wiki/Skia_Graphics_Engine 英文]、[https://zh.wikipedia.org/wiki/Skia_Graphics_Library 中文] + +它是 Google 基于 C++ 开发的图像渲染库。支持多种后端输出(rasterization、OpenGL、PDF、SVG、SWF ......)。 + +原先由 Skia 公司开发,后来该公司被 Google 收购。被用于 Android、Chrome、Chrome OS、Firefox 等知名开源项目。 +

PBRT(Physically Based Rendering Toolkit)

Home:[http://pbrt.org/] From 26edfe05becf3796ac86ce2997d195754805b4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Wed, 7 Oct 2015 23:56:08 +0800 Subject: [PATCH 042/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20fruit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 78daa02..6eee6af 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -596,6 +596,80 @@ POCO 前面已经介绍过。它提供了 UUID 的生成、格式转换。 == 3.1 面向对象编程(OOP) == +

fruit

+ +Home:[https://github.com/google/fruit] + +它是 Google 开发的 C++ 库,提供了“依赖注入”([https://en.wikipedia.org/wiki/Dependency_injection dependency injection])的框架。 + +代码示例——一个简单的例子 + +#include +#include + +using fruit::Component; +using fruit::Injector; + +class Writer +{ +public: + virtual void write(std::string str) = 0; +}; + +class StdoutWriter : public Writer +{ +public: + // Like "StdoutWriter() = default;" but also marks this constructor as the + // one to use for injection. + INJECT(StdoutWriter()) = default; + + virtual void write(std::string str) override + { + std::cout << str; + } +}; + +class Greeter +{ +public: + virtual void greet() = 0; +}; + +class GreeterImpl : public Greeter +{ +private: + Writer* writer; + +public: + // Like "GreeterImpl(Writer* writer) {...}" + // but also marks this constructor as the one to use for injection. + INJECT(GreeterImpl(Writer* writer)) + : writer(writer) + { + } + + virtual void greet() override + { + writer->write("Hello world!\n"); + } +}; + +Component getGreeterComponent() +{ + return fruit::createComponent() + .bind() + .bind(); +} + +int main() +{ + Injector injector(getGreeterComponent()); + Greeter* greeter = injector.get(); + greeter->greet(); + return 0; +} + + == 3.2 泛型编程(GP) ==

Boost.TypeTraits

From bcc8dbfa1d02c972970f7ec8b162e388af170a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Thu, 8 Oct 2015 23:24:35 +0800 Subject: [PATCH 043/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20oauth2client?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 5959b0f..0c2b5a9 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1259,6 +1259,14 @@ Home:[https://github.com/google/keyczar] 它提供了比较高层的 API, 使用者无需关心太多的细节。 +== 8.2 访问控制 == + +

oauth2client

+ +Home:[https://github.com/google/oauth2client] + +这是 Google 提供的 OAuth 客户端,支持 OAuth 2.0 规范。 + ---- = 9 处理文件格式 = From 5dbd8cea1edc2aba7ca8bee9a26a0d8261e09f66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Thu, 8 Oct 2015 23:37:38 +0800 Subject: [PATCH 044/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20pywebsocket?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 0c2b5a9..838d804 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -537,6 +537,16 @@ Home:[https://github.com/jmalonzo/pywebkitgtk] PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 +== 4.6 其它 == + +

pywebsocket

+ +Home:[https://github.com/google/pywebsocket] + +这是 Google 提供的 [https://zh.wikipedia.org/wiki/WebSocket WebSocket] 服务端。 + +该项目包含一个可独立运行的 server 以及一个 Apache 扩展模块(mod_pywebsocket)。 + ---- = 5 网络 = From a41374c58341f2baf11adae393f139c4d28ee914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Thu, 8 Oct 2015 23:58:32 +0800 Subject: [PATCH 045/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20pygtrie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 838d804..481d393 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -99,6 +99,14 @@ random.randint(0, 100) 这个标准库封装了跟有理数(分数)相关的运算 +== 1.4 容器 == + +

pygtrie

+ +Home:[https://github.com/google/pytrie] + +这是 Google 实现的 [https://zh.wikipedia.org/wiki/Trie trie](前缀树/字典树)封装库。 + ---- = 2 跨语言编程 = @@ -537,7 +545,7 @@ Home:[https://github.com/jmalonzo/pywebkitgtk] PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 -== 4.6 其它 == +== 4.6 (其它) ==

pywebsocket

From 3ac95484c27835b12acb6fa9e842c847ef9c032c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Tue, 27 Oct 2015 23:56:39 +0800 Subject: [PATCH 046/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20ScyllaDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 6eee6af..210abf6 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1760,6 +1760,14 @@ Wikipedia:[https://en.wikipedia.org/wiki/Firebird_%28database_server%29 英文 关于它有个插曲:Firefox 浏览器曾经用过“Firebird”这个名称,因为跟 Firebird 数据库同名,后来才改用 Firefox 这个名称。 +

ScyllaDB

+ +Home:[http://www.scylladb.com/] + +这是2015年新兴的 NoSQL 数据库,相当于是用 C++ 重写了(Java 开发的)Cassandra。 + +号称性能提高10倍,并且延迟极低。 + == 8.2 数据库 API 的封装库 == === 8.2.1 综合性的封装库 === From 75f97fecbc8d6b7f15f300dd89aa9c5fda536be0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sat, 31 Oct 2015 23:59:24 +0800 Subject: [PATCH 047/116] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 210abf6..5df1a81 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2037,7 +2037,7 @@ Docs:[http://pocoproject.org/docs/package-SQLite.SQLite.html] POCO 前面已经介绍过。它提供了 sqlite 的封装类 -=== 8.2.7 Redis === +=== 8.2.7 Redis 封装库 ===

Hiredis

From de49749a74f9a5fcef2ffdfeb5e5d44f84e6f7c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sun, 1 Nov 2015 23:20:46 +0800 Subject: [PATCH 048/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E7=BC=96=E7=A8=8B=E2=80=9D=E7=9A=84=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 5df1a81..aa7b0ba 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1277,9 +1277,7 @@ Home:[http://wxmathplot.sourceforge.net/] = 7 网络编程 = -== 7.1 标准协议 == - -=== 7.1.1 链路层 & 网络层 === +== 7.1 链路层 & 网络层 ==

libpcap

@@ -1354,7 +1352,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Pcap 英文] 它是 libpcap 在 Windows 系统下的移植。 -=== 7.1.2 传输层 === +== 7.2 传输层 ==

socket

@@ -1380,7 +1378,7 @@ Docs:[http://pocoproject.org/docs/Poco.Net.html] POCO 前面已经介绍过。它提供了针对 TCP 服务端的封装类。 -=== 7.1.3 应用层 === +== 7.3 标准的应用层 ==

cURL & libcurl

@@ -1451,7 +1449,7 @@ Home:[http://c-ares.haxx.se/] 对比官网域名可知,它跟 cURL 是一家子。除了 cURL/libcurl 用到它,还有一些知名开源项目(比如:Wireshark、node.js ...)用到它。 -== 7.2 自定义协议 == +== 7.4 自定义的应用层 ==

Protocol Buffers

@@ -1477,7 +1475,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] (在这个方面,它有点类似于 Google 的 Protocol Buffers) -== 7.3 网络库、框架、中间件 == +== 7.5 网络库、框架、中间件 ==

Boost.Asio

From 3508a59446af502bb5334dd39e2df84282c46277 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Sun, 1 Nov 2015 23:55:18 +0800 Subject: [PATCH 049/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E7=BC=96=E7=A8=8B=20/=20=E6=A0=87=E5=87=86=E7=9A=84?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=B1=82=E2=80=9D=E7=9A=84=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index aa7b0ba..056e15f 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1380,6 +1380,8 @@ POCO 前面已经介绍过。它提供了针对 TCP 服务端的封装类。 == 7.3 标准的应用层 == +=== 7.3.1 综合性的库 === +

cURL & libcurl

Home:[http://curl.haxx.se/libcurl/] @@ -1441,6 +1443,12 @@ Docs:[http://pocoproject.org/docs/Poco.Net.html] POCO 前面已经介绍过。它提供了几种常见应用层协议(HTTP、SMTP、POP3、FTP、NTP ...)的封装类。 +=== 7.3.2 HTTP === + +(关于“HTTP 协议”,请参见另一个大类:“Web 相关”) + +=== 7.3.3 DNS === +

c-ares

Home:[http://c-ares.haxx.se/] From 32e1030558eb3672dc45f8785059a220d3056523 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 2 Nov 2015 00:00:35 +0800 Subject: [PATCH 050/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=E2=80=9D=E7=9A=84=E4=B8=8B=E7=BA=A7=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 5015014..3d2abb9 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -559,9 +559,7 @@ Home:[https://github.com/google/pywebsocket] = 5 网络 = -== 5.1 标准协议 == - -=== 5.1.1 链路层 & 网络层 === +== 5.1 链路层 & 网络层 ==

Scapy

@@ -582,7 +580,7 @@ ans,unans = sr(IP(dst="192.168.1.1-254")/ICMP()) ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2) -=== 5.1.2 传输层 === +== 5.2 传输层 ==

socket

@@ -598,7 +596,7 @@ Python 标准库很早就提供了对 socket 编程的支持。 这个标准库基于上述的 asyncore,提供更高层的 API,简化异步通讯编程。 -=== 5.1.3 应用层 === +== 5.3 标准的应用层 ==

ftplib

@@ -664,7 +662,7 @@ Home:[https://bitbucket.org/jaraco/irc] IRC 是 Internet Relay Chat 的缩写。这是用 Python 封装的第三方库。 -== 5.2 自定义协议 == +== 5.4 自定义的应用层 ==

Protocol Buffers

@@ -690,7 +688,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] (在这个方面,它有点类似于 Google 的 Protocol Buffers) -== 5.3 网络库、框架、中间件 == +== 5.5 网络库、框架、中间件 ==

Twisted

From aec226f8e23c242ffdfd592c7b89a7fd92619586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 2 Nov 2015 00:09:30 +0800 Subject: [PATCH 051/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A4=A7=E7=B1=BB?= =?UTF-8?q?=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 3d2abb9..83ceb4f 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -185,7 +185,7 @@ Home:[http://pyobjc.sourceforge.net/] ---- -= 3 操作系统相关 = += 3 操作系统 = == 3.1 文件和目录操作 == @@ -376,7 +376,7 @@ Home:[https://pypi.python.org/pypi/setuptools] ---- -= 4 Web 开发 = += 4 Web = == 4.1 HTTP Client == @@ -973,7 +973,7 @@ Person.createTable() ---- -= 7 GUI 开发 = += 7 GUI = == 7.1 GUI 框架 == @@ -1580,7 +1580,7 @@ Home:[http://cairographics.org/pycairo/] Pycairo 是 Cairo 官方提供 Python 封装。 -= 11 游戏开发 = += 11 游戏 = == 11.1 综合性的游戏引擎 == From 296c90aef7157e3b84dd551aa098335cbda0ef14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 2 Nov 2015 00:24:05 +0800 Subject: [PATCH 052/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9C=E7=BD=91?= =?UTF-8?q?=E7=BB=9C=20/=20=E6=A0=87=E5=87=86=E7=9A=84=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=B1=82=E2=80=9D=E7=9A=84=E4=B8=8B=E7=BA=A7=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 60 +++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 83ceb4f..2dcacd8 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -598,6 +598,39 @@ Python 标准库很早就提供了对 socket 编程的支持。 == 5.3 标准的应用层 == +=== 5.3.1 综合性的库 === + +

PycURL

+ +Home:[http://pycurl.sourceforge.net/] + +[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。俺在前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 + +看名称就能猜到——PycURL 是 cURL 的 Python 封装。 + +代码示例——发起 HTTP GET 请求 + +import pycurl +try : + from io import BytesIO +except ImportError : + from StringIO import StringIO as BytesIO + +buffer = BytesIO() +curl = pycurl.Curl() +curl.setopt(curl.URL, "http://pycurl.sourceforge.net/") +curl.setopt(curl.WRITEDATA, buffer) +curl.perform() +curl.close() +body = buffer.getvalue() + + +=== 5.3.2 HTTP === + +(关于“HTTP 协议”,请参见另一个大类:“Web”) + +=== 5.3.3 FTP === +

ftplib

封装 FTP 协议(文件传输)的标准库 @@ -613,6 +646,8 @@ ftp.retrlines("LIST") # 列出当前目录的内容 ftp.quit() +=== 5.3.4 Email === +

smtplib

封装 SMTP 协议(邮件发送)的标准库 @@ -625,30 +660,7 @@ ftp.quit() 封装 POP3 协议(邮件接收)的标准库 -

PycURL

- -Home:[http://pycurl.sourceforge.net/] - -[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。俺在前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 - -看名称就能猜到——PycURL 是 cURL 的 Python 封装。 - -代码示例——发起 HTTP GET 请求 - -import pycurl -try : - from io import BytesIO -except ImportError : - from StringIO import StringIO as BytesIO - -buffer = BytesIO() -curl = pycurl.Curl() -curl.setopt(curl.URL, "http://pycurl.sourceforge.net/") -curl.setopt(curl.WRITEDATA, buffer) -curl.perform() -curl.close() -body = buffer.getvalue() - +=== 5.3.5 IM ===

jabber.py

From d39fa1d8d9e1c00f473b7fc88b9f61f50b152629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 2 Nov 2015 00:31:43 +0800 Subject: [PATCH 053/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E5=A4=A7=E7=B1=BB?= =?UTF-8?q?=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 056e15f..d03d330 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -874,7 +874,7 @@ Home:[https://github.com/google/benchmark] ---- -= 5 操作系统相关 = += 5 操作系统 = == 5.1 跨操作系统 == @@ -1054,7 +1054,7 @@ POCO 前面已经介绍过。它提供了相应的封装类(WinService), ---- -= 6 GUI 开发 = += 6 GUI = == 6.1 GUI 框架 == @@ -1275,7 +1275,7 @@ Home:[http://wxmathplot.sourceforge.net/] ---- -= 7 网络编程 = += 7 网络 = == 7.1 链路层 & 网络层 == @@ -2240,7 +2240,7 @@ trans.commit(); ---- -= 9 Web 相关 = += 9 Web = == 9.1 HTTP Server == @@ -2949,7 +2949,7 @@ C 语言开发的 3D 音效库,跨平台。最初由 Loki Software 开发。Lo ---- -= 14 游戏开发 = += 14 游戏 = == 14.1 综合性的游戏引擎 == From 70b8a822361af5ace609b5ef747f17b5cb45d2e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A8=8B=E9=9A=8F=E6=83=B3?= Date: Mon, 2 Nov 2015 00:56:48 +0800 Subject: [PATCH 054/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20XMPP=20=E5=BA=93?= =?UTF-8?q?=EF=BC=88Swiften=E3=80=81QXmpp=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index d03d330..ee9c385 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1457,6 +1457,24 @@ Home:[http://c-ares.haxx.se/] 对比官网域名可知,它跟 cURL 是一家子。除了 cURL/libcurl 用到它,还有一些知名开源项目(比如:Wireshark、node.js ...)用到它。 +=== 7.3.4 XMPP === + +(XMPP 的洋文全称是“Extensible Messaging and Presence Protocol”。这是一个标准化的 IM 交互协议) + +

Swiften

+ +Home:[http://swift.im/swiften.html] + +这是一个 C++ 语言开发的 XMPP 封装库。它同时也是 Swift 聊天客户端所用的后端。 + +它大量使用了 Boost 的子库(Signal、Bind、Optional、Smart Pointers ...)。 + +

QXmpp

+ +Home:[https://github.com/qxmpp-project/qxmpp] + +这是一个 C++ 语言开发的 XMPP 封装库。从它的名称可以看出——依赖了 Qt 框架(需要 Qt 4.5 或更高版本)。 + == 7.4 自定义的应用层 ==

Protocol Buffers

From 0aaa25a4094f92b9b7ac40aad7327acd44d42a4c Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 23 Dec 2015 23:58:58 +0800 Subject: [PATCH 055/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Requests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 2dcacd8..bebdefe 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -394,6 +394,27 @@ page = handle.read() handle.close() +

Requests

+ +Home:[http://www.python-requests.org/] + +这是一个用起来很优雅的库,如其名,封装了 HTTP 请求的功能。 + +代码示例 + +>>> r = requests.get('https://api.github.com/user', auth=('user', 'pass')) +>>> r.status_code +200 +>>> r.headers['content-type'] +'application/json; charset=utf8' +>>> r.encoding +'utf-8' +>>> r.text +u'{"type":"User"...' +>>> r.json() +{u'private_gists': 419, u'total_private_repos': 77, ...} + + == 4.2 HTTP Server ==

SimpleHTTPServer & http.server

From 350cae4b95b9efa3243e089739a5db9ec659d709 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 25 Dec 2015 23:37:25 +0800 Subject: [PATCH 056/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20libuv?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index ee9c385..fd9823f 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1459,7 +1459,7 @@ Home:[http://c-ares.haxx.se/] === 7.3.4 XMPP === -(XMPP 的洋文全称是“Extensible Messaging and Presence Protocol”。这是一个标准化的 IM 交互协议) +([https://zh.wikipedia.org/wiki/XMPP XMPP] 的洋文全称是“Extensible Messaging and Presence Protocol”。这是一个标准化的 IM 交互协议)

Swiften

@@ -1692,6 +1692,16 @@ Home:[http://libev.schmorp.de/] [http://www.gevent.org/ gevent] 官方博客的[http://blog.gevent.org/2011/04/28/libev-and-libevent/ 一篇文章]对比了这俩库的优缺点。 +

libuv

+ +Home:[https://github.com/libuv/libuv] + +Wikipedia:[https://en.wikipedia.org/wiki/Libuv 英文] + +它提供了跨平台的异步 I/O 机制。主要是为了提供给 [https://en.wikipedia.org/wiki/Node.js Node.js] 使用。 + +除了支持网络通讯,还支持:线程池、Windows 命名管道、Unix domain sockets、文件系统事件通知 ...... +

Dlib

Docs:[http://dlib.net/network.html] From 22339817825b327e38b045ee3607d6e20c2a4f67 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 25 Dec 2015 23:50:30 +0800 Subject: [PATCH 057/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20hiberlite?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index fd9823f..ef55622 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2266,6 +2266,12 @@ for(result::iterator i(r.begin()); i!=r.end(); ++i) trans.commit(); +

hiberlite

+ +Home:[https://github.com/paulftw/hiberlite] + +专门提供给 Sqlite 的 ORM 封装库。基于 C++ 开发,其 API 采用类似 Boost.Serialization 的风格。 + ---- = 9 Web = From e7ed27cc89d7d738a1a16eab747e74e3fd2317f9 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 26 Dec 2015 00:30:25 +0800 Subject: [PATCH 058/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20WebSocket++?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index ef55622..352cd49 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2403,6 +2403,16 @@ Wikipedia:[https://en.wikipedia.org/wiki/PhantomJS 英文] 它本身没有提供 GUI 界面。但是提供了 JavaScript 的 API,让你可以操纵 WebKit 引擎。可以利用它进行 Web 界面的单元测试。 +== 9.5 (其它) == + +

WebSocket++

+ +Home:[http://www.zaphoyd.com/websocketpp/] + +顾名思义,它提供了 [https://en.wikipedia.org/wiki/WebSocket WebSocket] 的 C++ 封装,基于 Boost Asio 构建。 + +支持多种操作系统平台,支持 TLS、proxy、IPv6。 + ---- = 10 信息安全 = From b2024b73abf6266fe7dbe1d646415246082c1844 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 27 Feb 2016 23:53:25 +0800 Subject: [PATCH 059/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20PyGraphviz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index bebdefe..6d30bcf 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1593,6 +1593,14 @@ with Image(filename="mona-lisa.png") as img : display(new_img) +

PyGraphviz

+ +Home:[https://github.com/pygraphviz/pygraphviz] + +[https://en.wikipedia.org/wiki/Graphviz Graphviz] 是一个功能很强大的关系图【自动】生成工具,具体介绍可以参见俺的博文(在“[https://program-think.blogspot.com/2016/02/opensource-review-graphviz.html 这里]”) + +这个库如其名所示,提供了 Python 对 Graphviz 的封装。 + == 10.2 图像格式转换 ==

Python Imaging Library(PIL)

From b7c81a1072f5317c13fd60ef487d165df7c632b7 Mon Sep 17 00:00:00 2001 From: programthink Date: Sun, 28 Feb 2016 00:10:37 +0800 Subject: [PATCH 060/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Graphviz?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 6d30bcf..6f4b7d8 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1599,7 +1599,29 @@ Home:[https://github.com/pygraphviz/pygraphviz] [https://en.wikipedia.org/wiki/Graphviz Graphviz] 是一个功能很强大的关系图【自动】生成工具,具体介绍可以参见俺的博文(在“[https://program-think.blogspot.com/2016/02/opensource-review-graphviz.html 这里]”) -这个库如其名所示,提供了 Python 对 Graphviz 的封装。 +这个库如其名所示,提供了 Python 对 Graphviz 的封装(基于 SWIG)。 + +

Graphviz

+ +Home:[https://github.com/xflr6/graphviz] + +这个库与上一个类似,也提供了 Graphviz 的 Python 的封装。 + +这两个库都在 GitHub 上。(可能是因为出现较晚)这个库的 Star 和 Fork 数都不如上一个,不过俺感觉文档比较全。 + +代码示例——创建一个 DOT 图并加入若干节点和连线 + +from graphviz import Digraph + +dot = Digraph(comment='The Round Table') +# 添加节点 +dot.node('A', 'King Arthur') +dot.node('B', 'Sir Bedevere the Wise') +dot.node('L', 'Sir Lancelot the Brave') +# 添加连线 +dot.edges(['AB', 'AL']) +dot.edge('B', 'L', constraint='false') + == 10.2 图像格式转换 == From 6aabdb7142148eb133275152aa060d1849857111 Mon Sep 17 00:00:00 2001 From: programthink Date: Sun, 28 Feb 2016 23:19:59 +0800 Subject: [PATCH 061/116] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E6=94=B9=E4=B8=BAHTTPS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 6f4b7d8..10c1a72 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -8,7 +8,7 @@ 本页面列出的各种 Python 库/模块,如果注明了官网的网址,说明这个库是第三方的;否则就是 Python 语言内置的标准库。 -如果你发现本页面的开源库有错漏之处,非常欢迎给俺提供反馈——有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[http://program-think.blogspot.com/ 俺博客]留言。 +如果你发现本页面的开源库有错漏之处,非常欢迎给俺提供反馈——有 GitHub 帐号的同学,可以[https://github.com/programthink/opensource/issues 给俺发 issue];没帐号的同学,可以去[https://program-think.blogspot.com/ 俺博客]留言。 ---- @@ -625,7 +625,7 @@ Python 标准库很早就提供了对 socket 编程的支持。 Home:[http://pycurl.sourceforge.net/] -[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。俺在前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 +[https://en.wikipedia.org/wiki/Curl cURL] 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。俺在前几年写过一篇博文推荐它(在“[https://program-think.blogspot.com/2009/03/opensource-review-curl-library.html 这里]”)。 看名称就能猜到——PycURL 是 cURL 的 Python 封装。 @@ -705,7 +705,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] 这是 Google 开发的一个跨语言的库,用于网络传输业务数据时的“编码/解码”。 -其优点是:跨多种语言、高性能、向前兼容、向后兼容。俺前几年写过一篇博文推荐 protobuf(在“[http://program-think.blogspot.com/2009/05/opensource-review-protocol-buffers.html 这里]”)。 +其优点是:跨多种语言、高性能、向前兼容、向后兼容。俺前几年写过一篇博文推荐 protobuf(在“[https://program-think.blogspot.com/2009/05/opensource-review-protocol-buffers.html 这里]”)。 作为 Protocol Buffers 的发明者,Google 默认实现了三种编程语言(C++、Java、Python)对它的支持。 @@ -898,7 +898,7 @@ Home:[https://pypi.python.org/pypi/ibm_db] sqlite3 从 Python 2.5 版本开始加入到标准库中。通过它,你可以很方便地操作 SQLite 数据库。 -[https://en.wikipedia.org/wiki/SQLite SQLite] 是一个很优秀的轻量级数据库,俺前几年写过一篇博文推荐它(在“[http://program-think.blogspot.com/2009/04/how-to-use-sqlite.html 这里]”)。 +[https://en.wikipedia.org/wiki/SQLite SQLite] 是一个很优秀的轻量级数据库,俺前几年写过一篇博文推荐它(在“[https://program-think.blogspot.com/2009/04/how-to-use-sqlite.html 这里]”)。 代码示例——创建一个内存数据库,建表并插入记录 @@ -1280,7 +1280,7 @@ Home:[http://code.enthought.com/chaco/] 它支持的哈希算法有:MD5 SHA1 SHA224 SHA256 SHA384 SHA512 -关于散列算法,俺写过一篇扫盲(在“[http://program-think.blogspot.com/2013/02/file-integrity-check.html 这里]”)。 +关于散列算法,俺写过一篇扫盲(在“[https://program-think.blogspot.com/2013/02/file-integrity-check.html 这里]”)。 代码示例——计算字符串的 SHA1 散列值 From fcb92149075fb06252a3503f337242b0f4cf15e0 Mon Sep 17 00:00:00 2001 From: programthink Date: Mon, 11 Apr 2016 23:24:43 +0800 Subject: [PATCH 062/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20PhysicsFS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 352cd49..e3505a3 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2639,6 +2639,16 @@ Home:[http://www.7-zip.org/sdk.html] 支持的格式:7z、LZMA、LZMA2、XZ +

PhysicsFS

+ +Home:[http://icculus.org/physfs/] + +Wikipedia:[https://en.wikipedia.org/wiki/PhysicsFS 英文] + +针对不同的压缩/归档格式,提供了类似 VFS 的抽象封装层。主要用于游戏开发中。 + +支持的格式:zip、7z、GRP、PAK、HOG、MVL、WAD... +

zopfli

Home:[https://github.com/google/zopfli] From 27260a49cdbbbb20687e975df8602fb4162d0c7d Mon Sep 17 00:00:00 2001 From: programthink Date: Mon, 11 Apr 2016 23:26:03 +0800 Subject: [PATCH 063/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20snappy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index e3505a3..34f0d94 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2711,6 +2711,18 @@ Home:[http://www.unrarlib.org/] 该项目的开发已经停止。只支持对 RAR2 格式的解压缩。 +=== 11.2.7 snappy === + +

snappy

+ +Home:[https://google.github.io/snappy/] + +由 Google 开发的压缩格式,特点是非常快(不论是压缩还是解压);但是压缩率不如 gzip。 + +起先被用于 Google 内部的 BigTable,如今被用于多种 NoSQL 数据库(比如:Cassandra、Hadoop、LevelDB、MongoDB、RocksDB...) + +支持多种语言的绑定(C#、Common Lisp、Erlang、Go、Haskell、Lua、Java、Node.js、Perl、PHP、Python、R、Ruby、Smalltalk) + == 11.3 标记语言 == === 11.3.1 XML === From b6cfbfc486d982b7d8045a21d9abd90cca74996e Mon Sep 17 00:00:00 2001 From: programthink Date: Mon, 11 Apr 2016 23:27:00 +0800 Subject: [PATCH 064/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Brotli?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 34f0d94..53be113 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2723,6 +2723,18 @@ Home:[https://google.github.io/snappy/] 支持多种语言的绑定(C#、Common Lisp、Erlang、Go、Haskell、Lua、Java、Node.js、Perl、PHP、Python、R、Ruby、Smalltalk) +=== 11.2.8 Brotli === + +

Brotli

+ +Home:[https://github.com/google/brotli] + +Wikipedia:[https://en.wikipedia.org/wiki/Brotli 英文] + +由 Google 开发的压缩格式,压缩率很高(据说高于 LZMA 和 bz2)。 + +该算法很新,是2015年9月才发布的。 + == 11.3 标记语言 == === 11.3.1 XML === From 9b0001e534039cff12aa4058dcb4a20058a63cde Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 21 May 2016 22:33:24 +0800 Subject: [PATCH 065/116] =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E4=B8=AD=E6=B3=A8?= =?UTF-8?q?=E6=98=8E=E2=80=9C=E6=A0=87=E5=87=86=E5=BA=93=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 138 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 110 insertions(+), 28 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 10c1a72..81fce7f 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -20,7 +20,9 @@

re

-正则表达式的标准库,提供基于正则的匹配和替换。 +【标准库】 + +提供基于正则的匹配和替换。 === 1.1.2 字符集 === @@ -42,12 +44,16 @@ print(chardet.detect(bytes))

StringIO & cStringIO

+【标准库】 + 以读写文件的方式来操作字符串(有点类似于内存文件)。 cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现的,提供 Unicode 兼容性。

difflib

+【标准库】 + 可以对两个字符串进行“按行”比较,其功能类似于命令行的 diff。 另外还支持“最佳匹配”功能——对给定的字符串 s 和字符串列表 l,在 l 里面找到最接近 s 的字符串。 @@ -60,7 +66,9 @@ cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现

base64

-标准库,提供 Base16、Base32、Base64 格式的编码和解码。 +【标准库】 + +提供 Base16、Base32、Base64 格式的编码和解码。 === 1.2.2 UUencode === @@ -68,7 +76,9 @@ cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现

uu

-标准库,提供 UUencode 格式的编码和解码。 +【标准库】 + +提供 UUencode 格式的编码和解码。 === 1.2.3 BinHex === @@ -76,16 +86,22 @@ cStringIO 是 C 语言实现的,性能更高;而 StringIO 是 Python 实现

binhex

-标准库,提供 BinHex 格式的编码和解码。 +【标准库】 + +提供 BinHex 格式的编码和解码。 == 1.3 数学类 ==

math

+【标准库】 + 顾名思义,这个标准库封装了常用的数学函数(开方、指数、对数、三角函数......)。

random

+【标准库】 + 顾名思义,这个标准库是用来进行随机数生成滴。 代码示例——生成 0-100 的随机数 @@ -97,7 +113,9 @@ random.randint(0, 100)

fractions

-这个标准库封装了跟有理数(分数)相关的运算 +【标准库】 + +封装了跟有理数(分数)相关的运算 == 1.4 容器 == @@ -191,11 +209,15 @@ Home:[http://pyobjc.sourceforge.net/]

os

-这是一个非常基本的标准库,提供了常见的操作系统相关功能,很多功能是针对文件系统。 +【标准库】 + +这是非常基本的标准库,提供了常见的操作系统相关功能,很多功能是针对文件系统。

shutil

-相对于 os 标准库,shutil 标准库提供了一些比较高级的文件和目录操作(目录递归复制、目录递归删除、目录压缩打包...) +【标准库】 + +相对于 os 而言,shutil 提供了一些比较高级的文件和目录操作(目录递归复制、目录递归删除、目录压缩打包...) 代码示例——递归删除某个目录 @@ -205,7 +227,9 @@ shutil.rmtree(xxxx)

glob

-这个标准库用于查找文件,【支持通配符】(* 和 ?) +【标准库】 + +用于查找文件,【支持通配符】(* 和 ?) 代码示例——获取当前目录所有 txt 文件 @@ -216,7 +240,9 @@ for file in glob.glob("./*.txt") :

fnmatch

-这个标准库用于匹配文件名(支持通配符,类似上面的 glob) +【标准库】 + +用于匹配文件名(支持通配符,类似上面的 glob) 代码示例——列出当前目录所有 txt 文件 @@ -229,7 +255,9 @@ for file in os.listdir(".") :

tempfile

-使用这个标准库,可以安全地生成临时文件或临时目录。 +【标准库】 + +使用它可以安全地生成临时文件或临时目录。 @@ -237,7 +265,9 @@ for file in os.listdir(".") :

threading

-这个模块提供了比较高层的线程封装 API。它本身包含了线程同步/互斥的机制。 +【标准库】 + +提供了比较高层的线程封装 API。它本身包含了线程同步/互斥的机制。 代码示例——基于“函数”的线程 @@ -275,7 +305,9 @@ if __name__ == "__main__" :

subprocess

-用于进程管理的标准库,可以启动子进程,通过标准输入输出跟子进程交互。 +【标准库】 + +用于进程管理,可以启动子进程,通过标准输入输出跟子进程交互。 代码示例——启动命令行进程,并获取该进程的标准输出 @@ -286,6 +318,8 @@ output = subprocess.check_output(["netstat", "-an"]) # 获取当前网络

multiprocessing

+【标准库】 + 它是 2.6 版本加入到标准库的,其 API 接口的风格类似于 threading 模块。 它本身包含了进程同步/互斥的机制。 @@ -309,6 +343,8 @@ if __name__ == "__main__" :

mmap

+【标准库】 + 提供了内存映射文件的支持。 代码示例——利用 mmap 在父子进程间交换数据 @@ -328,13 +364,17 @@ if pid == 0 : # 子进程

signal

+【标准库】 + 用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 == 3.5 Linux & Unix 系统相关 ==

syslog

-通过这个标准库,可以很方便地跟 POSIX 的 syslog 服务进行交互。 +【标准库】 + +通过它可以很方便地跟 POSIX 的 syslog 服务进行交互。 == 3.6 Windows 系统相关 == @@ -382,6 +422,8 @@ Home:[https://pypi.python.org/pypi/setuptools]

httplib & httplib2 & http.request & urllib.parse

+【标准库】 + 这几个库可以进行各种 HTTP 客户端请求(GET、POST、等)。 Python2 的模块名是 httplib 和 httplib2;到 Python3,模块名改为 http.request 和 urllib.parse @@ -419,6 +461,8 @@ u'{"type":"User"...'

SimpleHTTPServer & http.server

+【标准库】 + 提供轻量级 HTTP Server 的标准库。 Python2 的模块名叫 SimpleHTTPServer;到 Python3 模块名改为 http.server @@ -527,6 +571,8 @@ Home:[https://github.com/chrivers/pyjaco]

webbrowser

+【标准库】 + 操纵当前系统的默认浏览器,访问指定 URL 的页面。 代码示例——用默认浏览器打开 Google 主页 @@ -654,7 +700,9 @@ body = buffer.getvalue()

ftplib

-封装 FTP 协议(文件传输)的标准库 +【标准库】 + +封装 FTP(File Transfer Protocol)协议 代码示例——列出 FTP 服务器上某目录的内容 @@ -671,15 +719,21 @@ ftp.quit()

smtplib

-封装 SMTP 协议(邮件发送)的标准库 +【标准库】 + +封装 SMTP(Simple Mail Transfer Protocol)协议

imaplib

-封装 IMAP 协议(邮件接收)的标准库 +【标准库】 + +封装 IMAP(Internet Message Access Protocol)协议

poplib

-封装 POP3 协议(邮件接收)的标准库 +【标准库】 + +封装 POP3(Post Office Protocol v3)协议 === 5.3.5 IM === @@ -896,6 +950,8 @@ Home:[https://pypi.python.org/pypi/ibm_db]

sqlite3

+【标准库】 + sqlite3 从 Python 2.5 版本开始加入到标准库中。通过它,你可以很方便地操作 SQLite 数据库。 [https://en.wikipedia.org/wiki/SQLite SQLite] 是一个很优秀的轻量级数据库,俺前几年写过一篇博文推荐它(在“[https://program-think.blogspot.com/2009/04/how-to-use-sqlite.html 这里]”)。 @@ -1016,6 +1072,8 @@ Person.createTable()

Tkinter & tkinter

+【标准库】 + 这是 Python 内置的标准库,封装了 Tcl/Tk 界面库。 Python2 的模块名叫 Tkinter,到 Python3 模块名改为 tkinter @@ -1276,6 +1334,8 @@ Home:[http://code.enthought.com/chaco/]

hashlib

+【标准库】 + 在 Python 2.5 版本加入到标准库中。通过它,你可以很方便地计算各种散列值。 它支持的哈希算法有:MD5 SHA1 SHA224 SHA256 SHA384 SHA512 @@ -1327,14 +1387,18 @@ Home:[https://github.com/google/oauth2client] [https://en.wikipedia.org/wiki/Comma-separated_values CSV] 是一种历史悠久的结构化数据存储格式。其效果类似于一张数据库二维表。

csv

-标准库,提供 CSV 格式文件的读写。 +【标准库】 + +提供 CSV 格式文件的读写,可以手动指定行列分隔符。 === 9.1.2 JSON === JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。

json

-标准库,提供 JSON 格式的编码和解码。 +【标准库】 + +提供 JSON 格式的编码和解码。 代码示例——编码/解码 JSON 字符串 @@ -1366,29 +1430,39 @@ pyyaml 提供了 Python 对 YAML 的封装。

zipfile

-处理 zip 格式的标准库。 +【标准库】 + +提供对 zip 格式的读写。 === 9.2.2 bzip2(bz2) ===

bz2

-处理 bzip2 格式的标准库。 +【标准库】 + +提供对 bzip2 格式的读写。 === 9.2.3 gzip(gz) ===

gzip

-处理 gzip 格式的标准库。 +【标准库】 + +提供对 gzip 格式的读写。

zlib

-处理 gzip 格式的标准库。 +【标准库】 + +提供对 zlib 格式的读写。 === 9.2.4 tar ===

tarfile

-处理 tar 格式的标准库。 +【标准库】 + +提供对 tar 格式的读写。 === 9.2.5 7zip(7z) === @@ -1410,7 +1484,9 @@ Home:[http://rarfile.berlios.de/]

msilib

-处理 msi 格式的标准库,从 Python 2.5 版本开始提供。 +【标准库】 + +提供对 msi 格式的读写,从 Python 2.5 版本开始加入标准库。 == 9.3 标记语言 == @@ -1418,11 +1494,15 @@ Home:[http://rarfile.berlios.de/]

xml.dom & xml.miniDom & xml.etree.ElementTree

-用 DOM(Document Object Model)方式处理 XML 文件的标准库。 +【标准库】 + +用 DOM(Document Object Model)方式处理 XML 文件。

xml.sax & xml.parsers.expat

-用 SAX(Simple API for XML)方式处理 XML 文件的标准库。 +【标准库】 + +用 SAX(Simple API for XML)方式处理 XML 文件。

lxml

@@ -1436,7 +1516,9 @@ Home:[http://lxml.de/]

HTMLParser

-以回调方式解析 HTML/XHTML 文件内容的标准库。 +【标准库】 + +以回调方式解析 HTML/XHTML 文件内容。 == 9.4 PDF == From f924371770a315e2f461b34f26d7ec23036f0061 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 21 May 2016 22:35:51 +0800 Subject: [PATCH 066/116] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BA=94=E7=94=A8?= =?UTF-8?q?=E5=B1=82=E7=BD=91=E7=BB=9C=E5=8D=8F=E8=AE=AE=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 81fce7f..0bffb9f 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -696,7 +696,7 @@ body = buffer.getvalue() (关于“HTTP 协议”,请参见另一个大类:“Web”) -=== 5.3.3 FTP === +=== 5.3.3 文件传输 ===

ftplib

@@ -715,7 +715,7 @@ ftp.retrlines("LIST") # 列出当前目录的内容 ftp.quit() -=== 5.3.4 Email === +=== 5.3.4 电子邮件 ===

smtplib

@@ -735,7 +735,7 @@ ftp.quit() 封装 POP3(Post Office Protocol v3)协议 -=== 5.3.5 IM === +=== 5.3.5 即时通讯 ===

jabber.py

From 0278826104227b3b183dcab3d50c82a0f79e3d83 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 21 May 2016 22:45:12 +0800 Subject: [PATCH 067/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20telnetlib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 0bffb9f..9a9a3a3 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -749,6 +749,38 @@ Home:[https://bitbucket.org/jaraco/irc] IRC 是 Internet Relay Chat 的缩写。这是用 Python 封装的第三方库。 +=== 5.3.6 远程控制 === + +

telnetlib

+ +【标准库】 + +封装 telnet 协议 + +代码示例——使用 telnet 登录到某个主机并执行简单命令 + +import telnetlib +import getpass + +host = raw_input("Enter remote host: ") +user = raw_input("Enter your remote account: ") +password = getpass.getpass() + +tn = telnetlib.Telnet(host) + +tn.read_until("login: ") +tn.write(user + "\n") + +if password : + tn.read_until("Password: ") + tn.write(password + "\n") + +tn.write("ls\n") +tn.write("exit\n") + +print tn.read_all() + + == 5.4 自定义的应用层 ==

Protocol Buffers

From 86dabe460786d18340fb48f673f9b40adf3a3b93 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 21 May 2016 22:56:28 +0800 Subject: [PATCH 068/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20rdpy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 9a9a3a3..fc2d9f5 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -781,6 +781,12 @@ tn.write("exit\n") print tn.read_all() +

rdpy

+ +Home:[https://github.com/citronneur/rdpy] + +纯 Python 实现的 RDP([https://en.wikipedia.org/wiki/Remote_Desktop_Protocol 微软远程桌面协议])和 VNC([https://en.wikipedia.org/wiki/Virtual_Network_Computing Virtual Network Computing])客户端,依赖于 Twisted 库 + == 5.4 自定义的应用层 ==

Protocol Buffers

From 516ee93f7bc793d14e382a789ba660fba922fbc1 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 21 May 2016 23:05:51 +0800 Subject: [PATCH 069/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20urlparse?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index fc2d9f5..ef0d82c 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -787,6 +787,14 @@ Home:[https://github.com/citronneur/rdpy] 纯 Python 实现的 RDP([https://en.wikipedia.org/wiki/Remote_Desktop_Protocol 微软远程桌面协议])和 VNC([https://en.wikipedia.org/wiki/Virtual_Network_Computing Virtual Network Computing])客户端,依赖于 Twisted 库 +=== 5.3.7 (其它) === + +

urlparse

+ +【标准库】 + +用于解析 URL,提取各个部分的内容。从 Python 2.5 版本开始加入到标准库中,从 Python 2.7 开始支持包含 IPv6 的 URL + == 5.4 自定义的应用层 ==

Protocol Buffers

@@ -1861,7 +1869,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia ---- -= 13 其它 = += 13 (其它) = 一些不方便归类的,暂时放到这里。 From bd6f17824453aadb43561bdfc4542f56dd2419f3 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 21 May 2016 23:21:54 +0800 Subject: [PATCH 070/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20pysftp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index ef0d82c..cf9e33e 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -715,6 +715,22 @@ ftp.retrlines("LIST") # 列出当前目录的内容 ftp.quit() +

pysftp

+ +Home:[https://bitbucket.org/dundeemt/pysftp] + +封装 [https://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol SFTP] 协议,依赖于 ssh.py + +代码示例——简单的上传/下载 + +import pysftp + +with pysftp.Connection("hostxxx", username="userxxx", password="xxxxxx") as sftp : + with sftp.cd("public") # 服务端当前目录切换到 public + sftp.put("/my/local/filename") # 上传某个本地文件到服务端的 public 目录 + sftp.get_r("myfiles", "/local") # 递归复制某个服务端的目录到本地 + + === 5.3.4 电子邮件 ===

smtplib

@@ -772,8 +788,8 @@ tn.read_until("login: ") tn.write(user + "\n") if password : - tn.read_until("Password: ") - tn.write(password + "\n") + tn.read_until("Password: ") + tn.write(password + "\n") tn.write("ls\n") tn.write("exit\n") From 19219dfa449c6b52807408c643d3f2588ed92251 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 16 Jul 2016 22:30:59 +0800 Subject: [PATCH 071/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20nanomsg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 53be113..c5a7fea 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1552,7 +1552,7 @@ Home:[http://www.zeromq.org/] Wikipedia:[https://en.wikipedia.org/wiki/ZeroMQ 英文]、[https://zh.wikipedia.org/wiki/%C3%98MQ 中文] -ZeroMQ 是一个轻量级、跨平台的开源库,提供了高性能、异步的消息队列。它提供了多种语言的绑定(包括 C 和 C++)。 +ZeroMQ 是一个轻量级、跨平台的开源库,提供了高性能、异步的消息队列。采用 C++ 开发,提供了多种语言的绑定。 与传统的消息中间件不同,使用 ZeroMQ 不需要额外的“消息代理(message broker)”。 @@ -1584,6 +1584,50 @@ int main(int argc, char* argv[]) } +

nanomsg

+ +Home:[http://nanomsg.org/] + +很类似 ZeroMQ 的库,比 ZMQ 更加轻量级。采用 C 开发,提供了多种语言的绑定。 + +API 完全参照 BSD socket 的风格和语义。 + +代码示例——Request/Reply + +#include +#include +#include +#include +#include + +int reply(const char* url) +{ + int sock = nn_socket(AF_SP, NN_PULL); + assert(sock >= 0); + assert(nn_bind(sock, url) >= 0); + while(1) + { + char* msg = NULL; + int bytes = nn_recv(sock, &msg, NN_MSG, 0); + assert(bytes >= 0); + printf("RECEIVED:\n%s\n", msg); + nn_freemsg(msg); + } +} + +int request(const char* url, const char* msg) +{ + int sz_msg = strlen(msg) + 1; // '\0' + int sock = nn_socket(AF_SP, NN_PUSH); + assert(sock >= 0); + assert(nn_connect(sock, url) >= 0); + printf("SENDING:\n%s\n", msg); + int bytes = nn_send(sock, msg, sz_msg, 0); + assert(bytes == sz_msg); + return nn_shutdown(sock, 0); +} + +

ICE(Internet Communications Engine)

Home:[https://zeroc.com/] From 8d2fb83e88f53db10d4d5a6708cac53ad1a97817 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 16 Jul 2016 22:45:24 +0800 Subject: [PATCH 072/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20PyZMQ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index cf9e33e..5f3b0d4 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -884,6 +884,14 @@ gevent.joinall(jobs, timeout=2) print([job.value for job in jobs]) +

PyZMQ

+ +Home:[https://github.com/zeromq/pyzmq] + +这是 ZMQ(ZeroMQ)的 Python 封装库。同时支持 Python2 和 Python3。 + +PyZMQ 2.2 之后的版本同时支持 ZMQ 的 3.x 和 4.x 版本。 + ---- = 6 数据库 = From 1577625cd26f7c48ee7cf33a49e37ecf9585aa2c Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 16 Jul 2016 22:50:55 +0800 Subject: [PATCH 073/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20nanomsg-python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 5f3b0d4..27ea139 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -892,6 +892,27 @@ Home:[https://github.com/zeromq/pyzmq] PyZMQ 2.2 之后的版本同时支持 ZMQ 的 3.x 和 4.x 版本。 +

nanomsg-python

+ +Home:[https://github.com/tonysimpson/nanomsg-python] + +这是 nanomsg 的 Python 封装库。同时支持 Python2 和 Python3。 + +代码示例——Hello world + +from __future__ import print_function +from nanomsg import Socket, PAIR, PUB + +s1 = Socket(PAIR) +s2 = Socket(PAIR) +s1.bind("inproc://test") +s2.connect("inproc://test") +s1.send(b"hello world") +print(s2.recv()) +s1.close() +s2.close() + + ---- = 6 数据库 = From 193cca8f505eb6ad60fc5f4e6f5273d2f6f7f6d0 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 27 Jul 2016 18:15:24 +0800 Subject: [PATCH 074/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20fmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index c5a7fea..b87e89a 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -304,6 +304,28 @@ cout << format("%s %d") % "price" % 1234; // price 1234 +

fmt

+ +Home:[https://github.com/fmtlib/fmt] + +这是一个轻量级、类型安全、高性能的字符串格式化库。它也可以用来替代 C++ 标准库中的 IOStreams。 + +代码示例 + +#include +#include + +// 使用 Python 的格式化语法 +fmt::print("Hello, {}!", "world"); +// 使用 printf 的格式化语法 +fmt::printf("Hello, %s!", "world"); +// 使用序号参数, +std::string s = fmt::format("{0} {1} {0}", "Hello", "world"); +// 使用命名参数 +fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.", + fmt::arg("name", "World"), fmt::arg("number", 42)); + + === 2.3.3 正则表达式 ===

PCRE(Perl Compatible Regular Expressions)

From d928d2bddf48e63e317745f0f29c5170c55f41b3 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 27 Jul 2016 18:31:15 +0800 Subject: [PATCH 075/116] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=88=86=E7=B1=BB?= =?UTF-8?q?=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index b87e89a..b4ca3c8 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1076,7 +1076,7 @@ POCO 前面已经介绍过。它提供了相应的封装类(WinService), ---- -= 6 GUI = += 6 图形用户界面(GUI) = == 6.1 GUI 框架 == From c44d03fe8636d5b93defc65f4c45e7211ebd494d Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 27 Jul 2016 18:44:35 +0800 Subject: [PATCH 076/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Boost.Program=5Fop?= =?UTF-8?q?tions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 164 ++++++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 77 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index b4ca3c8..a0a9a02 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1297,9 +1297,19 @@ Home:[http://wxmathplot.sourceforge.net/] ---- -= 7 网络 = += 7 文本用户界面(TUI) = -== 7.1 链路层 & 网络层 == +== 7.1 命令行参数 == + +

Boost.Program_options

+ +Docs:[http://boost.org/libs/program_options] + +Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“处理命令行参数”的功能。 + += 8 网络 = + +== 8.1 链路层 & 网络层 ==

libpcap

@@ -1374,7 +1384,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Pcap 英文] 它是 libpcap 在 Windows 系统下的移植。 -== 7.2 传输层 == +== 8.2 传输层 ==

socket

@@ -1400,9 +1410,9 @@ Docs:[http://pocoproject.org/docs/Poco.Net.html] POCO 前面已经介绍过。它提供了针对 TCP 服务端的封装类。 -== 7.3 标准的应用层 == +== 8.3 标准的应用层 == -=== 7.3.1 综合性的库 === +=== 8.3.1 综合性的库 ===

cURL & libcurl

@@ -1465,11 +1475,11 @@ Docs:[http://pocoproject.org/docs/Poco.Net.html] POCO 前面已经介绍过。它提供了几种常见应用层协议(HTTP、SMTP、POP3、FTP、NTP ...)的封装类。 -=== 7.3.2 HTTP === +=== 8.3.2 HTTP === (关于“HTTP 协议”,请参见另一个大类:“Web 相关”) -=== 7.3.3 DNS === +=== 8.3.3 DNS ===

c-ares

@@ -1479,7 +1489,7 @@ Home:[http://c-ares.haxx.se/] 对比官网域名可知,它跟 cURL 是一家子。除了 cURL/libcurl 用到它,还有一些知名开源项目(比如:Wireshark、node.js ...)用到它。 -=== 7.3.4 XMPP === +=== 8.3.4 XMPP === ([https://zh.wikipedia.org/wiki/XMPP XMPP] 的洋文全称是“Extensible Messaging and Presence Protocol”。这是一个标准化的 IM 交互协议) @@ -1497,7 +1507,7 @@ Home:[https://github.com/qxmpp-project/qxmpp] 这是一个 C++ 语言开发的 XMPP 封装库。从它的名称可以看出——依赖了 Qt 框架(需要 Qt 4.5 或更高版本)。 -== 7.4 自定义的应用层 == +== 8.4 自定义的应用层 ==

Protocol Buffers

@@ -1523,7 +1533,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] (在这个方面,它有点类似于 Google 的 Protocol Buffers) -== 7.5 网络库、框架、中间件 == +== 8.5 网络库、框架、中间件 ==

Boost.Asio

@@ -1776,9 +1786,9 @@ Dlib 前面已经介绍过。它针对网络通讯,提供了比较高的抽象 ---- -= 8 数据库 = += 9 数据库 = -== 8.1 开源数据库 == +== 9.1 开源数据库 ==

MySQL

@@ -1868,9 +1878,9 @@ Home:[http://www.scylladb.com/] 号称性能提高10倍,并且延迟极低。 -== 8.2 数据库 API 的封装库 == +== 9.2 数据库 API 的封装库 == -=== 8.2.1 综合性的封装库 === +=== 9.2.1 综合性的封装库 ===

OTL

@@ -1922,7 +1932,7 @@ int main() } -=== 8.2.2 MySQL 封装库 === +=== 9.2.2 MySQL 封装库 ===

MySQL Connector C++

@@ -1992,7 +2002,7 @@ Docs:[http://pocoproject.org/docs/package-MySQL.MySQL.html] POCO 前面已经介绍过。它提供了 MySQL 的封装类 -=== 8.2.3 PostgreSQL 封装库 === +=== 9.2.3 PostgreSQL 封装库 ===

libpq

@@ -2036,7 +2046,7 @@ void update(const std::string& name) } -=== 8.2.4 Oracle 封装库 === +=== 9.2.4 Oracle 封装库 ===

OCILIB

@@ -2076,9 +2086,9 @@ int main() } -=== 8.2.5 DB2 封装库 === +=== 9.2.5 DB2 封装库 === -=== 8.2.6 SQLite 封装库 === +=== 9.2.6 SQLite 封装库 ===

官方的 C API

@@ -2137,7 +2147,7 @@ Docs:[http://pocoproject.org/docs/package-SQLite.SQLite.html] POCO 前面已经介绍过。它提供了 sqlite 的封装类 -=== 8.2.7 Redis 封装库 === +=== 9.2.7 Redis 封装库 ===

Hiredis

@@ -2209,7 +2219,7 @@ int main(int argc, char* argv[]) } -=== 8.2.8 MongoDB 封装库 === +=== 9.2.8 MongoDB 封装库 ===

官方的 C API

@@ -2257,7 +2267,7 @@ Docs:[http://pocoproject.org/docs/package-MongoDB.MongoDB.html] POCO 前面已经介绍过。它提供了 MongoDB 的封装类 -== 8.3 ODBC 相关 == +== 9.3 ODBC 相关 ==

unixODBC

@@ -2279,7 +2289,7 @@ Docs:[http://pocoproject.org/docs/package-ODBC.ODBC.html] POCO 前面已经介绍过。它提供了操作 ODBC 的封装类。 -== 8.4 ORM(Object-Relational Mapping) == +== 9.4 ORM(Object-Relational Mapping) ==

ODB

@@ -2340,9 +2350,9 @@ Home:[https://github.com/paulftw/hiberlite] ---- -= 9 Web = += 10 Web = -== 9.1 HTTP Server == +== 10.1 HTTP Server ==

Apache HTTP Server

@@ -2372,7 +2382,7 @@ Docs:[http://dlib.net/network.html#server_http] Dlib 前面已经介绍过。它提供了一个简单的 HTTP Server 的类(server_http)。 -== 9.2 HTTP Client == +== 10.2 HTTP Client ==

cURL & libcurl

@@ -2415,7 +2425,7 @@ Docs:[http://pocoproject.org/docs/package-Net.HTTPClient.html] POCO 前面已经介绍过。它提供了 HTTP Client 的封装类。 -== 9.3 浏览器引擎 == +== 10.3 浏览器引擎 ==

WebKit

@@ -2433,7 +2443,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Gecko_(software) 英文]、[https://z 它是 Firefox 的渲染引擎,基于 C++ 开发,由 Mozilla 社区维护。 -== 9.4 浏览器整合 == +== 10.4 浏览器整合 ==

CEF(Chromium Embedded Framework)

@@ -2469,7 +2479,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/PhantomJS 英文] 它本身没有提供 GUI 界面。但是提供了 JavaScript 的 API,让你可以操纵 WebKit 引擎。可以利用它进行 Web 界面的单元测试。 -== 9.5 (其它) == +== 10.5 (其它) ==

WebSocket++

@@ -2481,9 +2491,9 @@ Home:[http://www.zaphoyd.com/websocketpp/] ---- -= 10 信息安全 = += 11 信息安全 = -== 10.1 密码学 == +== 11.1 密码学 ==

Crypto++

@@ -2599,11 +2609,11 @@ POCO 前面已经介绍过。它提供了常见的加密算法和哈希算法。 ---- -= 11 处理文件格式 = += 12 处理文件格式 = -== 11.1 结构化数据格式 == +== 12.1 结构化数据格式 == -=== 11.1.1 CSV === +=== 12.1.1 CSV === [https://en.wikipedia.org/wiki/Comma-separated_values CSV] 是一种历史悠久的结构化数据存储格式。其效果类似于一张数据库二维表。 @@ -2613,7 +2623,7 @@ Docs:[http://boost.org/libs/tokenizer] Boost 前面已经介绍过。这是 Boost 的其中一个子库,用来灵活地切割字符串。使用它,可以帮你提取 CSV 的行和列。 -=== 11.1.2 JSON === +=== 12.1.2 JSON === JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。 @@ -2667,7 +2677,7 @@ Home:[https://github.com/open-source-parsers/jsoncpp] 如其名,这是个 C++ 的 JSON 封装库。 -=== 11.1.3 YAML === +=== 12.1.3 YAML === [https://en.wikipedia.org/wiki/YAML YAML] 是一种类似于 json 的结构化数据格式。它在确保可读性的基础上,提供了超越 json 的灵活性和扩展性。 @@ -2683,9 +2693,9 @@ Home:[http://pyyaml.org/wiki/LibYAML] C 语言实现的 YAML 解析器。 -== 11.2 压缩文件 & 打包文件 == +== 12.2 压缩文件 & 打包文件 == -=== 11.2.1 综合性的库 === +=== 12.2.1 综合性的库 ===

libarchive

@@ -2723,7 +2733,7 @@ Home:[https://github.com/google/zopfli] 压缩的速度比较慢,但是可以得到更高的压缩率。 -=== 11.2.2 zip === +=== 12.2.2 zip === [https://en.wikipedia.org/wiki/Zip_%28file_format%29 格式说明] @@ -2741,7 +2751,7 @@ Docs:[http://pocoproject.org/docs/Poco.Zip.html] POCO 前面已经介绍过。它提供了若干封装类,用于 zip 格式的压缩和解压。 -=== 11.2.3 bzip2(bz2) === +=== 12.2.3 bzip2(bz2) === [https://en.wikipedia.org/wiki/Bzip2 格式说明] @@ -2751,7 +2761,7 @@ Home:[http://bzip.org/] 这是 bzip2 官方提供的库,C 语言实现。 -=== 11.2.4 gzip(gz) === +=== 12.2.4 gzip(gz) ===

zlib

@@ -2761,7 +2771,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Zlib 英文]、[https://zh.wikipedia. C 语言实现,诞生于1995年,被大量的开源项目使用(OpenSSL、OpenSSH、Apache、PostgreSQL、Git、libpng......)。 -=== 11.2.5 tar === +=== 12.2.5 tar ===

libtar

@@ -2769,7 +2779,7 @@ Home:[http://www.feep.net/libtar/] 基于 C 语言开发,可以对 tar 格式添加内容或读取内容。 -=== 11.2.6 rar === +=== 12.2.6 rar ===

unrarlib

@@ -2777,7 +2787,7 @@ Home:[http://www.unrarlib.org/] 该项目的开发已经停止。只支持对 RAR2 格式的解压缩。 -=== 11.2.7 snappy === +=== 12.2.7 snappy ===

snappy

@@ -2789,7 +2799,7 @@ Home:[https://google.github.io/snappy/] 支持多种语言的绑定(C#、Common Lisp、Erlang、Go、Haskell、Lua、Java、Node.js、Perl、PHP、Python、R、Ruby、Smalltalk) -=== 11.2.8 Brotli === +=== 12.2.8 Brotli ===

Brotli

@@ -2801,9 +2811,9 @@ Wikipedia:[https://en.wikipedia.org/wiki/Brotli 英文] 该算法很新,是2015年9月才发布的。 -== 11.3 标记语言 == +== 12.3 标记语言 == -=== 11.3.1 XML === +=== 12.3.1 XML ===

Expat

@@ -2839,7 +2849,7 @@ Home:[http://libxmlplusplus.sourceforge.net/] 如其名,它是针对前面提到的 libxml2 的 C++ 封装。 -=== 11.3.2 HTML === +=== 12.3.2 HTML ===

htmlcxx

@@ -2847,7 +2857,7 @@ Home:[http://htmlcxx.sourceforge.net/] 如其名,是基于 C++ 开发的。支持 HTML 和 CSS 的解析。 -== 11.4 PDF == +== 12.4 PDF ==

PoDoFo

@@ -2894,7 +2904,7 @@ HPDF_SaveToFile(doc, "test.pdf"); HPDF_Free(doc); -== 11.5 MS Office 文档 == +== 12.5 MS Office 文档 ==

wvWare

@@ -2904,7 +2914,7 @@ Home:[http://wvware.sourceforge.net/] AbiWord 和 KWord 用到它。 -== 11.6 RTF == +== 12.6 RTF ==

LibRTF

@@ -2912,7 +2922,7 @@ Home:[http://sourceforge.net/projects/librtf/] C 语言实现的库,可以解析 RTF 文件格式。 -== 11.7 CHM == +== 12.7 CHM ==

CHMLIB

@@ -2930,9 +2940,9 @@ Home:[http://www.mare.ee/indrek/libchmxx/] ---- -= 12 图像 = += 13 图像 = -== 12.1 图像处理 == +== 13.1 图像处理 ==

ImageMagick

@@ -2975,7 +2985,7 @@ Docs:[http://dlib.net/imaging.html] Dlib 前面已经介绍过。它提供了常见的图像处理功能(旋转、剪切、拉伸、过滤)。 -== 12.2 图像格式转换 == +== 13.2 图像格式转换 ==

ImageMagick

@@ -2983,7 +2993,7 @@ ImageMagick 前面已经介绍过。它支持非常多的图片格式([http:// 在支持的格式中,它可以实现其中几十种格式的相互转换。 -== 12.3 图像渲染 == +== 13.3 图像渲染 ==

Cairo

@@ -3017,7 +3027,7 @@ Home:[http://pbrt.org/] 基于光线追踪的物理渲染系统,采用 C++ 开发。 -== 12.4 计算机视觉 == +== 13.4 计算机视觉 ==

OpenCV

@@ -3031,9 +3041,9 @@ Wikipedia:[https://en.wikipedia.org/wiki/OpenCV 英文]、[https://zh.wikipedi ---- -= 13 多媒体 = += 14 多媒体 = -== 13.1 多媒体框架 == +== 14.1 多媒体框架 ==

FFmpeg

@@ -3063,7 +3073,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Libav 英文] 它是2011年从 FFmpeg 派生出来的。基于 C 语言开发,支持多种操作系统。 -== 13.2 视频库 == +== 14.2 视频库 ==

libavcodec

@@ -3073,7 +3083,7 @@ Home:[http://ffmpeg.org/] 由于 Libav 从 FFmpeg 分裂出来,Libav 下也带有一个同名的库。 -== 13.3 音频库 == +== 14.3 音频库 ==

PortMedia & PortAudio

@@ -3093,9 +3103,9 @@ C 语言开发的 3D 音效库,跨平台。最初由 Loki Software 开发。Lo ---- -= 14 游戏 = += 15 游戏 = -== 14.1 综合性的游戏引擎 == +== 15.1 综合性的游戏引擎 ==

id Tech 系列

@@ -3141,7 +3151,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Panda3D 英文] 以 C++ 编写,用 Python 脚本扩展。虽然它的名字有“3D”,但它不仅仅是 3D 引擎,还包括了其它功能(碰撞检测、音效、关卡编辑器...)。 -== 14.2 3D 渲染引擎 == +== 15.2 3D 渲染引擎 ==

OGRE

@@ -3161,7 +3171,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Mesa_%28computer_graphics%29 英文] 使用 C 语言开发,它是针对 OpenGL 规范的【纯软件】实现(大部分 OpenGL 的实现都用到了显卡硬件)。 -== 14.3 物理引擎 == +== 15.3 物理引擎 ==

Bullet

@@ -3197,9 +3207,9 @@ Wikipedia:[https://en.wikipedia.org/wiki/Newton_Game_Dynamics 英文] ---- -= 15 数值运算 & 科学计算 = += 16 数值运算 & 科学计算 = -== 15.1 综合性的库 == +== 16.1 综合性的库 ==

GSL(GNU Scientific Library)

@@ -3219,7 +3229,7 @@ double y = gsl_sf_bessel_J0(x); printf("J0(%g) = %.18e\n", x, y); -== 15.2 有理数 == +== 16.2 有理数 ==

Boost.Rational

@@ -3227,7 +3237,7 @@ Docs:[http://boost.org/libs/rational] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“有理数”的功能。 -== 15.3 高精度数值运算 == +== 16.3 高精度数值运算 ==

GMP(GNU Multiple Precision)

@@ -3263,7 +3273,7 @@ Docs:[http://boost.org/libs/multiprecision] Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了高精度数值运算。它还提供了针对 GMP 的数据类型的封装。 -== 15.4 矩阵 == +== 16.4 矩阵 ==

Boost.uBLAS.Matrix

@@ -3292,7 +3302,7 @@ Docs:[http://dlib.net/linear_algebra.html#matrix] Dlib 前面已经介绍过。它提供了一个矩阵类。 -== 15.5 线性代数 == +== 16.5 线性代数 ==

Boost.uBLAS

@@ -3363,9 +3373,9 @@ Dlib 前面已经介绍过。它提供了线性代数相关的封装类。 ---- -= 16 跨语言编程 = += 17 跨语言编程 = -== 16.1 整合多种语言的库 == +== 17.1 整合多种语言的库 ==

SWIG

@@ -3377,9 +3387,9 @@ Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] 整合之后,你的 C/C++ 程序就可以享受到其它这些语言的特性啦,非常爽! -== 16.2 整合单一语言的库 == +== 17.2 整合单一语言的库 == -=== 16.2.1 整合 Python 语言 === +=== 17.2.1 整合 Python 语言 ===

Boost.Python

@@ -3410,11 +3420,11 @@ BOOST_PYTHON_MODULE(hello_ext) ---- -= 17 (其它) = += 18 (其它) = 一些不方便归类的,暂时放到这里。 -== 17.1 词法分析 & 语法分析 == +== 18.1 词法分析 & 语法分析 ==

Boost.Spirit

From ab54928fcfb590c12e49154f417ef90c3d3d89a0 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 27 Jul 2016 19:05:33 +0800 Subject: [PATCH 077/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20ncurses?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index a0a9a02..b36ce33 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1307,6 +1307,18 @@ Docs:[http://boost.org/libs/program_options] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“处理命令行参数”的功能。 +== 7.2 文本终端 == + +

ncurses

+ +Home:[https://www.gnu.org/software/ncurses/] + +Wikipedia:[https://en.wikipedia.org/wiki/Ncurses 英文]、[https://zh.wikipedia.org/wiki/Ncurses 中文] + +ncurses 是“new curses”的缩略词,它是 [https://en.wikipedia.org/wiki/Curses_(programming_library) curses] 库的自由软件克隆,诞生于1993年。 + +大名鼎鼎的 [https://en.wikipedia.org/wiki/Eric_S._Raymond Eric S. Raymond] 曾参与早期版本的开发。 + = 8 网络 = == 8.1 链路层 & 网络层 == From e6dcdd25ef6017eca30b273b8385b6a227c29c22 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 27 Jul 2016 19:30:46 +0800 Subject: [PATCH 078/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20getopt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index b36ce33..a89f305 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1301,12 +1301,86 @@ Home:[http://wxmathplot.sourceforge.net/] == 7.1 命令行参数 == +

getopt

+ +Home:[https://www.gnu.org/software/libc/manual/html_node/Getopt.html] + +Wikipedia:[https://en.wikipedia.org/wiki/Getopt 英文] + +这是标准C用来处理命令行参数的老牌函数,诞生于上世纪80年代初期。 + +它有很多种不同的实现,如今用得最多的是 GNU C Library 的实现。GNU 还实现了一个增强版 getopt_long。 + +代码示例 + +#include /* for printf */ +#include /* for exit */ +#include /* for getopt */ +int main(int argc, char** argv) +{ + int digit_optind = 0; + int aopt = 0, bopt = 0; + char* copt = NULL; + char* dopt = NULL; + int c; + while( (c = getopt(argc, argv, "abc:d:012")) != -1) + { + int this_option_optind = optind ? optind : 1; + switch(c) + { + case '0': + case '1': + case '2': + if(digit_optind != 0 && digit_optind != this_option_optind) + { + printf("digits occur in two different argv-elements.\n"); + } + digit_optind = this_option_optind; + printf("option %c\n", c); + break; + case 'a': + printf("option a\n"); + aopt = 1; + break; + case 'b': + printf("option b\n"); + bopt = 1; + break; + case 'c': + printf("option c with value '%s'\n", optarg); + copt = optarg; + break; + case 'd': + printf("option d with value '%s'\n", optarg); + dopt = optarg; + break; + case '?': + break; + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } + if(optind < argc) + { + printf("non-option ARGV-elements: "); + while(optind < argc) + { + printf("%s ", argv[optind++]); + } + printf("\n"); + } + exit (0); +} + +

Boost.Program_options

Docs:[http://boost.org/libs/program_options] Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“处理命令行参数”的功能。 +它的功能很丰富,但是比较重型。 + == 7.2 文本终端 ==

ncurses

From 7642bda6930ea39356615f683e21607c3981f997 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 15 Feb 2017 23:58:05 +0800 Subject: [PATCH 079/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20LZFSE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index a89f305..b434cda 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2897,6 +2897,18 @@ Wikipedia:[https://en.wikipedia.org/wiki/Brotli 英文] 该算法很新,是2015年9月才发布的。 +=== 12.2.9 LZFSE === + +

LZFSE

+ +Home:[https://github.com/lzfse/lzfse] + +Wikipedia:[https://zh.wikipedia.org/wiki/LZFSE 中文] + +由苹果开发的压缩格式。苹果称它的压缩率与“ZLib level 5”相似,但速度快2至3倍。 + +该算法是前不久(2016年7月)才开源出来的。 + == 12.3 标记语言 == === 12.3.1 XML === From ec4d2d8d27d3059f27328fa210d7c219e36ecc75 Mon Sep 17 00:00:00 2001 From: programthink Date: Thu, 16 Feb 2017 00:33:05 +0800 Subject: [PATCH 080/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20gopy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 27ea139..97ed8e8 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -193,7 +193,17 @@ Wikipedia:[https://en.wikipedia.org/wiki/IronPython 英文]、[https://zh.wiki 通过 IronPython 可以让 Python 代码运行在 dotNET 平台上,并且可以调用其它的 dotNET 语言的代码(C#、F#、VB.Net ...) -== 2.4 整合 Objective-C 语言 == +== 2.4 整合 Go == + +

gopy

+ +Home:[https://github.com/go-python/gopy] + +gopy 可以把 Go 源代码编译为 Python 的一个 module。 + +它提供了两种方式(命令行、Python 库)来实现:Go 源码编译为 Python 模块。 + +== 2.5 整合 Objective-C ==

PyObjC

From 905a6bc03aae748e700e26769b9b2c2b14c24d9a Mon Sep 17 00:00:00 2001 From: programthink Date: Thu, 16 Feb 2017 01:07:06 +0800 Subject: [PATCH 081/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Plyvel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 97ed8e8..bf07147 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1076,7 +1076,7 @@ Home:[https://github.com/andymccurdy/redis-py] 操作 Redis 的第三方 Python 客户端。 -代码示例——简单的 set/get +代码示例——简单的存取操作 import redis r = redis.StrictRedis(host="localhost", port=6379, db=0) @@ -1084,7 +1084,24 @@ r.set("foo", "bar") print(r.get("foo")) -=== 6.2.8 Berkeley DB === +=== 6.2.8 LevelDB === + +

Plyvel

+ +Home:[https://github.com/wbolster/plyvel] + +操作 LevelDB 的 Python 库,速度快,同时兼容 Python2 和 Python3。 + +代码示例——简单的存取操作 + +import plyvel +db = plyvel.DB("/tmp/testdb/", create_if_missing=True) +db.put(b"key", b"value") +print(db.get(b"key")) +db.close() + + +=== 6.2.9 Berkeley DB ===

PyBSDDB

From cecc7cf4350e37cac5f1ac47f3e04c6a870ca90d Mon Sep 17 00:00:00 2001 From: programthink Date: Thu, 16 Feb 2017 01:20:40 +0800 Subject: [PATCH 082/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20PyMongo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index bf07147..10be7f4 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1068,7 +1068,15 @@ conn.commit() conn.close() -=== 6.2.7 Redis === +=== 6.2.7 MongoDB === + +

PyMongo

+ +Docs:[https://docs.mongodb.com/ecosystem/drivers/python/] + +这是 MongoDB 官方提供的 Python 驱动。 + +=== 6.2.8 Redis ===

redis-py

@@ -1084,7 +1092,7 @@ r.set("foo", "bar") print(r.get("foo")) -=== 6.2.8 LevelDB === +=== 6.2.9 LevelDB ===

Plyvel

@@ -1101,7 +1109,7 @@ print(db.get(b"key")) db.close() -=== 6.2.9 Berkeley DB === +=== 6.2.10 Berkeley DB ===

PyBSDDB

From 1db701e4cfcb4f1894e2c1028e45eb55f974316a Mon Sep 17 00:00:00 2001 From: programthink Date: Thu, 16 Feb 2017 01:46:53 +0800 Subject: [PATCH 083/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20HappyBase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 10be7f4..4ec80da 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1076,7 +1076,25 @@ Docs:[https://docs.mongodb.com/ecosystem/drivers/python/] 这是 MongoDB 官方提供的 Python 驱动。 -=== 6.2.8 Redis === +=== 6.2.8 Apache HBase === + +

HappyBase

+ +Home:[https://github.com/wbolster/happybase] + +操作 HBase 的 Python 库,基于 [https://en.wikipedia.org/wiki/Apache_Thrift Thrift] 连接到 HBase。 + +代码示例——简单的存取操作 + +import happybase +connection = happybase.Connection("hostname") +table = connection.table("table-name") +table.put(b"row-key", {b"test1": b"data1", b"test2": b"data2"}) +row = table.row(b"row-key") +print(row[b"test1"]) + + +=== 6.2.9 Redis ===

redis-py

@@ -1092,7 +1110,7 @@ r.set("foo", "bar") print(r.get("foo")) -=== 6.2.9 LevelDB === +=== 6.2.10 LevelDB ===

Plyvel

@@ -1109,7 +1127,7 @@ print(db.get(b"key")) db.close() -=== 6.2.10 Berkeley DB === +=== 6.2.11 Berkeley DB ===

PyBSDDB

From 4144e313f7a8caaaa7fd1cbfee41ec7d0dff3b04 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 22 Feb 2017 22:13:48 +0800 Subject: [PATCH 084/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Pillow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 4ec80da..5c8ae8a 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1819,6 +1819,14 @@ with Image(filename="mona-lisa.png") as img : display(new_img) +

Pillow

+ +Home:[http://python-pillow.org/] + +你可以把它视作“轻量级的 PIL”。 + +它的目标是比 PIL 更容易使用,并尽可能与 PIL 的 API 兼容。 +

PyGraphviz

Home:[https://github.com/pygraphviz/pygraphviz] From 4d42aa695307f8d9ca4f5fc5f6385cf6dfa11f9a Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 22 Feb 2017 22:18:14 +0800 Subject: [PATCH 085/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Peewee?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 5c8ae8a..1efcedb 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1204,6 +1204,38 @@ class Person(SQLObject) : Person.createTable() +

Peewee

+ +Home:[http://www.peewee-orm.com/] + +一个轻量级的 ORM,支持 SQLite、MySQL 和 PostgreSQL,通过插件机制支持更多数据库。 + +同时支持 Python2 和 Python3。 + +代码示例——通过对象的方式创建表 + +from peewee import * + +db = SqliteDatabase("test.db") + +class Person(Model) : + name = CharField() + birthday = DateField() + is_relative = BooleanField() + class Meta : + database = db # This model uses the "test.db". + +class Pet(Model) : + owner = ForeignKeyField(Person, related_name="pets") + name = CharField() + animal_type = CharField() + class Meta : + database = db # This model uses the "test.db". + +db.connect() +db.create_tables([Person, Pet]) + + ---- = 7 GUI = From 64d386d4b627db7cca5b323911f4ec3e74df5d87 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 22 Feb 2017 22:24:48 +0800 Subject: [PATCH 086/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Apache=20Libcloud?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 1efcedb..b23fe96 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -923,6 +923,29 @@ s1.close() s2.close() +== 5.6 云计算 == + +

Apache Libcloud

+ +Home:[https://libcloud.apache.org/] + +如今云提供商越来越多。这个库提供了统一的 API 让你访问各大知名云提供商提供的各种服务。 + +代码示例——创建 DNS 记录 + +from libcloud.dns.types import Provider, RecordType +from libcloud.dns.providers import get_driver + +cls = get_driver(Provider.ZERIGO) +driver = cls("email", "api key") + +zones = driver.list_zones() +zone = [zone for zone in zones if zone.domain == "mydomain.com"][0] + +record = zone.create_record(name="www", type=RecordType.A, data="127.0.0.1") +print(record) + + ---- = 6 数据库 = From 39b99b116f1349f37928093deb028807e944fb57 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 22 Feb 2017 22:33:26 +0800 Subject: [PATCH 087/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20python-docx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index b23fe96..10bd3bd 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1775,6 +1775,14 @@ Home:[http://www.unixuser.org/~euske/python/pdfminer/] PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 +

python-docx

+ +Home:[https://github.com/python-openxml/python-docx] + +纯 python 实现的 docx 操作库,能够处理 docx 中的“文本、图片、样式”。 + +同时支持 Python2 和 Python3。 + === 9.5.2 Excel(xls、xlsx) ===

pyExcelerator

From c06baa82fc6f99fd8ea59eb18063e6b2e3b1da71 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 22 Feb 2017 22:41:22 +0800 Subject: [PATCH 088/116] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20PyWin32=20?= =?UTF-8?q?=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 10bd3bd..a2b30ef 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -1771,10 +1771,6 @@ Home:[http://www.unixuser.org/~euske/python/pdfminer/] === 9.5.1 Word(doc、docx) === -

PyWin32

- -PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word(本地需要安装 Office)。 -

python-docx

Home:[https://github.com/python-openxml/python-docx] @@ -1783,6 +1779,12 @@ Home:[https://github.com/python-openxml/python-docx] 同时支持 Python2 和 Python3。 +

PyWin32

+ +PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Word。 + +(本地需要安装 Office) + === 9.5.2 Excel(xls、xlsx) ===

pyExcelerator

@@ -1793,7 +1795,9 @@ Home:[http://sourceforge.net/projects/pyexcelerator/]

PyWin32

-PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 +PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel。 + +(本地需要安装 Office) === 9.5.3 Power Point(ppt、pptx) === @@ -1805,7 +1809,9 @@ Home:[https://github.com/scanny/python-pptx]

PyWin32

-PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Excel(本地需要安装 Office)。 +PyWin32 前面已经介绍过。它可以基于 [https://en.wikipedia.org/wiki/Component_Object_Model COM] 操作 Office 文档,包括 Power Point。 + +(本地需要安装 Office) == 9.6 RTF == From 3d58249aa875de008c9d1b6af0268157852ac466 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 25 Feb 2017 20:09:41 +0800 Subject: [PATCH 089/116] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index a2b30ef..8e7a667 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -161,7 +161,7 @@ MessageBox(text="Hello, world", flags=2) Home:[http://swig.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] +Links:[https://en.wikipedia.org/wiki/SWIG Wikipedia] 这是一个很老牌的、有名气的工具,它可以把多种语言(Java、Python、C#、Ruby、PHP、Perl、Lua、Go ...)整合到 C/C++ 中。 @@ -179,7 +179,7 @@ Home:[http://cython.org/] Home:[http://www.jython.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Jython 英文]、[https://zh.wikipedia.org/wiki/Jython 中文] +Links:[https://en.wikipedia.org/wiki/Jython Wikipedia] [https://zh.wikipedia.org/wiki/Jython 维基百科] 通过 Jython 可以让 Python 代码运行在 JVM 上,并且可以调用其它的 JVM 语言的代码(比如 Java、Scala) @@ -189,7 +189,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Jython 英文]、[https://zh.wikipedi Home:[http://ironpython.net/] -Wikipedia:[https://en.wikipedia.org/wiki/IronPython 英文]、[https://zh.wikipedia.org/wiki/IronPython 中文] +Links:[https://en.wikipedia.org/wiki/IronPython Wikipedia] [https://zh.wikipedia.org/wiki/IronPython 维基百科] 通过 IronPython 可以让 Python 代码运行在 dotNET 平台上,并且可以调用其它的 dotNET 语言的代码(C#、F#、VB.Net ...) @@ -408,7 +408,7 @@ PyInstaller 可以把你的 Python 代码制作成独立运行的程序(不依 Home:[http://www.py2exe.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Py2exe 英文] +Links:[https://en.wikipedia.org/wiki/Py2exe Wikipedia] py2exe 的功能类似 PyInstaller,但只支持 Windows 平台。 @@ -496,7 +496,7 @@ httpd.serve_forever() Home:[https://www.djangoproject.com/] -Wikipedia:[https://en.wikipedia.org/wiki/Django_(web_framework) 英文]、[https://zh.wikipedia.org/wiki/Django 中文] +Links:[https://en.wikipedia.org/wiki/Django_(web_framework) Wikipedia] [https://zh.wikipedia.org/wiki/Django 维基百科] 在 Python 社区,Django 是目前最有影响力的 Web 开发框架。该框架很重型,内置了 Web 服务端开发常用的组件(比如:ORM、用户管理)。 @@ -508,7 +508,7 @@ Django 应用范围很广,比如 Google 的 Web 开发平台 GAE 就支持它 Home:[http://www.turbogears.org/] -Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wikipedia.org/wiki/TurboGears 中文] +Links:[https://en.wikipedia.org/wiki/TurboGears Wikipedia] [https://zh.wikipedia.org/wiki/TurboGears 维基百科] 又一个重型的 Web 开发框架,名气仅次于 Django。 @@ -518,7 +518,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/TurboGears 英文]、[https://zh.wiki Home:[http://www.cherrypy.org/] -Wikipedia:[https://en.wikipedia.org/wiki/CherryPy 英文] +Links:[https://en.wikipedia.org/wiki/CherryPy Wikipedia] 轻量级的 Web 框架。某些 Web 框架(比如前面提到的 TurboGears)使用它作为底层。 @@ -642,7 +642,7 @@ Home:[https://github.com/google/pywebsocket] Home:[http://www.secdev.org/projects/scapy/] -Wikipedia:[https://en.wikipedia.org/wiki/Scapy 英文] +Links:[https://en.wikipedia.org/wiki/Scapy Wikipedia] 这是一个底层的网络库,可以在不同协议层次构造网络数据包(包括链路层、网络层、传输层),还支持 Sniffer 抓包。 @@ -827,7 +827,7 @@ Home:[https://github.com/citronneur/rdpy] Home:[https://developers.google.com/protocol-buffers/] -Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] +Links:[https://en.wikipedia.org/wiki/Protocol_Buffers Wikipedia] 这是 Google 开发的一个跨语言的库,用于网络传输业务数据时的“编码/解码”。 @@ -839,7 +839,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] Home:[https://thrift.apache.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] +Links:[https://en.wikipedia.org/wiki/Apache_Thrift Wikipedia] 来自于 Apache 社区,提供了一种跨语言的通讯机制。 @@ -853,7 +853,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] Home:[http://twistedmatrix.com/] -Wikipedia:[https://en.wikipedia.org/wiki/Twisted_%28software%29 英文] +Links:[https://en.wikipedia.org/wiki/Twisted_%28software%29 Wikipedia] 这是一个基于 Python 网络通讯开发框架,诞生于2002年,名气很大。 @@ -1164,7 +1164,7 @@ Home:[http://www.jcea.es/programacion/pybsddb.htm] Home:[http://www.sqlalchemy.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SQLAlchemy 英文]、[https://zh.wikipedia.org/wiki/SQLAlchemy 中文] +Links:[https://en.wikipedia.org/wiki/SQLAlchemy Wikipedia] [https://zh.wikipedia.org/wiki/SQLAlchemy 维基百科] SQLAlchemy 支持的数据库有:MySQL、PostgreSQL、Sqlite、Oracle、MS SQL Server、Firebird、Sybase SQL Server、Informix、等。 @@ -1211,7 +1211,7 @@ Base.metadata.create_all(create_engine("dbms://user:pwd@host/dbname")) Home:[http://sqlobject.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SQLObject 英文] +Links:[https://en.wikipedia.org/wiki/SQLObject Wikipedia] SQLObject 支持的数据库有:MySQL、PostgreSQL、Sqlite、MS SQL Server、Firebird、Sybase SQL Server、SAP DB、等。 @@ -1295,7 +1295,7 @@ if __name__ == "__main__" : Home:[http://www.wxpython.org/] -Wikipedia:[https://en.wikipedia.org/wiki/WxPython 英文]、[https://zh.wikipedia.org/wiki/WxPython 中文] +Links:[https://en.wikipedia.org/wiki/WxPython Wikipedia] [https://zh.wikipedia.org/wiki/WxPython 维基百科] 在所有的 wxWidgets 的 Python 封装库中,这个是名气最大的。 @@ -1333,7 +1333,7 @@ Home:[http://pythoncard.sourceforge.net/] Home:[http://www.pygtk.org/] -Wikipedia:[https://en.wikipedia.org/wiki/PyGTK 英文] +Links:[https://en.wikipedia.org/wiki/PyGTK Wikipedia] 它是 Python 对 GTK+2 的封装。 @@ -1411,7 +1411,7 @@ Gtk.main() Home:[http://www.riverbankcomputing.com/software/pyqt/] -Wikipedia:[https://en.wikipedia.org/wiki/PyQt 英文]、[https://zh.wikipedia.org/wiki/PyQt 中文] +Links:[https://en.wikipedia.org/wiki/PyQt Wikipedia] [https://zh.wikipedia.org/wiki/PyQt 维基百科] 这是 Python 对 Qt 的封装。 @@ -1495,7 +1495,7 @@ Home:[http://ocemp.sourceforge.net/gui.html] Home:[http://matplotlib.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Matplotlib 英文] +Links:[https://en.wikipedia.org/wiki/Matplotlib Wikipedia] 这是一个有名的图形库,主要用来绘制数学相关的图形。 @@ -1839,7 +1839,7 @@ Home:[http://gnochm.sourceforge.net/pychm.html] Home:[http://www.pythonware.com/products/pil/] -Wikipedia:[https://en.wikipedia.org/wiki/Python_Imaging_Library 英文] +Links:[https://en.wikipedia.org/wiki/Python_Imaging_Library Wikipedia] 这是一个很有名气的 Python 图像处理库,支持常见图像文件格式(BMP、JPG、GIF、PNG ...)。 @@ -1954,7 +1954,7 @@ Pycairo 是 Cairo 官方提供 Python 封装。 Home:[http://www.pygame.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Pygame 英文]、[https://zh.wikipedia.org/wiki/Pygame 中文] +Links:[https://en.wikipedia.org/wiki/Pygame Wikipedia] [https://zh.wikipedia.org/wiki/Pygame 维基百科] 这是名气很大的跨平台游戏引擎,构建于 [https://zh.wikipedia.org/wiki/SDL SDL](Simple DirectMedia Layer)之上。 @@ -1974,7 +1974,7 @@ Home:[http://cocos2d.org/] Home:[http://www.blender.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Game_Blender 英文]、[https://zh.wikipedia.org/wiki/Game_Blender 中文] +Links:[https://en.wikipedia.org/wiki/Game_Blender Wikipedia] [https://zh.wikipedia.org/wiki/Game_Blender 维基百科] 它是 [https://en.wikipedia.org/wiki/Blender_%28software%29 Blender] 的组成部分,虽然是以 C++ 编写,但内置了 Python 脚本的扩展。 @@ -2002,7 +2002,7 @@ Home:[http://www.python-ogre.org/] Home:[http://www.numpy.org/] -Wikipedia:[https://en.wikipedia.org/wiki/NumPy 英文]、[https://zh.wikipedia.org/wiki/NumPy 中文] +Links:[https://en.wikipedia.org/wiki/NumPy Wikipedia] [https://zh.wikipedia.org/wiki/NumPy 维基百科] 它提供了功能强大、性能很高的数值数组,可以用来进行各种数值计算(包括矩阵运算)。 @@ -2026,7 +2026,7 @@ c = a + b Home:[http://www.scipy.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SciPy 英文]、[https://zh.wikipedia.org/wiki/SciPy 中文] +Links:[https://en.wikipedia.org/wiki/SciPy Wikipedia] [https://zh.wikipedia.org/wiki/SciPy 维基百科] 它依赖 NumPy 提供的多维数组。相比 NumPy,它提供了更高层的数学运算模块(统计、线性代数、积分、常微分方程求解、傅立叶变换、信号处理 ...)。 @@ -2036,7 +2036,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/SciPy 英文]、[https://zh.wikipedia Home:[http://sympy.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia.org/wiki/SymPy 中文] +Links:[https://en.wikipedia.org/wiki/SymPy Wikipedia] [https://zh.wikipedia.org/wiki/SymPy 维基百科] 它是用来做符号计算的,其目标是成为一个全功能的“计算机代数系统”。 @@ -2052,7 +2052,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/SymPy 英文]、[https://zh.wikipedia Home:[http://www.pypy.org/] -Wikipedia:[https://en.wikipedia.org/wiki/PyPy 英文]、[https://zh.wikipedia.org/wiki/PyPy 中文] +Links:[https://en.wikipedia.org/wiki/PyPy Wikipedia] [https://zh.wikipedia.org/wiki/PyPy 维基百科] 它是一个用 Python 写的 Python 解释器(有点绕口令)。 From 24a7b0c54f42d890f5495b0ab6508474757c5aff Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 25 Feb 2017 20:28:39 +0800 Subject: [PATCH 090/116] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=93=BE=E6=8E=A5?= =?UTF-8?q?=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 158 +++++++++++++++++++++++++------------------------- 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index b434cda..1cb842f 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -16,7 +16,7 @@ Home:[http://boost.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Boost_%28C%2B%2B_libraries%29 英文]、[https://zh.wikipedia.org/wiki/Boost_C%2B%2B_Libraries 中文] +Links:[https://en.wikipedia.org/wiki/Boost_%28C%2B%2B_libraries%29 Wikipedia] [https://zh.wikipedia.org/wiki/Boost_C%2B%2B_Libraries 维基百科] Boost 大概是最重要的第三方 C++ 库。其作者有很多是 C++ 标准委员会的成员。Boost 的很多子库后来都成为 C++ 的标准库。 @@ -26,7 +26,7 @@ Boost 大概是最重要的第三方 C++ 库。其作者有很多是 C++ 标准 Home:[https://wxwidgets.org/] -Wikipedia:[https://en.wikipedia.org/wiki/WxWidgets 英文]、[https://zh.wikipedia.org/wiki/WxWidgets 中文] +Links:[https://en.wikipedia.org/wiki/WxWidgets Wikipedia] [https://zh.wikipedia.org/wiki/WxWidgets 维基百科] 这是一个非常老牌的 C++ 开源 GUI 框架,诞生于1992年。原先叫做 wxWindows,后来因为微软的法律纠纷,改为现名。 @@ -40,7 +40,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/WxWidgets 英文]、[https://zh.wikip Home:[http://www.qt-project.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Qt_(toolkit) 英文]、[https://zh.wikipedia.org/wiki/Qt 中文] +Links:[https://en.wikipedia.org/wiki/Qt_(toolkit) Wikipedia] [https://zh.wikipedia.org/wiki/Qt 维基百科] 这是一个非常老牌的 C++ 开源 GUI 框架,于1995年发布 1.0 版本。原先由 Trolltech 公司维护,后来该公司被 Nokia 收购。 @@ -52,7 +52,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Qt_(toolkit) 英文]、[https://zh.wi Home:[https://apr.apache.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Apache_Portable_Runtime 英文]、[https://zh.wikipedia.org/wiki/Apache%E5%8F%AF%E7%A7%BB%E6%A4%8D%E8%BF%90%E8%A1%8C%E6%97%B6 中文] +Links:[https://en.wikipedia.org/wiki/Apache_Portable_Runtime Wikipedia] [https://zh.wikipedia.org/wiki/Apache%E5%8F%AF%E7%A7%BB%E6%A4%8D%E8%BF%90%E8%A1%8C%E6%97%B6 维基百科] 这是由 Apache 社区维护的 C 开源库,主要提供操作系统相关的功能(文件系统、进程、线程、用户、IPC)。此外还提供了一些网络相关的功能。 @@ -62,7 +62,7 @@ APR 原先是 Apache Web 服务器的一个组成部分,后来独立出来, Home:[http://www.cse.wustl.edu/~schmidt/ACE.html] -Wikipedia:[https://en.wikipedia.org/wiki/Adaptive_Communication_Environment 英文]、[https://zh.wikipedia.org/wiki/ACE%E8%87%AA%E9%80%82%E9%85%8D%E9%80%9A%E4%BF%A1%E7%8E%AF%E5%A2%83 中文] +Links:[https://en.wikipedia.org/wiki/Adaptive_Communication_Environment Wikipedia] [https://zh.wikipedia.org/wiki/ACE%E8%87%AA%E9%80%82%E9%85%8D%E9%80%9A%E4%BF%A1%E7%8E%AF%E5%A2%83 维基百科] 这是一个跨平台的 C++ 库,提供了一套网络通讯的框架;另外还支持线程、进程和 IPC。 @@ -70,7 +70,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Adaptive_Communication_Environment Home:[http://pocoproject.org/] -Wikipedia:[https://en.wikipedia.org/wiki/POCO_C%2B%2B_Libraries 英文] +Links:[https://en.wikipedia.org/wiki/POCO_C%2B%2B_Libraries Wikipedia] 它的名称源自“POrtable COmponents”,是一个基于 C++ 的开源库。 @@ -80,7 +80,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/POCO_C%2B%2B_Libraries 英文] Home:[http://dlib.net/] -Wikipedia:[https://en.wikipedia.org/wiki/Dlib 英文] +Links:[https://en.wikipedia.org/wiki/Dlib Wikipedia] 诞生于2002年的 C++ 开源库,提供了非常多的功能(网络、多线程、GUI、数值计算、图像处理、数据挖掘......)。 @@ -90,7 +90,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Dlib 英文] Home:[http://www.cryptopp.com/] -Wikipedia:[https://en.wikipedia.org/wiki/Crypto%2B%2B 英文] +Links:[https://en.wikipedia.org/wiki/Crypto%2B%2B Wikipedia] 它也叫“CryptoPP”或“libcrypto++”,是非常著名的开源加密库,诞生于1995年。基于 C++ 开发,大量用到模板语法。 @@ -332,7 +332,7 @@ fmt::print("Hello, {name}! The answer is {number}. Goodbye, {name}.", Home:[http://www.pcre.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions 英文] +Links:[https://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions Wikipedia] 这是一个很老牌的正则表达式的库,诞生于1997年。很多知名的开源项目(Apache、PHP、KDE)用到了它。 @@ -395,7 +395,7 @@ assert(i == 1234); Home:[http://www.geocities.jp/kosako3/oniguruma/] -Wikipedia:[https://en.wikipedia.org/wiki/Oniguruma 英文] +Links:[https://en.wikipedia.org/wiki/Oniguruma Wikipedia] 来自日本的正则式库,基于 C 语言。据说性能很高。 @@ -839,7 +839,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了与 Home:[https://github.com/google/googletest] -Wikipedia:[https://en.wikipedia.org/wiki/Google_Test 英文] +Links:[https://en.wikipedia.org/wiki/Google_Test Wikipedia] 这是 Google 提供的单元测试框架。从 Google Code 迁移到 GitHub 之后,又整合了 GoogleMock 项目。 @@ -849,7 +849,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Google_Test 英文] Home:[http://freedesktop.org/wiki/Software/cppunit/] -Wikipedia:[https://en.wikipedia.org/wiki/CppUnit 英文] +Links:[https://en.wikipedia.org/wiki/CppUnit Wikipedia] 如其名,这是一个 C++ 的单元测试框架。该项目起先是作为 JUnit 的 C++ 移植而创建的。 @@ -857,7 +857,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/CppUnit 英文] Home:[http://check.sourceforge.net/] -Wikipedia:[https://en.wikipedia.org/wiki/Check_%28unit_testing_framework%29 英文] +Links:[https://en.wikipedia.org/wiki/Check_%28unit_testing_framework%29 Wikipedia] 这是针对 C 的单元测试框架。 @@ -1159,7 +1159,7 @@ int main(int argc, char* argv[]) Home:[http://www.gtk.org/] -Wikipedia:[https://en.wikipedia.org/wiki/GTK%2B 英文]、[https://zh.wikipedia.org/wiki/GTK%2B 中文] +Links:[https://en.wikipedia.org/wiki/GTK%2B Wikipedia] [https://zh.wikipedia.org/wiki/GTK%2B 维基百科] 老牌的 GUI 框架,诞生于1998年。原先叫做“GIMP Toolkit”,是基于 C 开发的跨平台界面组件库。 @@ -1196,7 +1196,7 @@ int main(int argc, char* argv[]) Home:[http://www.fltk.org/] -Wikipedia:[https://en.wikipedia.org/wiki/FLTK 英文]、[https://zh.wikipedia.org/wiki/FLTK 中文] +Links:[https://en.wikipedia.org/wiki/FLTK Wikipedia] [https://zh.wikipedia.org/wiki/FLTK 维基百科] 它的全称是“Fast, Light Toolkit”。如其名,它非常轻量级。用它写一个“Hello World 应用”,静态链接后大约才 100KB @@ -1227,7 +1227,7 @@ int main(int argc, char **argv) Home:[http://sourceforge.net/projects/wtl/] -Wikipedia:[https://en.wikipedia.org/wiki/Windows_Template_Library 英文]、[https://zh.wikipedia.org/wiki/Windows_Template_Library 中文] +Links:[https://en.wikipedia.org/wiki/Windows_Template_Library Wikipedia] [https://zh.wikipedia.org/wiki/Windows_Template_Library 维基百科] 这是微软雇员 Nenad Stefanovic 开发的开源 GUI 框架。开发 WTL 是为了提供一个轻量级的 MFC 替代品。 @@ -1305,7 +1305,7 @@ Home:[http://wxmathplot.sourceforge.net/] Home:[https://www.gnu.org/software/libc/manual/html_node/Getopt.html] -Wikipedia:[https://en.wikipedia.org/wiki/Getopt 英文] +Links:[https://en.wikipedia.org/wiki/Getopt Wikipedia] 这是标准C用来处理命令行参数的老牌函数,诞生于上世纪80年代初期。 @@ -1387,7 +1387,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ Home:[https://www.gnu.org/software/ncurses/] -Wikipedia:[https://en.wikipedia.org/wiki/Ncurses 英文]、[https://zh.wikipedia.org/wiki/Ncurses 中文] +Links:[https://en.wikipedia.org/wiki/Ncurses Wikipedia] [https://zh.wikipedia.org/wiki/Ncurses 维基百科] ncurses 是“new curses”的缩略词,它是 [https://en.wikipedia.org/wiki/Curses_(programming_library) curses] 库的自由软件克隆,诞生于1993年。 @@ -1401,7 +1401,7 @@ ncurses 是“new curses”的缩略词,它是 [https://en.wikipedia.org/wiki/ Home:[http://www.tcpdump.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Pcap 英文] +Links:[https://en.wikipedia.org/wiki/Pcap Wikipedia] 很著名的 Sniffer 抓包库,基于 C 语言开发。 @@ -1466,7 +1466,7 @@ int main(int argc, char* argv[]) Home:[http://www.winpcap.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Pcap 英文] +Links:[https://en.wikipedia.org/wiki/Pcap Wikipedia] 它是 libpcap 在 Windows 系统下的移植。 @@ -1504,7 +1504,7 @@ POCO 前面已经介绍过。它提供了针对 TCP 服务端的封装类。 Home:[http://curl.haxx.se/libcurl/] -Wikipedia:[https://en.wikipedia.org/wiki/CURL 英文]、[https://zh.wikipedia.org/wiki/CURL 中文] +Links:[https://en.wikipedia.org/wiki/CURL Wikipedia] [https://zh.wikipedia.org/wiki/CURL 维基百科] cURL 是一个功能很强的网络库/网络工具,支持 N 多应用层协议。下面是支持协议的列表(从它官网抄袭的) @@ -1599,7 +1599,7 @@ Home:[https://github.com/qxmpp-project/qxmpp] Home:[https://developers.google.com/protocol-buffers/] -Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] +Links:[https://en.wikipedia.org/wiki/Protocol_Buffers Wikipedia] 它是 Google 开发的一个跨语言的库,用于传输业务数据时的“编码/解码”。其优点是:跨多种语言、高性能、向前兼容、向后兼容。 @@ -1611,7 +1611,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Protocol_Buffers 英文] Home:[https://thrift.apache.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Apache_Thrift 英文] +Links:[https://en.wikipedia.org/wiki/Apache_Thrift Wikipedia] 来自于 Apache 社区,提供了一种跨语言的通讯机制。 @@ -1668,7 +1668,7 @@ ACE 前面已经介绍过。它提供了很多种用于网络通讯的设计模 Home:[http://www.zeromq.org/] -Wikipedia:[https://en.wikipedia.org/wiki/ZeroMQ 英文]、[https://zh.wikipedia.org/wiki/%C3%98MQ 中文] +Links:[https://en.wikipedia.org/wiki/ZeroMQ Wikipedia] [https://zh.wikipedia.org/wiki/%C3%98MQ 维基百科] ZeroMQ 是一个轻量级、跨平台的开源库,提供了高性能、异步的消息队列。采用 C++ 开发,提供了多种语言的绑定。 @@ -1750,7 +1750,7 @@ int request(const char* url, const char* msg) Home:[https://zeroc.com/] -Wikipedia:[https://en.wikipedia.org/wiki/Internet_Communications_Engine 英文]、[https://zh.wikipedia.org/wiki/ICE_(%E4%B8%AD%E9%97%B4%E4%BB%B6) 中文] +Links:[https://en.wikipedia.org/wiki/Internet_Communications_Engine Wikipedia] [https://zh.wikipedia.org/wiki/ICE_(%E4%B8%AD%E9%97%B4%E4%BB%B6) 维基百科] 这是一个面向对象的通讯中间件,诞生于2002年。支持不同编程语言的通讯。 @@ -1760,7 +1760,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Internet_Communications_Engine 英文 Home:[http://libevent.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Libevent 英文]、[https://zh.wikipedia.org/wiki/Libevent 中文] +Links:[https://en.wikipedia.org/wiki/Libevent Wikipedia] [https://zh.wikipedia.org/wiki/Libevent 维基百科] 它提供了异步事件处理机制。在网络开发中,可以用它替代传统的“event loop”,有助于简化代码。 @@ -1858,7 +1858,7 @@ Home:[http://libev.schmorp.de/] Home:[https://github.com/libuv/libuv] -Wikipedia:[https://en.wikipedia.org/wiki/Libuv 英文] +Links:[https://en.wikipedia.org/wiki/Libuv Wikipedia] 它提供了跨平台的异步 I/O 机制。主要是为了提供给 [https://en.wikipedia.org/wiki/Node.js Node.js] 使用。 @@ -1880,7 +1880,7 @@ Dlib 前面已经介绍过。它针对网络通讯,提供了比较高的抽象 Home:[https://www.mysql.com/] -Wikipedia:[https://en.wikipedia.org/wiki/MySQL 英文]、[https://zh.wikipedia.org/wiki/MySQL 中文] +Links:[https://en.wikipedia.org/wiki/MySQL Wikipedia] [https://zh.wikipedia.org/wiki/MySQL 维基百科] 名气最大的开源数据库,诞生于1995年,采用 C 和 C++ 语言开发。如今隶属于 Oracle 公司。 @@ -1888,7 +1888,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/MySQL 英文]、[https://zh.wikipedia Home:[http://postgresql.org/] -Wikipedia:[https://en.wikipedia.org/wiki/PostgreSQL 英文]、[https://zh.wikipedia.org/wiki/PostgreSQL 中文] +Links:[https://en.wikipedia.org/wiki/PostgreSQL Wikipedia] [https://zh.wikipedia.org/wiki/PostgreSQL 维基百科] 名气仅次于 MySQL 的开源数据库,诞生于1996年。采用 C 语言开发。 @@ -1896,7 +1896,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/PostgreSQL 英文]、[https://zh.wiki Home:[http://sqlite.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SQLite 英文]、[https://zh.wikipedia.org/wiki/SQLite 中文] +Links:[https://en.wikipedia.org/wiki/SQLite Wikipedia] [https://zh.wikipedia.org/wiki/SQLite 维基百科] 它是一个很优秀的嵌入式(进程内)数据库,非常轻量级,支持各种作系统平台。采用 C 语言开发。 @@ -1906,7 +1906,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/SQLite 英文]、[https://zh.wikipedi Home:[https://www.mongodb.org/] -Wikipedia:[https://en.wikipedia.org/wiki/MongoDB 英文] +Links:[https://en.wikipedia.org/wiki/MongoDB Wikipedia] 这是近几年兴起的 NoSQL 数据库的一员。它本身是基于 C++ 和 C 开发的。 @@ -1914,7 +1914,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/MongoDB 英文] Home:[http://redis.io/] -Wikipedia:[https://zh.wikipedia.org/wiki/Redis 中文]、[https://en.wikipedia.org/wiki/Redis 英文] +Links:[https://zh.wikipedia.org/wiki/Redis 维基百科] [https://en.wikipedia.org/wiki/Redis Wikipedia] 诞生于2009年,是目前(2014~2015)最流行的键值存储数据库,基于 C 语言开发。 @@ -1924,7 +1924,7 @@ Wikipedia:[https://zh.wikipedia.org/wiki/Redis 中文]、[https://en.wikipedia Home:[http://www.oracle.com/us/products/database/berkeley-db/] -Wikipedia:[https://en.wikipedia.org/wiki/Berkeley_DB 英文]、[https://zh.wikipedia.org/wiki/Berkeley_DB 中文] +Links:[https://en.wikipedia.org/wiki/Berkeley_DB Wikipedia] [https://zh.wikipedia.org/wiki/Berkeley_DB 维基百科] 诞生于1994年,是一个很老牌的嵌入式(进程内)数据库,提供“键值存储”的功能,基于 C 语言开发。 @@ -1936,7 +1936,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Berkeley_DB 英文]、[https://zh.wik Home:[https://github.com/google/leveldb] -Wikipedia:[https://en.wikipedia.org/wiki/LevelDB 英文]、[https://zh.wikipedia.org/wiki/LevelDB 中文] +Links:[https://en.wikipedia.org/wiki/LevelDB Wikipedia] [https://zh.wikipedia.org/wiki/LevelDB 维基百科] 它是 Google 基于 C++ 开发的 NoSQL 数据库,提供“键值存储”的功能。 @@ -1948,7 +1948,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/LevelDB 英文]、[https://zh.wikiped Home:[http://www.firebirdsql.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Firebird_%28database_server%29 英文]、[https://zh.wikipedia.org/wiki/Firebird_(%E6%95%B0%E6%8D%AE%E5%BA%93) 中文] +Links:[https://en.wikipedia.org/wiki/Firebird_%28database_server%29 Wikipedia] [https://zh.wikipedia.org/wiki/Firebird_(%E6%95%B0%E6%8D%AE%E5%BA%93) 维基百科] 它是2000年的时候,从 [https://en.wikipedia.org/wiki/Borland Borland] 公司的 InterBase 数据库派生出来的。 @@ -1972,7 +1972,7 @@ Home:[http://www.scylladb.com/] Home:[http://otl.sourceforge.net/] -Wikipedia:[https://en.wikipedia.org/wiki/Oracle_Template_Library 英文] +Links:[https://en.wikipedia.org/wiki/Oracle_Template_Library Wikipedia] 原生支持的数据库:Oracle、SQL Server、DB2、Informix、TimesTen, MAX/DB;另支持 ODBC。 @@ -2359,7 +2359,7 @@ POCO 前面已经介绍过。它提供了 MongoDB 的封装类 Home:[http://www.unixodbc.org/] -Wikipedia:[https://en.wikipedia.org/wiki/UnixODBC 英文] +Links:[https://en.wikipedia.org/wiki/UnixODBC Wikipedia] 诞生于1999年,实现了全套的 ODBC 架构,包括:驱动管理器、相关的 GUI 界面和命令行界面。支持多种操作系统。 @@ -2381,7 +2381,7 @@ POCO 前面已经介绍过。它提供了操作 ODBC 的封装类。 Home:[http://www.codesynthesis.com/products/odb] -Wikipedia:[https://en.wikipedia.org/wiki/ODB_%28C%2B%2B%29 英文] +Links:[https://en.wikipedia.org/wiki/ODB_%28C%2B%2B%29 Wikipedia] 它的特色是:可以根据 C++ 类定义自动生成数据库的表结构。 @@ -2444,7 +2444,7 @@ Home:[https://github.com/paulftw/hiberlite] Home:[https://httpd.apache.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Apache_HTTP_Server 英文]、[https://zh.wikipedia.org/wiki/Apache_HTTP_Server 中文] +Links:[https://en.wikipedia.org/wiki/Apache_HTTP_Server Wikipedia] [https://zh.wikipedia.org/wiki/Apache_HTTP_Server 维基百科] 大名鼎鼎的 Apache,诞生于1995年,采用 C 和 C++ 开发。长期作为 Web Server 市场份额的老大。 @@ -2452,7 +2452,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Apache_HTTP_Server 英文]、[https:/ Home:[http://nginx.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Nginx 英文]、[https://zh.wikipedia.org/wiki/Nginx 中文] +Links:[https://en.wikipedia.org/wiki/Nginx Wikipedia] [https://zh.wikipedia.org/wiki/Nginx 维基百科] Web Server 的后起之秀,诞生于2002年,采用 C 语言开发。其市场份额如今排名第二。 @@ -2517,7 +2517,7 @@ POCO 前面已经介绍过。它提供了 HTTP Client 的封装类。 Home:[https://www.webkit.org/] -Wikipedia:[https://en.wikipedia.org/wiki/WebKit 英文]、[https://zh.wikipedia.org/wiki/WebKit 中文] +Links:[https://en.wikipedia.org/wiki/WebKit Wikipedia] [https://zh.wikipedia.org/wiki/WebKit 维基百科] 它是很多浏览器使用的渲染引擎,基于 C++ 开发。 @@ -2525,7 +2525,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/WebKit 英文]、[https://zh.wikipedi Home:[https://developer.mozilla.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Gecko_(software) 英文]、[https://zh.wikipedia.org/wiki/Gecko 中文] +Links:[https://en.wikipedia.org/wiki/Gecko_(software) Wikipedia] [https://zh.wikipedia.org/wiki/Gecko 维基百科] 它是 Firefox 的渲染引擎,基于 C++ 开发,由 Mozilla 社区维护。 @@ -2535,7 +2535,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Gecko_(software) 英文]、[https://z Home:[https://bitbucket.org/chromiumembedded/cef] -Wikipedia:[https://en.wikipedia.org/wiki/Chromium_Embedded_Framework 英文] +Links:[https://en.wikipedia.org/wiki/Chromium_Embedded_Framework Wikipedia] 如其名,它提供了嵌入 Chrome 浏览器的框架。采用 C++ 开发。好几个商业公司(Google、Adobe、Facebook、Evernote...)的产品用到它。 @@ -2559,7 +2559,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Chromium_Embedded_Framework 英文] Home:[http://phantomjs.org/] -Wikipedia:[https://en.wikipedia.org/wiki/PhantomJS 英文] +Links:[https://en.wikipedia.org/wiki/PhantomJS Wikipedia] 2011年才诞生的。基于 C++ 开发,整合了 WebKit。 @@ -2603,7 +2603,7 @@ SHA256().CalculateDigest(abDigest, pbData, nDataLen); Home:[https://www.openssl.org/] -Wikipedia:[https://en.wikipedia.org/wiki/OpenSSL 英文]、[https://zh.wikipedia.org/wiki/OpenSSL 中文] +Links:[https://en.wikipedia.org/wiki/OpenSSL Wikipedia] [https://zh.wikipedia.org/wiki/OpenSSL 维基百科] OpenSSL 基于 C 语言开发,在加密领域那可是大名鼎鼎。大部分常用的加密算法(对称、非对称)和散列算法,它都支持。 @@ -2613,7 +2613,7 @@ OpenSSL 基于 C 语言开发,在加密领域那可是大名鼎鼎。大部分 Home:[http://www.libressl.org/] -Wikipedia:[https://en.wikipedia.org/wiki/LibreSSL 英文]、[https://zh.wikipedia.org/wiki/LibreSSL 中文] +Links:[https://en.wikipedia.org/wiki/LibreSSL Wikipedia] [https://zh.wikipedia.org/wiki/LibreSSL 维基百科] OpenSSL 爆出“心脏滴血漏洞”之后,OpenBSD 社区的程序员复制了 OpenSSL 版本 1.0.1g 的代码,然后另起炉灶。 @@ -2623,7 +2623,7 @@ LibreSSL 的主要目标是“安全性”,其维护人员删除了原 OpenSSL Home:[http://gnutls.org/] -Wikipedia:[https://en.wikipedia.org/wiki/GnuTLS 英文] +Links:[https://en.wikipedia.org/wiki/GnuTLS Wikipedia] 采用 C 语言开发,名气也挺大。如其名,主要提供 TLS/SSL 的相关功能。 @@ -2631,7 +2631,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/GnuTLS 英文] Home:[http://nacl.cr.yp.to/] -Wikipedia:[https://en.wikipedia.org/wiki/NaCl_%28software%29 英文] +Links:[https://en.wikipedia.org/wiki/NaCl_%28software%29 Wikipedia] 这个名称是“Networking and Cryptography library”的缩写。 @@ -2805,7 +2805,7 @@ Home:[http://www.7-zip.org/sdk.html] Home:[http://icculus.org/physfs/] -Wikipedia:[https://en.wikipedia.org/wiki/PhysicsFS 英文] +Links:[https://en.wikipedia.org/wiki/PhysicsFS Wikipedia] 针对不同的压缩/归档格式,提供了类似 VFS 的抽象封装层。主要用于游戏开发中。 @@ -2827,7 +2827,7 @@ Home:[https://github.com/google/zopfli] Home:[http://www.nih.at/libzip/] -Wikipedia:[https://en.wikipedia.org/wiki/Libzip 英文] +Links:[https://en.wikipedia.org/wiki/Libzip Wikipedia] 用 C 语言开发的库,基于 zlib 库。 @@ -2853,7 +2853,7 @@ Home:[http://bzip.org/] Home:[http://zlib.net/] -Wikipedia:[https://en.wikipedia.org/wiki/Zlib 英文]、[https://zh.wikipedia.org/wiki/Zlib 中文] +Links:[https://en.wikipedia.org/wiki/Zlib Wikipedia] [https://zh.wikipedia.org/wiki/Zlib 维基百科] C 语言实现,诞生于1995年,被大量的开源项目使用(OpenSSL、OpenSSH、Apache、PostgreSQL、Git、libpng......)。 @@ -2891,7 +2891,7 @@ Home:[https://google.github.io/snappy/] Home:[https://github.com/google/brotli] -Wikipedia:[https://en.wikipedia.org/wiki/Brotli 英文] +Links:[https://en.wikipedia.org/wiki/Brotli Wikipedia] 由 Google 开发的压缩格式,压缩率很高(据说高于 LZMA 和 bz2)。 @@ -2903,7 +2903,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Brotli 英文] Home:[https://github.com/lzfse/lzfse] -Wikipedia:[https://zh.wikipedia.org/wiki/LZFSE 中文] +Links:[https://zh.wikipedia.org/wiki/LZFSE 维基百科] 由苹果开发的压缩格式。苹果称它的压缩率与“ZLib level 5”相似,但速度快2至3倍。 @@ -2917,7 +2917,7 @@ Wikipedia:[https://zh.wikipedia.org/wiki/LZFSE 中文] Home:[http://www.libexpat.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Expat_(library) 英文] +Links:[https://en.wikipedia.org/wiki/Expat_(library) Wikipedia] 基于 C 语言实现,诞生于1998年。很多知名的开源项目(Apache Server、Firefox、Python、PHP、Perl)用到它。 @@ -2925,7 +2925,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Expat_(library) 英文] Home:[http://xmlsoft.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Libxml2 英文] +Links:[https://en.wikipedia.org/wiki/Libxml2 Wikipedia] 基于 C 语言实现,诞生于1999年。提供了多种语言(C++、Python、Ruby、Common Lisp、PHP、Perl)的 API 绑定。 @@ -2969,7 +2969,7 @@ Home:[http://podofo.sourceforge.net/] Home:[http://libharu.org/] -Wikipedia:[https://en.wikipedia.org/wiki/LibHaru 英文] +Links:[https://en.wikipedia.org/wiki/LibHaru Wikipedia] 它是基于 C 语言开发的跨平台库,可以用来生成 PDF 文件格式。 @@ -3046,7 +3046,7 @@ Home:[http://www.mare.ee/indrek/libchmxx/] Home:[http://imagemagick.org/] -Wikipedia:[https://en.wikipedia.org/wiki/ImageMagick 英文]、[https://zh.wikipedia.org/wiki/ImageMagick 中文] +Links:[https://en.wikipedia.org/wiki/ImageMagick Wikipedia] [https://zh.wikipedia.org/wiki/ImageMagick 维基百科] ImageMagick 可说是最强大的开源图片处理工具集,采用 C 语言编写。诞生于1990年,其开发至今依然非常活跃。支持非常多的操作系统平台。 @@ -3097,7 +3097,7 @@ ImageMagick 前面已经介绍过。它支持非常多的图片格式([http:// Home:[http://cairographics.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Cairo_%28graphics%29 英文]、[https://zh.wikipedia.org/wiki/Cairo_(%E7%B9%AA%E5%9C%96) 中文] +Links:[https://en.wikipedia.org/wiki/Cairo_%28graphics%29 Wikipedia] [https://zh.wikipedia.org/wiki/Cairo_(%E7%B9%AA%E5%9C%96) 维基百科] 它提供了矢量图像的渲染功能。支持多种后端输出(Win32 GDI、OpenGL、Xlib、XCB、PDF、PNG、SVG ......)。 @@ -3113,7 +3113,7 @@ Home:[http://cairographics.org/cairomm/] Home:[https://github.com/google/skia] -Wikipedia:[https://en.wikipedia.org/wiki/Skia_Graphics_Engine 英文]、[https://zh.wikipedia.org/wiki/Skia_Graphics_Library 中文] +Links:[https://en.wikipedia.org/wiki/Skia_Graphics_Engine Wikipedia] [https://zh.wikipedia.org/wiki/Skia_Graphics_Library 维基百科] 它是 Google 基于 C++ 开发的图像渲染库。支持多种后端输出(rasterization、OpenGL、PDF、SVG、SWF ......)。 @@ -3131,7 +3131,7 @@ Home:[http://pbrt.org/] Home:[http://opencv.org/] -Wikipedia:[https://en.wikipedia.org/wiki/OpenCV 英文]、[https://zh.wikipedia.org/wiki/OpenCV 中文] +Links:[https://en.wikipedia.org/wiki/OpenCV Wikipedia] [https://zh.wikipedia.org/wiki/OpenCV 维基百科] 它是一个跨平台的计算机视觉库,由 Intel 发起并参与开发。开发语言是 C 和 C++。 @@ -3147,7 +3147,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/OpenCV 英文]、[https://zh.wikipedi Home:[http://ffmpeg.org/] -Wikipedia:[https://en.wikipedia.org/wiki/FFmpeg 英文]、[https://zh.wikipedia.org/wiki/FFmpeg 中文] +Links:[https://en.wikipedia.org/wiki/FFmpeg Wikipedia] [https://zh.wikipedia.org/wiki/FFmpeg 维基百科] 名气非常大的开源多媒体框架,基于 C 和汇编开发,支持多种操作系统。 @@ -3167,7 +3167,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/FFmpeg 英文]、[https://zh.wikipedi Home:[http://libav.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Libav 英文] +Links:[https://en.wikipedia.org/wiki/Libav Wikipedia] 它是2011年从 FFmpeg 派生出来的。基于 C 语言开发,支持多种操作系统。 @@ -3187,7 +3187,7 @@ Home:[http://ffmpeg.org/] Home:[http://www.portaudio.com/] -Wikipedia:[https://en.wikipedia.org/wiki/PortAudio 英文] +Links:[https://en.wikipedia.org/wiki/PortAudio Wikipedia] PortAudio 是 PortMedia 的组成部分,提供了音频的播放和录制功能。支持多种底层 API(ALSA、DirectSound、WASAPI、ASIO...) @@ -3195,7 +3195,7 @@ PortAudio 是 PortMedia 的组成部分,提供了音频的播放和录制功 Home:[http://www.openal.org/] -Wikipedia:[https://en.wikipedia.org/wiki/OpenAL 英文]、[https://zh.wikipedia.org/wiki/OpenAL 中文] +Links:[https://en.wikipedia.org/wiki/OpenAL Wikipedia] [https://zh.wikipedia.org/wiki/OpenAL 维基百科] C 语言开发的 3D 音效库,跨平台。最初由 Loki Software 开发。Loki 倒闭以后,这个项目由开源社区继续维护。 @@ -3207,7 +3207,7 @@ C 语言开发的 3D 音效库,跨平台。最初由 Loki Software 开发。Lo

id Tech 系列

-Wikipedia:[https://en.wikipedia.org/wiki/Id_Tech 英文] +Links:[https://en.wikipedia.org/wiki/Id_Tech Wikipedia] 这个系列来自于大名鼎鼎的 [https://en.wikipedia.org/wiki/Id_Software id Software 公司],由同样大名鼎鼎约翰·卡马克打造。 @@ -3229,7 +3229,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Id_Tech 英文] Home:[http://www.crystalspace3d.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Crystal_Space 英文] +Links:[https://en.wikipedia.org/wiki/Crystal_Space Wikipedia] 以 C++ 编写,功能包括:2D 和 3D 渲染、音效、AI... 它的物理引擎基于 ODE 和 Bullet @@ -3237,7 +3237,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Crystal_Space 英文] Home:[http://www.blender.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Game_Blender 英文]、[https://zh.wikipedia.org/wiki/Game_Blender 中文] +Links:[https://en.wikipedia.org/wiki/Game_Blender Wikipedia] [https://zh.wikipedia.org/wiki/Game_Blender 维基百科] 它是 [https://en.wikipedia.org/wiki/Blender_%28software%29 Blender] 的组成部分,以 C++ 编写,使用 Python 脚本扩展。功能包括:3D 渲染、碰撞检测、角色编辑器、音效、网络通讯、AI、... @@ -3245,7 +3245,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Game_Blender 英文]、[https://zh.wi Home:[http://www.panda3d.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Panda3D 英文] +Links:[https://en.wikipedia.org/wiki/Panda3D Wikipedia] 以 C++ 编写,用 Python 脚本扩展。虽然它的名字有“3D”,但它不仅仅是 3D 引擎,还包括了其它功能(碰撞检测、音效、关卡编辑器...)。 @@ -3255,7 +3255,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Panda3D 英文] Home:[http://www.ogre3d.org/] -Wikipedia:[https://en.wikipedia.org/wiki/OGRE 英文]、[https://zh.wikipedia.org/wiki/OGRE 中文] +Links:[https://en.wikipedia.org/wiki/OGRE Wikipedia] [https://zh.wikipedia.org/wiki/OGRE 维基百科] 著名的 3D 渲染引擎,C++ 开发,诞生于2005年。支持很多操作系统(包括两大手机操作系统)。很多商业游戏用到它。 @@ -3265,7 +3265,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/OGRE 英文]、[https://zh.wikipedia. Home:[http://mesa3d.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Mesa_%28computer_graphics%29 英文]、[https://zh.wikipedia.org/wiki/Mesa_3D 中文] +Links:[https://en.wikipedia.org/wiki/Mesa_%28computer_graphics%29 Wikipedia] [https://zh.wikipedia.org/wiki/Mesa_3D 维基百科] 使用 C 语言开发,它是针对 OpenGL 规范的【纯软件】实现(大部分 OpenGL 的实现都用到了显卡硬件)。 @@ -3275,7 +3275,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Mesa_%28computer_graphics%29 英文] Home:[http://www.bulletphysics.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Bullet_%28software%29 英文]、[https://zh.wikipedia.org/wiki/Bullet 中文] +Links:[https://en.wikipedia.org/wiki/Bullet_%28software%29 Wikipedia] [https://zh.wikipedia.org/wiki/Bullet 维基百科] 采用 C 和 C++ 开发。电影《2012》用到它,游戏“侠盗猎车手”、“荒野大镖客”用到它。 @@ -3283,7 +3283,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Bullet_%28software%29 英文]、[http Home:[http://www.box2d.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Box2D 英文]、[https://zh.wikipedia.org/wiki/Box2D 中文] +Links:[https://en.wikipedia.org/wiki/Box2D Wikipedia] [https://zh.wikipedia.org/wiki/Box2D 维基百科] 基于 C++ 开发的2维物理引擎。“愤怒的小鸟”用到它。 @@ -3291,7 +3291,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Box2D 英文]、[https://zh.wikipedia Home:[http://www.ode.org/] -Wikipedia:[https://en.wikipedia.org/wiki/Open_Dynamics_Engine 英文]、[https://zh.wikipedia.org/wiki/Open_Dynamics_Engine 中文] +Links:[https://en.wikipedia.org/wiki/Open_Dynamics_Engine Wikipedia] [https://zh.wikipedia.org/wiki/Open_Dynamics_Engine 维基百科] 诞生于2001年,采用 C 和 C++ 开发。 @@ -3299,7 +3299,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Open_Dynamics_Engine 英文]、[https Home:[http://www.newtondynamics.com/] -Wikipedia:[https://en.wikipedia.org/wiki/Newton_Game_Dynamics 英文] +Links:[https://en.wikipedia.org/wiki/Newton_Game_Dynamics Wikipedia] 基于 C++ 开发。 @@ -3313,7 +3313,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Newton_Game_Dynamics 英文] Home:[https://www.gnu.org/software/gsl/] -Wikipedia:[https://en.wikipedia.org/wiki/GNU_Scientific_Library 英文] +Links:[https://en.wikipedia.org/wiki/GNU_Scientific_Library Wikipedia] 由 GNU 官方提供,包括:复数、多项式、矩阵、线性代数、特征向量、快速傅里叶变换、统计、模拟退火...... @@ -3341,7 +3341,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ Home:[https://gmplib.org/] -Wikipedia:[https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library 英文]、[https://zh.wikipedia.org/wiki/GNU%E5%A4%9A%E9%87%8D%E7%B2%BE%E5%BA%A6%E8%BF%90%E7%AE%97%E5%BA%93 中文] +Links:[https://en.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library Wikipedia] [https://zh.wikipedia.org/wiki/GNU%E5%A4%9A%E9%87%8D%E7%B2%BE%E5%BA%A6%E8%BF%90%E7%AE%97%E5%BA%93 维基百科] 基于 C 语言的高精度数值运算库,诞生于1991年,非常老牌。 @@ -3431,7 +3431,7 @@ std::cout << v2 << std::endl; Home:[http://blitz.sourceforge.net/] -Wikipedia:[https://en.wikipedia.org/wiki/Blitz%2B%2B 英文] +Links:[https://en.wikipedia.org/wiki/Blitz%2B%2B Wikipedia] 它是基于 C++ 实现的。其特色是:采用“模板元编程”的技术进行编译时计算,从而优化了性能。 @@ -3439,7 +3439,7 @@ Wikipedia:[https://en.wikipedia.org/wiki/Blitz%2B%2B 英文] Home:[http://arma.sourceforge.net/] -Wikipedia:[https://en.wikipedia.org/wiki/Armadillo_%28C%2B%2B_library%29 英文] +Links:[https://en.wikipedia.org/wiki/Armadillo_%28C%2B%2B_library%29 Wikipedia] 类似 Blitz++,Armadillo 也用了“模板元编程”的技术。 @@ -3479,7 +3479,7 @@ Dlib 前面已经介绍过。它提供了线性代数相关的封装类。 Home:[http://swig.org/] -Wikipedia:[https://en.wikipedia.org/wiki/SWIG 英文] +Links:[https://en.wikipedia.org/wiki/SWIG Wikipedia] 这是一个很老牌的、有名气的工具,它可以把多种语言(Java、Python、C#、Ruby、PHP、Perl、Lua、Go ......)整合到 C/C++ 中。 From 32983f62e155b42239e720952a6e51a9fd45af53 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 25 Feb 2017 20:56:44 +0800 Subject: [PATCH 091/116] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 1cb842f..8ad9411 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -290,6 +290,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ #include #include + using std::cout; using boost::format; @@ -347,6 +348,7 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ 代码示例——基于正则式进行匹配和替换 #include + using std::string; using namespace boost; @@ -384,6 +386,7 @@ Home:[https://github.com/google/re2] 代码示例——基于正则式进行匹配 #include + int i; string s; assert(RE2::FullMatch("test:1234", "(\\w+):(\\d+)", &s, &i)); @@ -719,11 +722,13 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,用来辅助 #include #include -boost::function f = std::atoi; -std::cout << f("42") << '\n'; +using namespace std; + +boost::function f = atoi; +cout << f("42") << '\n'; -f = std::strlen; -std::cout << f("42") << '\n'; +f = strlen; +cout << f("42") << '\n';

Boost.Lambda

@@ -741,10 +746,11 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ #include #include -std::vector v; +using namespace std; + +vector v; // 此处填充 v -std::for_each(v.begin(), v.end(), - std::cout << boost::lambda::_1 << "\n"); +for_each(v.begin(), v.end(), cout << boost::lambda::_1 << "\n"); == 3.4 元编程(Metaprogramming) == @@ -1316,7 +1322,8 @@ Links:[https://en.wikipedia.org/wiki/Getopt Wikipedia] #include /* for printf */ #include /* for exit */ #include /* for getopt */ -int main(int argc, char** argv) + +int main(int argc, char* argv[]) { int digit_optind = 0; int aopt = 0, bopt = 0; @@ -1410,7 +1417,7 @@ Links:[https://en.wikipedia.org/wiki/Pcap Wikipedia] #include #include -int main(int argc, char* argv[]) +int main() { pcap_t* handle; /* Session handle */ char* dev; /* The device to sniff on */ @@ -1680,7 +1687,7 @@ ZeroMQ 是一个轻量级、跨平台的开源库,提供了高性能、异步 #include -int main(int argc, char* argv[]) +int main() { zmq::context_t context(1); @@ -1772,7 +1779,6 @@ Links:[https://en.wikipedia.org/wiki/Libevent Wikipedia] [https://zh.wikipedia #include #include #include - #include #include @@ -1785,7 +1791,7 @@ void generic_request_handler(struct evhttp_request* req, void* arg) evbuffer_free(return_buffer); } -int main(int argc, char** argv) +int main() { short http_port = 8080; char* http_addr = "127.0.0.1"; @@ -2319,7 +2325,7 @@ MongoDB 前面已经介绍过。这是其官方提供的 API。 #include #include -int main(int argc, char* argv[]) +int main() { mongoc_init(); @@ -3415,7 +3421,9 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,实现了 BLA #include #include +using namespace std; using namespace boost::numeric::ublas; + vector v(2); v(0) = 1; v(1) = 2; @@ -3424,7 +3432,7 @@ m(0,0) = 0; m(0,1) = 1; m(1,0) = 2; m(1,1) = 3; vector v2 = prod(m, v); -std::cout << v2 << std::endl; +cout << v2 << endl;

Blitz++

From 0b271b5746c5491c6a20d0e99d5691bab4e147b3 Mon Sep 17 00:00:00 2001 From: Benny Date: Thu, 11 Jan 2018 10:43:32 +0800 Subject: [PATCH 092/116] Update python.wiki --- libs/python.wiki | 174 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index 8e7a667..fe8e84c 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -424,6 +424,50 @@ Home:[https://pypi.python.org/pypi/setuptools] 这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) + +== 3.8 系统管理 == + +

sys

+【标准库】 + +这个模块可供访问由解释器使用或维护的变量和与解释器进行交互的函数。 + +代码示例 + +sys.argv # 命令行参数List,第一个元素是程序本身路径 +sys.exit(n) # 退出程序,正常退出时exit(0) +sys.version # 获取Python解释程序的版本信息 + + +

platform

+【标准库】 + +这个模块提供了很多用于获取操作系统的信息的功能。 + +代码示例 + +import platform + +platform.platform() # 获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1' +platform.version() # 获取操作系统版本号,'6.1.7601' +platform.architecture() # 获取操作系统的位数,('32bit', 'WindowsPE') + + +

psutil

+ +Home:[https://github.com/giampaolo/psutil] + +psutil(Python system and process utilities)是一个跨平台的进程管理和系统工具的python库,可以处理系统CPU,memory,disks,network等信息。主要用于系统资源的监控,分析,以及对进程进行一定的管理。 + +代码示例 + +import psutil + +psutil.cpu_count() # 获取CPU数量 +psutil.cpu_freq()   # 获取CPU频率 +psutil.virtual_memory()     # 获取内存信息 + + ---- = 4 Web = @@ -561,6 +605,36 @@ if __name__ == "__main__" : app.run() +

Flask

+ +Home:[http://flask.pocoo.org/] + +Links:[https://zh.wikipedia.org/wiki/Flask] + +轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎。 + +代码示例——Hello world + +from flask import Flask +app = Flask(__name__) + +@app.route('/') +def hello_world(): + return 'Hello World!' + +if __name__ == '__main__': + app.run() + + + +

Tornado

+ +Home:[http://www.tornadoweb.org/en/stable/] + +Links:[https://zh.wikipedia.org/wiki/Tornado] + +同样也是轻量级的Web框架,类似Web.py,但是异步非阻塞IO的处理方式使其拥有较为出色的抗负载能力。 + == 4.4 Web前端 & JS整合 ==

Pyjamas & pyjs

@@ -632,6 +706,34 @@ Home:[https://github.com/google/pywebsocket] 该项目包含一个可独立运行的 server 以及一个 Apache 扩展模块(mod_pywebsocket)。 +

selenium

+ +Home:[http://www.seleniumhq.org/] + +selenium是一个非常优秀的用于爬虫、Web自动化测试测试的框架。 + +代码示例(模拟登录) + + +from selenium import webdriver + +driver = webdriver.Chrome() + +driver.get('http://192.168.1.1') +driver.find_element_by_xpath('//*[@id="lgPwd"]').send_keys('123456') +driver.find_element_by_xpath('//*[@id="loginSub"]').click() +driver.quit() + + + +

scrapy

+ +Home:[https://scrapy.org/] + +Links:[https://en.wikipedia.org/wiki/Scrapy] +Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。 + + ---- = 5 网络 = @@ -761,6 +863,21 @@ with pysftp.Connection("hostxxx", username="userxxx", password="xxxxxx") as sftp 封装 POP3(Post Office Protocol v3)协议 +

yagmail

+ +Home:[https://github.com/kootenpv/yagmail] + +一个非常简单易用的用来发送邮件的第三方库。 + +代码示例 + +import yagmail +yag = yagmail.SMTP() +contents = ['This is the body, and here is just text http://somedomain/image.png', + 'You can find an audio file attached.', '/local/path/song.mp3'] +yag.send('to@someone.com', 'subject', contents) + + === 5.3.5 即时通讯 ===

jabber.py

@@ -813,6 +930,22 @@ Home:[https://github.com/citronneur/rdpy] 纯 Python 实现的 RDP([https://en.wikipedia.org/wiki/Remote_Desktop_Protocol 微软远程桌面协议])和 VNC([https://en.wikipedia.org/wiki/Virtual_Network_Computing Virtual Network Computing])客户端,依赖于 Twisted 库 +

paramiko

+ +Home:[http://www.paramiko.org/] + +paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接。除了SSH协议之外,paramiko还支持SFTP。 + +代码示例 + +import paramiko +ssh = paramiko.SSHClient() + +ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) +ssh.connect("IP", port, "username", "password") + + + === 5.3.7 (其它) ===

urlparse

@@ -1525,6 +1658,13 @@ Home:[http://code.enthought.com/chaco/] 这是一个商业公司维护的库,主要提供2维图表。效果图在“[http://docs.enthought.com/chaco/user_manual/annotated_examples.html 这里]”。 + +

Plotly

+ +Home:[https://plot.ly/d3-js-for-python-and-pandas-charts/] + +plotly是现代平台的敏捷商业智能和数据科学库,它作为一款开源的绘图库,可以应用于Python、R、MATLAB、Excel、JavaScript和jupyter等多种语言 + ---- = 8 信息安全 = @@ -1567,6 +1707,31 @@ Home:[https://github.com/google/keyczar] 它提供了比较高层的 API, 使用者无需关心太多的细节。 + +

passlib

+ +Home:[https://passlib.readthedocs.io/en/stable/index.html] + +passlib是一个久经考验的非常成熟的跨平台的散列函数库,他所提供的功能包括随机盐密码的生成与验证,两步验证等。 + +代码示例——验证随机盐密码 + +>>> # import the hash algorithm +>>> from passlib.hash import pbkdf2_sha256 + +>>> # generate new salt, and hash a password +>>> hash = pbkdf2_sha256.hash("toomanysecrets") +>>> hash +'$pbkdf2-sha256$29000$N2YMIWQsBWBMae09x1jrPQ$1t8iyB2A.WF/Z5JZv.lfCIhXXN33N23OSgQYThBYRfk' + +>>> # verifying the password +>>> pbkdf2_sha256.verify("toomanysecrets", hash) +True +>>> pbkdf2_sha256.verify("joshua", hash) +False + + + == 8.2 访问控制 ==

oauth2client

@@ -1719,6 +1884,15 @@ Home:[http://lxml.de/] 以回调方式解析 HTML/XHTML 文件内容。 +

beautifulsoup

+ +Home:[https://www.crummy.com/software/BeautifulSoup/bs4/doc/] + +Links:[https://zh.wikipedia.org/zh-cn/Beautiful_Soup] + +Beautiful Soup 是一个可以从HTML 或XML 文件中提取数据的Python 库,爬虫利器,通常与requests或者selenium配合。 + + == 9.4 PDF ==

pyfpdf

From 0eb16637748810d95845d4b060093fa6c221573d Mon Sep 17 00:00:00 2001 From: Benny Date: Thu, 11 Jan 2018 10:45:49 +0800 Subject: [PATCH 093/116] Update python.wiki --- libs/python.wiki | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index fe8e84c..7a22d73 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -712,7 +712,7 @@ Home:[http://www.seleniumhq.org/] selenium是一个非常优秀的用于爬虫、Web自动化测试测试的框架。 -代码示例(模拟登录) +代码示例——模拟登录 from selenium import webdriver @@ -731,6 +731,7 @@ driver.quit() Home:[https://scrapy.org/] Links:[https://en.wikipedia.org/wiki/Scrapy] + Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。 From ddceeb343810b94ca2b03ad37094a15d693ae0e1 Mon Sep 17 00:00:00 2001 From: Benny Date: Thu, 11 Jan 2018 10:58:38 +0800 Subject: [PATCH 094/116] =?UTF-8?q?sys,=20platform,=20psutil,=20flask,=20t?= =?UTF-8?q?ornado,=20selenium=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sys, platform, psutil, flask, tornado, selenium, scrapy, yagmail, paramiko, plotly, passlib, beautifulsoup, telegram --- libs/python.wiki | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 7a22d73..651fe4d 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -893,6 +893,19 @@ Home:[https://bitbucket.org/jaraco/irc] IRC 是 Internet Relay Chat 的缩写。这是用 Python 封装的第三方库。 +

pyTelegramBotAPI

+ +Home:[https://github.com/eternnoir/pyTelegramBotAPI] + +一个简单、易用的 [https://core.telegram.org/bots TelegramBot] 封装。 + +

Telethon

+ +Home:[https://github.com/LonamiWebs/Telethon] + +纯 Python 3 的 [https://telegram.org/ Telegram] 客户端封装。 + + === 5.3.6 远程控制 ===

telnetlib

@@ -1713,7 +1726,7 @@ Home:[https://github.com/google/keyczar] Home:[https://passlib.readthedocs.io/en/stable/index.html] -passlib是一个久经考验的非常成熟的跨平台的散列函数库,他所提供的功能包括随机盐密码的生成与验证,两步验证等。 +passlib是一个久经考验的非常成熟的跨平台的散列函数库,它所提供的功能包括随机盐密码的生成与验证,两步验证等。 代码示例——验证随机盐密码 From d1044390a9a0df4a47a32d97ccc0d82b1d4c350b Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 22:10:57 +0800 Subject: [PATCH 095/116] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E4=B8=AD=E7=9A=84=20HTML=20=E8=BD=AC?= =?UTF-8?q?=E4=B9=89=EF=BC=88=E8=B2=8C=E4=BC=BC=E4=B8=8D=E9=9C=80=E8=A6=81?= =?UTF-8?q?=E4=BA=86=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 116 ++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 63 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 651fe4d..825145a 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -296,7 +296,7 @@ threading.Thread(target=my_thread).start() import threading import time -from __future__ import print_function +from __future__ import print_function class MyThread(threading.Thread) : def run(self) : @@ -304,7 +304,7 @@ class MyThread(threading.Thread) : time.sleep(3) print("{} finished!".format(self.getName())) -if __name__ == "__main__" : +if __name__ == "__main__" : for n in range(10) : mythread = MyThread(name = "Thread-{}".format(n + 1)) mythread.start() @@ -322,8 +322,8 @@ if __name__ == "__main__" : 代码示例——启动命令行进程,并获取该进程的标准输出 import subprocess -output = subprocess.check_output(["dir"]) # 获取当前目录的内容 -output = subprocess.check_output(["netstat", "-an"]) # 获取当前网络链接 +output = subprocess.check_output(["dir"]) # 获取当前目录的内容 +output = subprocess.check_output(["netstat", "-an"]) # 获取当前网络链接

multiprocessing

@@ -343,7 +343,7 @@ def f(lock, n) : print("hello world %d" % n) lock.release() -if __name__ == "__main__" : +if __name__ == "__main__" : lock = Lock() for num in range(10): Process(target=f, args=(lock, num)).start() @@ -366,7 +366,7 @@ map = mmap.mmap(-1, 13) map.write("Hello, world") pid = os.fork() -if pid == 0 : # 子进程 +if pid == 0 : # 子进程 map.seek(0) print(map.readline()) map.close() @@ -424,10 +424,10 @@ Home:[https://pypi.python.org/pypi/setuptools] 这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) - == 3.8 系统管理 ==

sys

+ 【标准库】 这个模块可供访问由解释器使用或维护的变量和与解释器进行交互的函数。 @@ -440,6 +440,7 @@ sys.version # 获取Python解释程序的版本信息

platform

+ 【标准库】 这个模块提供了很多用于获取操作系统的信息的功能。 @@ -600,7 +601,7 @@ class index: def GET(self): return "Hello, world!" -if __name__ == "__main__" : +if __name__ == "__main__" : app = web.application(urls, globals()) app.run() @@ -609,7 +610,7 @@ if __name__ == "__main__" : Home:[http://flask.pocoo.org/] -Links:[https://zh.wikipedia.org/wiki/Flask] +Links:[https://zh.wikipedia.org/wiki/Flask 维基百科] 轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎。 @@ -624,14 +625,13 @@ def hello_world(): if __name__ == '__main__': app.run() -

Tornado

Home:[http://www.tornadoweb.org/en/stable/] -Links:[https://zh.wikipedia.org/wiki/Tornado] +Links:[https://zh.wikipedia.org/wiki/Tornado 维基百科] 同样也是轻量级的Web框架,类似Web.py,但是异步非阻塞IO的处理方式使其拥有较为出色的抗负载能力。 @@ -677,15 +677,15 @@ import PyV8 ctxt1 = PyV8.JSContext() ctxt1.enter() -ctxt1.eval("1+2") # 对 JS 表达式求值 +ctxt1.eval("1+2") # 对 JS 表达式求值 -class Global(PyV8.JSClass) : # 定义一个兼容 JS 的类 +class Global(PyV8.JSClass) : # 定义一个兼容 JS 的类 def hello(self) : print("Hello, world") -ctxt2 = PyV8.JSContext(Global()) # 创建一个 JS 上下文,传入 Global 类的对象 +ctxt2 = PyV8.JSContext(Global()) # 创建一个 JS 上下文,传入 Global 类的对象 ctxt2.enter() -ctxt2.eval("hello()") # 调用 hello() 函数 +ctxt2.eval("hello()") # 调用 hello() 函数

PyWebKitGtk

@@ -714,27 +714,23 @@ selenium是一个非常优秀的用于爬虫、Web自动化测试测试的框架 代码示例——模拟登录 - from selenium import webdriver driver = webdriver.Chrome() - driver.get('http://192.168.1.1') driver.find_element_by_xpath('//*[@id="lgPwd"]').send_keys('123456') driver.find_element_by_xpath('//*[@id="loginSub"]').click() driver.quit() -

scrapy

Home:[https://scrapy.org/] -Links:[https://en.wikipedia.org/wiki/Scrapy] +Links:[https://en.wikipedia.org/wiki/Scrapy Wikipedia] Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。 - ---- = 5 网络 = @@ -753,10 +749,10 @@ Links:[https://en.wikipedia.org/wiki/Scapy Wikipedia] 代码示例 -# 传统的 ping 扫描(网络层) +# 传统的 ping 扫描(网络层) ans,unans = sr(IP(dst="192.168.1.1-254")/ICMP()) -# 局域网内的 ARP 扫描(链路层) +# 局域网内的 ARP 扫描(链路层) ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2) @@ -821,10 +817,10 @@ body = buffer.getvalue() from ftplib import FTP -ftp = FTP("ftp.debian.org") # 连接服务器(如果不指定端口号,则用默认端口号 21) -ftp.login() # 登录(如果不指定用户名和密码,则用匿名登录) -ftp.cwd("debian") # 切换到 "debian" 目录 -ftp.retrlines("LIST") # 列出当前目录的内容 +ftp = FTP("ftp.debian.org") # 连接服务器(如果不指定端口号,则用默认端口号 21) +ftp.login() # 登录(如果不指定用户名和密码,则用匿名登录) +ftp.cwd("debian") # 切换到 "debian" 目录 +ftp.retrlines("LIST") # 列出当前目录的内容 ftp.quit() @@ -839,9 +835,9 @@ Home:[https://bitbucket.org/dundeemt/pysftp] import pysftp with pysftp.Connection("hostxxx", username="userxxx", password="xxxxxx") as sftp : - with sftp.cd("public") # 服务端当前目录切换到 public - sftp.put("/my/local/filename") # 上传某个本地文件到服务端的 public 目录 - sftp.get_r("myfiles", "/local") # 递归复制某个服务端的目录到本地 + with sftp.cd("public") # 服务端当前目录切换到 public + sftp.put("/my/local/filename") # 上传某个本地文件到服务端的 public 目录 + sftp.get_r("myfiles", "/local") # 递归复制某个服务端的目录到本地 === 5.3.4 电子邮件 === @@ -905,7 +901,6 @@ Home:[https://github.com/LonamiWebs/Telethon] 纯 Python 3 的 [https://telegram.org/ Telegram] 客户端封装。 - === 5.3.6 远程控制 ===

telnetlib

@@ -959,7 +954,6 @@ ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("IP", port, "username", "password") - === 5.3.7 (其它) ===

urlparse

@@ -1057,7 +1051,7 @@ Home:[https://github.com/tonysimpson/nanomsg-python] 代码示例——Hello world -from __future__ import print_function +from __future__ import print_function from nanomsg import Socket, PAIR, PUB s1 = Socket(PAIR) @@ -1230,7 +1224,7 @@ sqlite3 从 Python 2.5 版本开始加入到标准库中。通过它,你可以 代码示例——创建一个内存数据库,建表并插入记录 import sqlite3 -conn = sqlite3.connect(":memory:") # ":memory:" 表示这是一个内存数据库 +conn = sqlite3.connect(":memory:") # ":memory:" 表示这是一个内存数据库 cursor = conn.cursor() cursor.execute("CREATE TABLE person (name text, age int)") cursor.execute("INSERT INTO stocks VALUES ('TOM',20)") @@ -1324,7 +1318,7 @@ from sqlalchemy.orm import relation, sessionmaker Base = declarative_base() class Movie(Base) : - __tablename__ = "movies" + __tablename__ = "movies" id = Column(Integer, primary_key=True) title = Column(String(255), nullable=False) @@ -1332,23 +1326,23 @@ class Movie(Base) : directed_by = Column(Integer, ForeignKey("directors.id")) director = relation("Director", backref="movies", lazy=False) - def __init__(self, title=None, year=None) : + def __init__(self, title=None, year=None) : self.title = title self.year = year - def __repr__(self) : + def __repr__(self) : return "Movie(%r, %r, %r)" % (self.title, self.year, self.director) class Director(Base) : - __tablename__ = "directors" + __tablename__ = "directors" id = Column(Integer, primary_key=True) name = Column(String(50), nullable=False, unique=True) - def __init__(self, name=None) : + def __init__(self, name=None) : self.name = name - def __repr__(self) : + def __repr__(self) : return "Director(%r)" % (self.name) Base.metadata.create_all(create_engine("dbms://user:pwd@host/dbname")) @@ -1393,14 +1387,14 @@ class Person(Model) : birthday = DateField() is_relative = BooleanField() class Meta : - database = db # This model uses the "test.db". + database = db # This model uses the "test.db". class Pet(Model) : owner = ForeignKeyField(Person, related_name="pets") name = CharField() animal_type = CharField() class Meta : - database = db # This model uses the "test.db". + database = db # This model uses the "test.db". db.connect() db.create_tables([Person, Pet]) @@ -1428,7 +1422,7 @@ Python2 的模块名叫 Tkinter,到 Python3 模块名改为 tkinter from Tkinter import * -if __name__ == "__main__" : +if __name__ == "__main__" : root = Tk() label = Label(root, text="Hello, world") label.pack() @@ -1462,7 +1456,7 @@ class App(wx.App) : self.SetTopWindow(self.frame) return True -if __name__ == "__main__" : +if __name__ == "__main__" : app = App() app.MainLoop() @@ -1491,7 +1485,7 @@ pygtk.require("2.0") import gtk class HelloWorld : - def __init__(self) : + def __init__(self) : self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) @@ -1518,7 +1512,7 @@ class HelloWorld : def destroy(self, widget, data=None) : gtk.main_quit() -if __name__ == "__main__" : +if __name__ == "__main__" : hello = HelloWorld() hello.main() @@ -1534,8 +1528,8 @@ Home:[https://live.gnome.org/PyGObject] from gi.repository import Gtk class MyWindow(Gtk.Window): - def __init__(self): - Gtk.Window.__init__(self, title="Hello World") + def __init__(self): + Gtk.Window.__init__(self, title="Hello World") self.button = Gtk.Button(label="Click Here") self.button.connect("clicked", self.on_button_clicked) @@ -1567,7 +1561,7 @@ Links:[https://en.wikipedia.org/wiki/PyQt Wikipedia] [https://zh.wikipedia.org import sys from PyQt4.QtGui import * -if __name__ == "__main__" : +if __name__ == "__main__" : app = QApplication(sys.argv) window = QWidget() @@ -1672,7 +1666,6 @@ Home:[http://code.enthought.com/chaco/] 这是一个商业公司维护的库,主要提供2维图表。效果图在“[http://docs.enthought.com/chaco/user_manual/annotated_examples.html 这里]”。 -

Plotly

Home:[https://plot.ly/d3-js-for-python-and-pandas-charts/] @@ -1721,7 +1714,6 @@ Home:[https://github.com/google/keyczar] 它提供了比较高层的 API, 使用者无需关心太多的细节。 -

passlib

Home:[https://passlib.readthedocs.io/en/stable/index.html] @@ -1745,7 +1737,6 @@ True False - == 8.2 访问控制 ==

oauth2client

@@ -1783,14 +1774,14 @@ JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。 import json json.dumps(["foo", {"bar": ("baz", None, 1.0, 2)}]) -# JSON 编码 -# 得到如下【字符串】 -# """["foo", {"bar": ["baz", null, 1.0, 2]}]""" +# JSON 编码 +# 得到如下【字符串】 +# """["foo", {"bar": ["baz", null, 1.0, 2]}]""" json.loads("""["foo", {"bar":["baz", null, 1.0, 2]}]""") -# JSON 解码 -# 得到如下【对象】 -# [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] +# JSON 解码 +# 得到如下【对象】 +# [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] === 9.1.3 YAML === @@ -1902,11 +1893,10 @@ Home:[http://lxml.de/] Home:[https://www.crummy.com/software/BeautifulSoup/bs4/doc/] -Links:[https://zh.wikipedia.org/zh-cn/Beautiful_Soup] +Links:[https://zh.wikipedia.org/zh-cn/Beautiful_Soup 维基百科] Beautiful Soup 是一个可以从HTML 或XML 文件中提取数据的Python 库,爬虫利器,通常与requests或者selenium配合。 - == 9.4 PDF ==

pyfpdf

@@ -2105,11 +2095,11 @@ Home:[https://github.com/xflr6/graphviz] from graphviz import Digraph dot = Digraph(comment='The Round Table') -# 添加节点 +# 添加节点 dot.node('A', 'King Arthur') dot.node('B', 'Sir Bedevere the Wise') dot.node('L', 'Sir Lancelot the Brave') -# 添加连线 +# 添加连线 dot.edges(['AB', 'AL']) dot.edge('B', 'L', constraint='false') @@ -2196,14 +2186,14 @@ Links:[https://en.wikipedia.org/wiki/NumPy Wikipedia] [https://zh.wikipedia.or 代码示例 -# 以下是传统 Python 写法,冗长且速度较慢 +# 以下是传统 Python 写法,冗长且速度较慢 a = range(10000000) b = range(10000000) c = [] for i in range(len(a)) : c.append(a[i] + b[i]) -# 以下是 NumPy 的写法,简洁且速度飞快 +# 以下是 NumPy 的写法,简洁且速度飞快 import numpy as np a = np.arange(10000000) b = np.arange(10000000) From 330a7d7261217f465c4c3de4fe7b05e1cf88c647 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 22:32:13 +0800 Subject: [PATCH 096/116] =?UTF-8?q?=E7=BB=9F=E4=B8=80=E7=A4=BA=E4=BE=8B?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 85 ++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 825145a..ae59560 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -296,7 +296,7 @@ threading.Thread(target=my_thread).start() import threading import time -from __future__ import print_function +from __future__ import print_function class MyThread(threading.Thread) : def run(self) : @@ -304,7 +304,7 @@ class MyThread(threading.Thread) : time.sleep(3) print("{} finished!".format(self.getName())) -if __name__ == "__main__" : +if __name__ == "__main__" : for n in range(10) : mythread = MyThread(name = "Thread-{}".format(n + 1)) mythread.start() @@ -343,7 +343,7 @@ def f(lock, n) : print("hello world %d" % n) lock.release() -if __name__ == "__main__" : +if __name__ == "__main__" : lock = Lock() for num in range(10): Process(target=f, args=(lock, num)).start() @@ -434,9 +434,9 @@ Home:[https://pypi.python.org/pypi/setuptools] 代码示例 -sys.argv # 命令行参数List,第一个元素是程序本身路径 -sys.exit(n) # 退出程序,正常退出时exit(0) -sys.version # 获取Python解释程序的版本信息 +sys.argv # 命令行参数 List,第一个元素是程序本身路径 +sys.exit(0) # 退出程序,正常退出时用 0 表示退出码 +sys.version # 获取 Python 解释程序的版本信息

platform

@@ -449,9 +449,9 @@ sys.version # 获取Python解释程序的版本信息 import platform -platform.platform() # 获取操作系统名称及版本号,'Windows-7-6.1.7601-SP1' -platform.version() # 获取操作系统版本号,'6.1.7601' -platform.architecture() # 获取操作系统的位数,('32bit', 'WindowsPE') +platform.platform() # 获取操作系统名称及版本号,例如:"Windows-7-6.1.7601-SP1" +platform.version() # 获取操作系统版本号,例如:"6.1.7601" +platform.architecture() # 获取操作系统的架构,例如:("32bit", "WindowsPE")

psutil

@@ -464,9 +464,9 @@ psutil(Python system and process utilities)是一个跨平台的进程管理和 import psutil -psutil.cpu_count() # 获取CPU数量 -psutil.cpu_freq()   # 获取CPU频率 -psutil.virtual_memory()     # 获取内存信息 +psutil.cpu_count() # 获取 CPU 数量 +psutil.cpu_freq() # 获取 CPU 频率 +psutil.virtual_memory() # 获取内存信息 ---- @@ -571,8 +571,8 @@ Links:[https://en.wikipedia.org/wiki/CherryPy Wikipedia] import cherrypy -class HelloWorld(object): - def index(self): +class HelloWorld(object) : + def index(self) : return "Hello World!" index.exposed = True @@ -597,11 +597,11 @@ urls = ( "/", "index" ) -class index: - def GET(self): +class index : + def GET(self) : return "Hello, world!" -if __name__ == "__main__" : +if __name__ == "__main__" : app = web.application(urls, globals()) app.run() @@ -617,13 +617,13 @@ Links:[https://zh.wikipedia.org/wiki/Flask 维基百科] 代码示例——Hello world from flask import Flask -app = Flask(__name__) +app = Flask(__name__) -@app.route('/') -def hello_world(): - return 'Hello World!' +app.route("/") +def hello_world() : + return “Hello World!" -if __name__ == '__main__': +if __name__ == "__main__" : app.run() @@ -717,8 +717,8 @@ selenium是一个非常优秀的用于爬虫、Web自动化测试测试的框架 from selenium import webdriver driver = webdriver.Chrome() -driver.get('http://192.168.1.1') -driver.find_element_by_xpath('//*[@id="lgPwd"]').send_keys('123456') +driver.get("http://192.168.1.1") +driver.find_element_by_xpath('//*[@id="lgPwd"]').send_keys("123456") driver.find_element_by_xpath('//*[@id="loginSub"]').click() driver.quit() @@ -869,10 +869,11 @@ Home:[https://github.com/kootenpv/yagmail] 代码示例 import yagmail + yag = yagmail.SMTP() -contents = ['This is the body, and here is just text http://somedomain/image.png', - 'You can find an audio file attached.', '/local/path/song.mp3'] -yag.send('to@someone.com', 'subject', contents) +contents = ["This is the body, and here is just text http://somedomain/image.png", + "You can find an audio file attached.', '/local/path/song.mp3"] +yag.send("to@someone.com", "subject", contents) === 5.3.5 即时通讯 === @@ -948,8 +949,8 @@ paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加 代码示例 import paramiko -ssh = paramiko.SSHClient() +ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect("IP", port, "username", "password") @@ -1051,7 +1052,7 @@ Home:[https://github.com/tonysimpson/nanomsg-python] 代码示例——Hello world -from __future__ import print_function +from __future__ import print_function from nanomsg import Socket, PAIR, PUB s1 = Socket(PAIR) @@ -1318,7 +1319,7 @@ from sqlalchemy.orm import relation, sessionmaker Base = declarative_base() class Movie(Base) : - __tablename__ = "movies" + __tablename__ = "movies" id = Column(Integer, primary_key=True) title = Column(String(255), nullable=False) @@ -1326,23 +1327,23 @@ class Movie(Base) : directed_by = Column(Integer, ForeignKey("directors.id")) director = relation("Director", backref="movies", lazy=False) - def __init__(self, title=None, year=None) : + def __init__(self, title=None, year=None) : self.title = title self.year = year - def __repr__(self) : + def __repr__(self) : return "Movie(%r, %r, %r)" % (self.title, self.year, self.director) class Director(Base) : - __tablename__ = "directors" + __tablename__ = "directors" id = Column(Integer, primary_key=True) name = Column(String(50), nullable=False, unique=True) - def __init__(self, name=None) : + def __init__(self, name=None) : self.name = name - def __repr__(self) : + def __repr__(self) : return "Director(%r)" % (self.name) Base.metadata.create_all(create_engine("dbms://user:pwd@host/dbname")) @@ -1422,7 +1423,7 @@ Python2 的模块名叫 Tkinter,到 Python3 模块名改为 tkinter from Tkinter import * -if __name__ == "__main__" : +if __name__ == "__main__" : root = Tk() label = Label(root, text="Hello, world") label.pack() @@ -1456,7 +1457,7 @@ class App(wx.App) : self.SetTopWindow(self.frame) return True -if __name__ == "__main__" : +if __name__ == "__main__" : app = App() app.MainLoop() @@ -1485,7 +1486,7 @@ pygtk.require("2.0") import gtk class HelloWorld : - def __init__(self) : + def __init__(self) : self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) self.window.connect("delete_event", self.delete_event) self.window.connect("destroy", self.destroy) @@ -1512,7 +1513,7 @@ class HelloWorld : def destroy(self, widget, data=None) : gtk.main_quit() -if __name__ == "__main__" : +if __name__ == "__main__" : hello = HelloWorld() hello.main() @@ -1528,8 +1529,8 @@ Home:[https://live.gnome.org/PyGObject] from gi.repository import Gtk class MyWindow(Gtk.Window): - def __init__(self): - Gtk.Window.__init__(self, title="Hello World") + def __init__(self): + Gtk.Window.__init__(self, title="Hello World") self.button = Gtk.Button(label="Click Here") self.button.connect("clicked", self.on_button_clicked) @@ -1561,7 +1562,7 @@ Links:[https://en.wikipedia.org/wiki/PyQt Wikipedia] [https://zh.wikipedia.org import sys from PyQt4.QtGui import * -if __name__ == "__main__" : +if __name__ == "__main__" : app = QApplication(sys.argv) window = QWidget() From 496dfe4c1899a7de5b62db5fa3a4bec44f7807fe Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 22:41:11 +0800 Subject: [PATCH 097/116] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E8=8B=A5=E5=B9=B2?= =?UTF-8?q?=E5=BA=93=E7=9A=84=20home=20=E7=BD=91=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index ae59560..a4703d7 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -629,7 +629,7 @@ if __name__ == "__main__" :

Tornado

-Home:[http://www.tornadoweb.org/en/stable/] +Home:[http://www.tornadoweb.org/] Links:[https://zh.wikipedia.org/wiki/Tornado 维基百科] @@ -1669,7 +1669,7 @@ Home:[http://code.enthought.com/chaco/]

Plotly

-Home:[https://plot.ly/d3-js-for-python-and-pandas-charts/] +Home:[https://plot.ly/] plotly是现代平台的敏捷商业智能和数据科学库,它作为一款开源的绘图库,可以应用于Python、R、MATLAB、Excel、JavaScript和jupyter等多种语言 @@ -1717,7 +1717,7 @@ Home:[https://github.com/google/keyczar]

passlib

-Home:[https://passlib.readthedocs.io/en/stable/index.html] +Home:[https://bitbucket.org/ecollins/passlib/] passlib是一个久经考验的非常成熟的跨平台的散列函数库,它所提供的功能包括随机盐密码的生成与验证,两步验证等。 @@ -1892,7 +1892,7 @@ Home:[http://lxml.de/]

beautifulsoup

-Home:[https://www.crummy.com/software/BeautifulSoup/bs4/doc/] +Home:[https://www.crummy.com/software/BeautifulSoup/] Links:[https://zh.wikipedia.org/zh-cn/Beautiful_Soup 维基百科] From 15a95bed36fff8df2b5da4304cc421e523ed1206 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 22:44:20 +0800 Subject: [PATCH 098/116] =?UTF-8?q?=E8=B0=83=E6=95=B4=E2=80=9D=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E7=B3=BB=E7=BB=9F=E2=80=9C=E4=B8=8B=E7=BA=A7=E5=88=86?= =?UTF-8?q?=E7=B1=BB=E7=9A=84=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index a4703d7..746b584 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -378,53 +378,7 @@ if pid == 0 : # 子进程 用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 -== 3.5 Linux & Unix 系统相关 == - -

syslog

- -【标准库】 - -通过它可以很方便地跟 POSIX 的 syslog 服务进行交互。 - -== 3.6 Windows 系统相关 == - -

PyWin32

- -Home:[http://python.net/crew/mhammond/win32/] - -这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 - -== 3.7 程序打包 == - -

PyInstaller

- -Home:[http://www.pyinstaller.org/] - -PyInstaller 可以把你的 Python 代码制作成独立运行的程序(不依赖 Python 环境就可以运行)。 - -该工具支持多种操作系统,包括:Windows、Linux、Mac OS X、Solaris、AIX、等。 - -

py2exe

- -Home:[http://www.py2exe.org/] - -Links:[https://en.wikipedia.org/wiki/Py2exe Wikipedia] - -py2exe 的功能类似 PyInstaller,但只支持 Windows 平台。 - -

py2app

- -Home:[https://bitbucket.org/ronaldoussoren/py2app] - -它很类似于 [http://www.py2exe.org/ py2exe],差别在于 [http://www.py2exe.org/ py2exe] 支持 Windows 平台,而 [https://bitbucket.org/ronaldoussoren/py2app py2app] 支持 Mac OS X 平台。 - -

EasyInstall & Setuptools

- -Home:[https://pypi.python.org/pypi/setuptools] - -这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) - -== 3.8 系统管理 == +== 3.5 获取系统信息 ==

sys

@@ -469,6 +423,52 @@ psutil.cpu_freq() # 获取 CPU 频率 psutil.virtual_memory() # 获取内存信息 +== 3.6 Linux & Unix 系统相关 == + +

syslog

+ +【标准库】 + +通过它可以很方便地跟 POSIX 的 syslog 服务进行交互。 + +== 3.7 Windows 系统相关 == + +

PyWin32

+ +Home:[http://python.net/crew/mhammond/win32/] + +这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 + +== 3.8 程序打包 == + +

PyInstaller

+ +Home:[http://www.pyinstaller.org/] + +PyInstaller 可以把你的 Python 代码制作成独立运行的程序(不依赖 Python 环境就可以运行)。 + +该工具支持多种操作系统,包括:Windows、Linux、Mac OS X、Solaris、AIX、等。 + +

py2exe

+ +Home:[http://www.py2exe.org/] + +Links:[https://en.wikipedia.org/wiki/Py2exe Wikipedia] + +py2exe 的功能类似 PyInstaller,但只支持 Windows 平台。 + +

py2app

+ +Home:[https://bitbucket.org/ronaldoussoren/py2app] + +它很类似于 [http://www.py2exe.org/ py2exe],差别在于 [http://www.py2exe.org/ py2exe] 支持 Windows 平台,而 [https://bitbucket.org/ronaldoussoren/py2app py2app] 支持 Mac OS X 平台。 + +

EasyInstall & Setuptools

+ +Home:[https://pypi.python.org/pypi/setuptools] + +这套工具可以帮助你进行第三方库的管理(下载、编译、安装、升级、卸载) + ---- = 4 Web = From ee28561782845c2e240408a3cdfcc8f6ac71feb8 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 22:54:31 +0800 Subject: [PATCH 099/116] =?UTF-8?q?=E5=AE=8C=E5=96=84=20yagmail=20?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 746b584..b1e75c0 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -870,7 +870,7 @@ Home:[https://github.com/kootenpv/yagmail] import yagmail -yag = yagmail.SMTP() +yag = yagmail.SMTP("my_gmail_username", "my_gmail_password") contents = ["This is the body, and here is just text http://somedomain/image.png", "You can find an audio file attached.', '/local/path/song.mp3"] yag.send("to@someone.com", "subject", contents) From d5c6f40db76f360f52c7c25e9287b3cb75f796ad Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 23:03:35 +0800 Subject: [PATCH 100/116] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=87=A0=E4=B8=AA?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BA=93=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index b1e75c0..ef1b208 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -612,7 +612,7 @@ Home:[http://flask.pocoo.org/] Links:[https://zh.wikipedia.org/wiki/Flask 维基百科] -轻量级Web应用框架。基于Werkzeug WSGI工具箱和Jinja2 模板引擎。 +轻量级 Web 应用框架。基于 Werkzeug WSGI 工具箱和 Jinja2 模板引擎。 代码示例——Hello world @@ -633,7 +633,7 @@ Home:[http://www.tornadoweb.org/] Links:[https://zh.wikipedia.org/wiki/Tornado 维基百科] -同样也是轻量级的Web框架,类似Web.py,但是异步非阻塞IO的处理方式使其拥有较为出色的抗负载能力。 +同样也是轻量级的 Web 框架,类似 Web.py。提供异步非阻塞 IO 的处理方式使其拥有较为出色的抗负载能力。 == 4.4 Web前端 & JS整合 == @@ -710,7 +710,7 @@ Home:[https://github.com/google/pywebsocket] Home:[http://www.seleniumhq.org/] -selenium是一个非常优秀的用于爬虫、Web自动化测试测试的框架。 +selenium 是一个非常优秀的框架,用于爬虫和 Web 自动化测试。 代码示例——模拟登录 @@ -729,7 +729,9 @@ Home:[https://scrapy.org/] Links:[https://en.wikipedia.org/wiki/Scrapy Wikipedia] -Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。 +Scrapy 是一个为了爬取网站数据,提取结构性数据而编写的应用框架。 + +可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中。 ---- @@ -900,7 +902,7 @@ Home:[https://github.com/eternnoir/pyTelegramBotAPI] Home:[https://github.com/LonamiWebs/Telethon] -纯 Python 3 的 [https://telegram.org/ Telegram] 客户端封装。 +纯 Python3 的 [https://telegram.org/ Telegram] 客户端封装。 === 5.3.6 远程控制 === @@ -944,7 +946,9 @@ Home:[https://github.com/citronneur/rdpy] Home:[http://www.paramiko.org/] -paramiko是用python语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接。除了SSH协议之外,paramiko还支持SFTP。 +paramiko 是用 python 语言写的一个模块,遵循SSH2协议,支持以加密和认证的方式,进行远程服务器的连接。 + +除了 SSH 协议之外,paramiko 还支持SFTP。 代码示例 @@ -1671,7 +1675,9 @@ Home:[http://code.enthought.com/chaco/] Home:[https://plot.ly/] -plotly是现代平台的敏捷商业智能和数据科学库,它作为一款开源的绘图库,可以应用于Python、R、MATLAB、Excel、JavaScript和jupyter等多种语言 +plotly 是现代平台的敏捷商业智能和数据科学库。 + +它作为一款开源的绘图库,可以应用于 Python、R、MATLAB、Excel、JavaScript、jupyter 等多种语言。 ---- @@ -1719,7 +1725,7 @@ Home:[https://github.com/google/keyczar] Home:[https://bitbucket.org/ecollins/passlib/] -passlib是一个久经考验的非常成熟的跨平台的散列函数库,它所提供的功能包括随机盐密码的生成与验证,两步验证等。 +passlib 是一个久经考验的非常成熟的跨平台的散列函数库,它所提供的功能包括随机盐密码的生成与验证,两步验证等。 代码示例——验证随机盐密码 @@ -1896,7 +1902,9 @@ Home:[https://www.crummy.com/software/BeautifulSoup/] Links:[https://zh.wikipedia.org/zh-cn/Beautiful_Soup 维基百科] -Beautiful Soup 是一个可以从HTML 或XML 文件中提取数据的Python 库,爬虫利器,通常与requests或者selenium配合。 +Beautiful Soup 可以从 HTML 或 XML 文件中提取数据。 + +它是写”爬虫“的利器,通常与 requests 或 selenium 配合。 == 9.4 PDF == From 81943cd673508d4b04d4352f498028287dd992f0 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 27 Apr 2018 23:26:15 +0800 Subject: [PATCH 101/116] =?UTF-8?q?=E5=AE=8C=E5=96=84=20psutil=20=E7=9A=84?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E5=92=8C=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index ef1b208..4ecc184 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -412,7 +412,9 @@ platform.architecture() # 获取操作系统的架构,例如:("32bit", "Win Home:[https://github.com/giampaolo/psutil] -psutil(Python system and process utilities)是一个跨平台的进程管理和系统工具的python库,可以处理系统CPU,memory,disks,network等信息。主要用于系统资源的监控,分析,以及对进程进行一定的管理。 +psutil(Python system and process utilities)是一个跨平台的进程管理和系统工具库,可以处理”CPU、内存、磁盘、网络、用户“等信息。 + +主要用于系统资源的监控,分析,以及对进程进行一定的管理。 代码示例 @@ -420,7 +422,20 @@ import psutil psutil.cpu_count() # 获取 CPU 数量 psutil.cpu_freq() # 获取 CPU 频率 + psutil.virtual_memory() # 获取内存信息 +psutil.swap_memory() # 获取交换分区(换页文件)信息 + +psutil.disk_partitions() # 获取分区信息 +psutil.disk_usage('/') # 获取某分区的使用情况 + +psutil.users() # 获取用户信息 + +p = psutil.Process(pid) # 根据给定的 pid 获得进程对象 +p.name() # 进程名 +p.exe() # 可执行程序的全路径 +p.cwd() # 进程的当前目录 +p.cmdline() # 启动进程的命令行参数 == 3.6 Linux & Unix 系统相关 == From 53ae70d5fd0b3d15a2a3384660d77e766b2f0371 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 4 Aug 2018 19:56:14 +0800 Subject: [PATCH 102/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20cpr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 8ad9411..3054f20 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -2517,6 +2517,28 @@ Docs:[http://pocoproject.org/docs/package-Net.HTTPClient.html] POCO 前面已经介绍过。它提供了 HTTP Client 的封装类。 +

cpr

+ +Home:[https://github.com/whoshuu/cpr] + +类似 Python 的 [http://docs.python-requests.org/ Requests 库],以【优雅的语法】实现 HTTP 请求。 + +代码示例——HTTP GET + +#include + +int main() +{ + auto r = cpr::Get(cpr::Url{"https://api.github.com/repos/whoshuu/cpr/contributors"}, + cpr::Authentication{"user", "pass"}, + cpr::Parameters{{"anon", "true"}, {"key", "value"}}); + r.status_code; // 200 + r.header["content-type"]; // application/json; charset=utf-8 + r.text; // JSON text string + return 0; +} + + == 10.3 浏览器引擎 ==

WebKit

From e41f440b31e25e32faee7250a107b47db8942802 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 4 Aug 2018 20:23:20 +0800 Subject: [PATCH 103/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20docopt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 3054f20..2bef0f4 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1388,6 +1388,57 @@ Boost 前面已经介绍过。这是 Boost 的其中一个子库,提供了“ 它的功能很丰富,但是比较重型。 +

docopt

+ +Home:[https://github.com/docopt/docopt.cpp] + +这是一个很有创意的库,提供了一种【全新】的方式来处理命令行参数。 + +你只需定义好命令行的帮助文本(usage),该库会根据 usage 文本自动分析出命令行参数的定义。 + +也就是说:用了这个库,就无需再写一大堆 parse 命令行参数的代码 :) + +代码示例 + +#include +#include + +static const char USAGE[] = +R"(Naval Fate. + + Usage: + naval_fate ship new ... + naval_fate ship move [--speed=] + naval_fate ship shoot + naval_fate mine (set|remove) [--moored | --drifting] + naval_fate (-h | --help) + naval_fate --version + + Options: + -h --help Show this screen. + --version Show version. + --speed= Speed in knots [default: 10]. + --moored Moored (anchored) mine. + --drifting Drifting mine. +)"; + +int main(int argc, const char* argv[]) +{ + std::map args + = docopt::docopt(USAGE, + { argv + 1, argv + argc }, + true, // 是否显示帮助 + "Naval Fate 2.0"); // 版本号 + + for(auto const& arg : args) + { + std::cout << arg.first << arg.second << std::endl; + } + +return 0; +} + + == 7.2 文本终端 ==

ncurses

From 1aab23863384ead7e4c2a8ed44d628bc1b0bb1e0 Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 4 Aug 2018 20:57:24 +0800 Subject: [PATCH 104/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20simple=5Fmatch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 2bef0f4..fb32af5 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -753,6 +753,35 @@ vector v; for_each(v.begin(), v.end(), cout << boost::lambda::_1 << "\n"); +

simple_match

+ +Home:[https://github.com/jbandela/simple_match] + +这个库是为了提供类似 Rust 语言中的 match 语法。 + +(不懂 Rust 的同学,可以把 match 语法视作增强版的 switch/case) + +代码示例 + +#include +#include +using namespace simple_match; +using namespace simple_match::placeholders; + +int x = 0; +while (true) +{ + std::cin >> x; + match(x, + 1, []() { std::cout << "one\n"; }, + 2, []() { std::cout << "two\n"; }, + _x < 10, [](auto&& n) { std::cout << n << " is less than 10\n"; }, + 10 < _x < 20, [](auto&& n) { std::cout << n << " is between 10 and 20 exclusive\n"; }, + _, []() { std::cout << "NOT match\n"; } + ); +} + + == 3.4 元编程(Metaprogramming) == (不知道何为“元编程”,可以先看[https://zh.wikipedia.org/wiki/%E5%85%83%E7%BC%96%E7%A8%8B 维基百科]) From 490156aaa53e7769694b5cd4cede737ef8065ece Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 4 Aug 2018 21:08:10 +0800 Subject: [PATCH 105/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Poppler?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index fb32af5..0103134 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -3073,6 +3073,18 @@ Home:[http://podofo.sourceforge.net/] 它既支持 PDF 文件的生成,也支持 PDF 内容的提取。它同时还提供[http://podofo.sourceforge.net/tools.html 一堆命令行的小工具],用来操作 PDF 文件。 +

Poppler

+ +Home:[https://poppler.freedesktop.org/] + +Links:[https://en.wikipedia.org/wiki/Poppler_%28software%29 Wikipedia] + +派生自 Xpdf 3.0 的开源库,用于渲染 PDF 的内容。很多开源的 PDF 阅读软件用到它。 + +在开源界,它第一个【完整】实现了 ISO 32000-1(PDF 的 ISO 标准)。 + +它内置了若干命令行工具(poppler-utils),可以用来进行 PDF 的内容提取和格式转换。 +

LibHaru

Home:[http://libharu.org/] From 9b71c58132fab40f4de0719e9f17c7b913466e2b Mon Sep 17 00:00:00 2001 From: programthink Date: Sat, 4 Aug 2018 21:57:56 +0800 Subject: [PATCH 106/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Scintilla?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 0103134..e4a6bd2 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -1330,6 +1330,18 @@ Home:[http://wxmathplot.sourceforge.net/] 看名称就知道它是跟 wxWidgets 搭配的。效果图参见“[http://wxmathplot.sourceforge.net/screenshot.shtml 这里]” +== 6.3 文本编辑 == + +

Scintilla

+ +Home:[https://scintilla.org/] + +Links:[https://en.wikipedia.org/wiki/Scintilla_(software) Wikipedia] + +功能【超强】的文本编辑组件,支持:词法高亮、代码折叠、自动补全、动态提示......(基本上你能想到的,它都已经有了) + +不光功能齐全,还支持各种主流的操作系统平台。很多编辑器/IDE 用到它。 + ---- = 7 文本用户界面(TUI) = From 143c3755f1d398e04147a33666d661e19a9d610c Mon Sep 17 00:00:00 2001 From: programthink Date: Sun, 5 Aug 2018 17:31:25 +0800 Subject: [PATCH 107/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Cython?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index e4a6bd2..58a62a1 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -3650,6 +3650,16 @@ BOOST_PYTHON_MODULE(hello_ext) // print(hello_ext.greet()) +

Cython

+ +Home:[http://cython.org/] + +Links:[https://en.wikipedia.org/wiki/Cython Wikipedia] + +Cython 提供了一种机制(编译器)编译 Python 代码为【原生代码】。编译后的原生代码是个 Python 的 module(扩展名是 pyd 或 so),可以在常规的 Python 环境中用 import 语句加载。如此一来,既得到了类似 C/C++ 的高性能,又保留了 Python 语法的简介性。 + +另外,它也提供了把 C/C++ 代码编译为 Python 模块的机制。 + ---- = 18 (其它) = From 03120d5d4ec8c6b4196809b95cedfedff28be5fc Mon Sep 17 00:00:00 2001 From: programthink Date: Sun, 5 Aug 2018 18:05:07 +0800 Subject: [PATCH 108/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20V8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 58a62a1..3efc90e 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -3660,6 +3660,72 @@ Cython 提供了一种机制(编译器)编译 Python 代码为【原生代 另外,它也提供了把 C/C++ 代码编译为 Python 模块的机制。 +=== 17.2.2 整合 JavaScript 语言 === + +

V8

+ +Home:[https://github.com/v8/v8] + +Links:[https://en.wikipedia.org/wiki/Chrome_V8 Wikipedia] + +这就是大名鼎鼎的 V8 引擎,Google 公司开发,C++ 编写,被用于 Chrome 浏览器。 + +既然用于 Chrome 浏览器,显然【完整地】支持了 JS 语言的规范(ECMA-262)。 + +它既可以独立运行,也可以嵌入到 C++ 程序中。 + +代码示例——Hello world + +#include +#include +#include +#include +#include + +int main(int argc, char* argv[]) +{ + // Initialize V8. + v8::V8::InitializeICUDefaultLocation(argv[0]); + v8::V8::InitializeExternalStartupData(argv[0]); + std::unique_ptr platform = v8::platform::NewDefaultPlatform(); + v8::V8::InitializePlatform(platform.get()); + v8::V8::Initialize(); + + // Create a new Isolate and make it the current one. + v8::Isolate::CreateParams create_params; + create_params.array_buffer_allocator = v8::ArrayBuffer::Allocator::NewDefaultAllocator(); + v8::Isolate* isolate = v8::Isolate::New(create_params); + + { + v8::Isolate::Scope isolate_scope(isolate); + // Create a stack-allocated handle scope. + v8::HandleScope handle_scope(isolate); + // Create a new context. + v8::Local context = v8::Context::New(isolate); + // Enter the context for compiling and running the hello world script. + v8::Context::Scope context_scope(context); + // Create a string containing the JavaScript source code. + v8::Local source = + v8::String::NewFromUtf8(isolate, "'Hello World!'", + v8::NewStringType::kNormal).ToLocalChecked(); + // Compile the source code. + v8::Local script = v8::Script::Compile(context, source).ToLocalChecked(); + // Run the script to get the result. + v8::Local result = script->Run(context).ToLocalChecked(); + // Convert the result to an UTF8 string and print it. + v8::String::Utf8Value utf8(isolate, result); + printf("%s\n", *utf8); + } + + // Dispose the isolate and tear down V8. + isolate->Dispose(); + v8::V8::Dispose(); + v8::V8::ShutdownPlatform(); + delete create_params.array_buffer_allocator; + return 0; +} + + ---- = 18 (其它) = From 5810f1337566397ec488ccf57888e6359634ee1c Mon Sep 17 00:00:00 2001 From: programthink Date: Sun, 5 Aug 2018 18:51:55 +0800 Subject: [PATCH 109/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20nbind?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/cpp.wiki | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/libs/cpp.wiki b/libs/cpp.wiki index 3efc90e..723d5c9 100644 --- a/libs/cpp.wiki +++ b/libs/cpp.wiki @@ -3726,6 +3726,57 @@ int main(int argc, char* argv[]) } +

nbind

+ +Home:[https://github.com/charto/nbind] + +把 C++ 代码编译为 JS 的 package。编译方式支持“原生二进制”或“asm.js”。 + +编译需要依赖 Node.js,运行环境支持 Node.js 或浏览器。 + +代码示例——C++ 代码 + +#include +#include + +struct Greeter +{ + static void sayHello(std::string name) + { + std::cout << "Hello, " << name << "\n"; + } +}; + +// 建立绑定 +#include + +NBIND_CLASS(Greeter) +{ + method(sayHello); +} + + +代码示例——node.js 环境调用代码 + +var nbind = require("nbind"); +var lib = nbind.init().lib; +lib.Greeter.sayHello("you"); + + +代码示例——浏览器环境调用代码 + + + + + ---- = 18 (其它) = From 315f1f0af8653695468a17c626081de7fbf20764 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 10 Aug 2018 16:53:04 +0800 Subject: [PATCH 110/116] =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E4=B8=AD=E8=A1=8C=E9=A6=96=20#=20=E5=AD=97=E7=AC=A6=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=20HTML=20=E8=BD=AC=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 4ecc184..73581bc 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -769,7 +769,7 @@ Links:[https://en.wikipedia.org/wiki/Scapy Wikipedia] # 传统的 ping 扫描(网络层) ans,unans = sr(IP(dst="192.168.1.1-254")/ICMP()) -# 局域网内的 ARP 扫描(链路层) +# 局域网内的 ARP 扫描(链路层) ans,unans = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst="192.168.1.0/24"), timeout=2) @@ -1796,14 +1796,14 @@ JSON 格式源自 JavaScript,如今在 Web 开发中广为应用。 import json json.dumps(["foo", {"bar": ("baz", None, 1.0, 2)}]) -# JSON 编码 -# 得到如下【字符串】 -# """["foo", {"bar": ["baz", null, 1.0, 2]}]""" +# JSON 编码 +# 得到如下【字符串】 +# """["foo", {"bar": ["baz", null, 1.0, 2]}]""" json.loads("""["foo", {"bar":["baz", null, 1.0, 2]}]""") -# JSON 解码 -# 得到如下【对象】 -# [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] +# JSON 解码 +# 得到如下【对象】 +# [u"foo", {u"bar": [u"baz", None, 1.0, 2]}] === 9.1.3 YAML === @@ -2119,11 +2119,11 @@ Home:[https://github.com/xflr6/graphviz] from graphviz import Digraph dot = Digraph(comment='The Round Table') -# 添加节点 +# 添加节点 dot.node('A', 'King Arthur') dot.node('B', 'Sir Bedevere the Wise') dot.node('L', 'Sir Lancelot the Brave') -# 添加连线 +# 添加连线 dot.edges(['AB', 'AL']) dot.edge('B', 'L', constraint='false') @@ -2217,7 +2217,7 @@ c = [] for i in range(len(a)) : c.append(a[i] + b[i]) -# 以下是 NumPy 的写法,简洁且速度飞快 +# 以下是 NumPy 的写法,简洁且速度飞快 import numpy as np a = np.arange(10000000) b = np.arange(10000000) From 446858bfbe61290e7d37ccdd6f982ddf401add15 Mon Sep 17 00:00:00 2001 From: programthink Date: Fri, 10 Aug 2018 17:16:31 +0800 Subject: [PATCH 111/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20keyboard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index 73581bc..fa715d4 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -378,7 +378,35 @@ if pid == 0 : # 子进程 用于进程信号处理的标准库(主要用于 Linux & UNIX 系统)。 -== 3.5 获取系统信息 == +== 3.5 操作硬件 == + +

keyboard

+ +Home:[https://github.com/boppreh/keyboard] + +顾名思义,这个库让你可以进行各种键盘相关的操作,包括:模拟按键、键盘钩子(hook),按键记录及重放。 + +支持复杂的组合键。纯 python 代码代码,同时支持 Windows 和 Linux。 + +代码示例 + +import keyboard + +# 模拟按键。 +keyboard.press_and_release("shift+s, space") + +# 模拟按键,并执行相应代码。 +keyboard.add_hotkey("page up, page down", lambda: keyboard.write("xxxx")) + +# 等待特定按键,然后继续执行。 +keyboard.wait("esc") + +# 记录按键,直到用户按了 ESC;然后以3倍速重放刚才记录的按键。 +recorded = keyboard.record(until="esc") +keyboard.play(recorded, speed_factor=3) + + +== 3.6 获取系统信息 ==

sys

@@ -438,7 +466,7 @@ p.cwd() # 进程的当前目录 p.cmdline() # 启动进程的命令行参数 -== 3.6 Linux & Unix 系统相关 == +== 3.7 Linux & Unix 系统相关 ==

syslog

@@ -446,7 +474,7 @@ p.cmdline() # 启动进程的命令行参数 通过它可以很方便地跟 POSIX 的 syslog 服务进行交互。 -== 3.7 Windows 系统相关 == +== 3.8 Windows 系统相关 ==

PyWin32

@@ -454,7 +482,7 @@ Home:[http://python.net/crew/mhammond/win32/] 这个第三方库封装了 Windows API 及 COM API。通过它可以方便地用 Python 进行 Windows 编程(调用 COM 组件、编写 Windows 服务、等)。 -== 3.8 程序打包 == +== 3.9 程序打包 ==

PyInstaller

From 34bb7d079596f44c70d3b1eef017ba45e76d5c0c Mon Sep 17 00:00:00 2001 From: programthink Date: Tue, 30 Oct 2018 23:10:19 +0800 Subject: [PATCH 112/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E2=80=9DWebSocket?= =?UTF-8?q?=E2=80=9C=E5=88=86=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libs/python.wiki b/libs/python.wiki index fa715d4..86290b2 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -739,16 +739,18 @@ Home:[https://github.com/jmalonzo/pywebkitgtk] PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 -== 4.6 (其它) == +== 4.6 WebSocket ==

pywebsocket

Home:[https://github.com/google/pywebsocket] -这是 Google 提供的 [https://zh.wikipedia.org/wiki/WebSocket WebSocket] 服务端。 +这是 Google 提供的 [https://zh.wikipedia.org/wiki/WebSocket WebSocket]【服务端】。 该项目包含一个可独立运行的 server 以及一个 Apache 扩展模块(mod_pywebsocket)。 +== 4.7 (其它) == +

selenium

Home:[http://www.seleniumhq.org/] From 73c27911a3c243ebd03a31d33b2aecf61113c43f Mon Sep 17 00:00:00 2001 From: programthink Date: Tue, 30 Oct 2018 23:27:19 +0800 Subject: [PATCH 113/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20ws4py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 86290b2..d83820e 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -741,14 +741,23 @@ PyWebKitGtk 则提供了对 WebKitGtk 的 Python 封装。 == 4.6 WebSocket == +(关于 WebSocket 的介绍,可以参见维基百科的“[https://zh.wikipedia.org/wiki/WebSocket 这个链接]”)

pywebsocket

Home:[https://github.com/google/pywebsocket] -这是 Google 提供的 [https://zh.wikipedia.org/wiki/WebSocket WebSocket]【服务端】。 +这是 Google 提供的 WebSocket【服务端】。 该项目包含一个可独立运行的 server 以及一个 Apache 扩展模块(mod_pywebsocket)。 +

ws4py

+ +Home:[https://github.com/Lawouach/WebSocket-for-Python] + +此项目同时提供了 WebSocket 的“服务端 & 客户端”;并同时支持 Python2 和 Python3。 + +其【服务端】可以跟“CherryPy、gevent、wsgiref、asyncio”整合;其【客户端】可以跟“Tornado、gevent”整合。 + == 4.7 (其它) ==

selenium

From bf30db21fb845086432e9d989ea5cc818f9b4ede Mon Sep 17 00:00:00 2001 From: programthink Date: Tue, 30 Oct 2018 23:46:23 +0800 Subject: [PATCH 114/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20AutobahnPython?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index d83820e..e573f04 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -750,11 +750,45 @@ Home:[https://github.com/google/pywebsocket] 该项目包含一个可独立运行的 server 以及一个 Apache 扩展模块(mod_pywebsocket)。 +

AutobahnPython

+ +Home:[https://github.com/crossbario/autobahn-python] + +这是 [http://crossbar.io/autobahn Autobahn] 项目的子项目,同时提供了 WebSocket 的“服务端 & 客户端”。 + +它兼容 Python2 和 Python3,另外还兼容 PyPy 和 Jython。 + +网络方面,它可以跟“asyncio 标准库”以及“[https://en.wikipedia.org/wiki/Twisted_%28software%29 Twisted]”整合。 + +除了实现 WebSocket 协议,它还完整实现了 WAMP(Web Application Messaging Protocol)。 + +代码示例——Echo Server + +from autobahn.twisted.websocket import WebSocketServerProtocol + +class MyServerProtocol(WebSocketServerProtocol) : + def onConnect(self, request) : + print("Client connecting: {}".format(request.peer)) + + def onOpen(self) : + print("WebSocket connection open.") + + def onMessage(self, payload, isBinary) : + if isBinary : + print("Binary message received: {} bytes".format(len(payload))) + else: + print("Text message received: {}".format(payload.decode("utf8"))) + self.sendMessage(payload, isBinary) + + def onClose(self, wasClean, code, reason) : + print("WebSocket connection closed: {}".format(reason)) + +

ws4py

Home:[https://github.com/Lawouach/WebSocket-for-Python] -此项目同时提供了 WebSocket 的“服务端 & 客户端”;并同时支持 Python2 和 Python3。 +此项目同时提供了 WebSocket 的“服务端 & 客户端”;并同时兼容 Python2 和 Python3。 其【服务端】可以跟“CherryPy、gevent、wsgiref、asyncio”整合;其【客户端】可以跟“Tornado、gevent”整合。 From c9ef0a0dfc06716b7ac43d71e0d7cf33c0212a4d Mon Sep 17 00:00:00 2001 From: programthink Date: Tue, 30 Oct 2018 23:59:30 +0800 Subject: [PATCH 115/116] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libs/python.wiki b/libs/python.wiki index e573f04..6d00d34 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -349,6 +349,18 @@ if __name__ == "__main__" : Process(target=f, args=(lock, num)).start() +

sh

+ +Home:[https://github.com/amoffat/sh] + +这个项目可以用来取代标准库中的 subprocess;同时兼容 Python2 和 Python3。 + +代码示例 + +from sh import ifconfig +print(ifconfig("wlan0")) + + == 3.4 本地进程间通信(IPC) ==

mmap

From 23adccf2dc6f2d4ca74abc136e1a94777c456276 Mon Sep 17 00:00:00 2001 From: programthink Date: Wed, 31 Oct 2018 00:13:00 +0800 Subject: [PATCH 116/116] =?UTF-8?q?=E5=AE=8C=E5=96=84=20sh=20=E7=9A=84?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0=E5=92=8C=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/python.wiki | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libs/python.wiki b/libs/python.wiki index 6d00d34..5dd27e0 100644 --- a/libs/python.wiki +++ b/libs/python.wiki @@ -355,12 +355,29 @@ Home:[https://github.com/amoffat/sh] 这个项目可以用来取代标准库中的 subprocess;同时兼容 Python2 和 Python3。 -代码示例 +使用它可以写出比 subprocess 更简洁、更优雅的代码。 + +代码示例——获取命令输出 from sh import ifconfig print(ifconfig("wlan0")) +代码示例——命令行参数 + +from sh import curl +# 传统风格 +curl("https://program-think.blogspot.com/", "-o", "test.html", "--silent") +# 命名参数风格 +curl("https://program-think.blogspot.com/", o="test.html", silent=True) + + +代码示例——管道 + +from sh import ls, wc +print(wc(ls("/etc", "-1"), "-l")) + + == 3.4 本地进程间通信(IPC) ==

mmap