??xml version="1.0" encoding="utf-8" standalone="yes"?>无码精品久久久久久人妻中字,精品久久久久久国产潘金莲 ,人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 http://www.shnenglu.com/bigsml/zh-cnWed, 07 May 2025 16:21:06 GMTWed, 07 May 2025 16:21:06 GMT60Google 是下一个受完吗? http://www.shnenglu.com/bigsml/archive/2009/02/17/74036.html泡?/dc:creator>泡?/author>Tue, 17 Feb 2009 06:57:00 GMThttp://www.shnenglu.com/bigsml/archive/2009/02/17/74036.htmlhttp://www.shnenglu.com/bigsml/comments/74036.htmlhttp://www.shnenglu.com/bigsml/archive/2009/02/17/74036.html#Feedback1http://www.shnenglu.com/bigsml/comments/commentRss/74036.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/74036.htmlJohn Borthwick ?Google Next Victim Of Creative Destruction? 一文中阐述了AOL 的死亡以及业的不断循环, yahoo, ebay {已l成为技术革新的受害?

随着搜烦的垂直分? 搜烦市场也被l化
1. 视频搜烦的突? youtube ?007.10 ?2008.10 的搜索增长了114%, 占了google 搜烦?6%.
 2. 实时消息的发? ?a >twitter Z? 市场对突发事件的要求的强? 使得twitter q速发? twitter 的搜?http://search.twitter.com/)与传l引擎依赖内容相关以及链接关pȝ? 更注重时间的相关?

Gerry campbell 的文?nbsp;Search is broken – really broken. 的一个图说明了这U趋?





]]>
Pythong logging ?Logging4cplus 的适配?/title><link>http://www.shnenglu.com/bigsml/archive/2008/12/19/69856.html</link><dc:creator>泡?/dc:creator><author>泡?/author><pubDate>Fri, 19 Dec 2008 10:13:00 GMT</pubDate><guid>http://www.shnenglu.com/bigsml/archive/2008/12/19/69856.html</guid><wfw:comment>http://www.shnenglu.com/bigsml/comments/69856.html</wfw:comment><comments>http://www.shnenglu.com/bigsml/archive/2008/12/19/69856.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/bigsml/comments/commentRss/69856.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bigsml/services/trackbacks/69856.html</trackback:ping><description><![CDATA[<p>Python 的logging 模块的Socket ?Logging4cplus ?socket 的格式是不一L, 现实中需要将日志发送到logging4cplus 的服务器, 不得? 写了?Python logging 模块?logging4cplus的Adapter <br></p> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008080"> 1</span> <span style="COLOR: #008000">#</span><span style="COLOR: #008000">!/usr/bin/env python</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080"> 2</span> <span style="COLOR: #008000">#</span><span style="COLOR: #008000">-*- coding: gbk -*-</span><span style="COLOR: #008000"><br></span><span style="COLOR: #008080"> 3</span> <span style="COLOR: #008000"></span><span style="COLOR: #0000ff">from</span><span style="COLOR: #000000"> struct </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> pack, unpack <br></span><span style="COLOR: #008080"> 4</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 5</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> BufferPack(object):    <br></span><span style="COLOR: #008080"> 6</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">__init__</span><span style="COLOR: #000000">(self):<br></span><span style="COLOR: #008080"> 7</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">''</span><span style="COLOR: #000000"><br></span><span style="COLOR: #008080"> 8</span> <span style="COLOR: #000000">        <br></span><span style="COLOR: #008080"> 9</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> addChar(self, s, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">10</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>b</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>c</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, s )<br></span><span style="COLOR: #008080">11</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">12</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> addShort(self, s, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">13</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>H</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>h</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, s )<br></span><span style="COLOR: #008080">14</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">15</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> addInt(self, s, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">16</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>I</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>i</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, s )<br></span><span style="COLOR: #008080">17</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">18</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> addLong(self, s, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">19</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>L</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>l</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, s )<br></span><span style="COLOR: #008080">20</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">21</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> addString(self, s):<br></span><span style="COLOR: #008080">22</span> <span style="COLOR: #000000">        self.addInt( len(s) ) <br></span><span style="COLOR: #008080">23</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> s <br></span><span style="COLOR: #008080">24</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">25</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> addBuffer(self, s):<br></span><span style="COLOR: #008080">26</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> s.buffer <br></span><span style="COLOR: #008080">27</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">28</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> BufferUnpack(object):<br></span><span style="COLOR: #008080">29</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">30</span> <span style="COLOR: #000000">    char_bits     </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> len( pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>b</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, 0) ) <br></span><span style="COLOR: #008080">31</span> <span style="COLOR: #000000">    short_bits     </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> len( pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>H</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, 0) ) <br></span><span style="COLOR: #008080">32</span> <span style="COLOR: #000000">    int_bits    </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> len( pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>I</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, 0) ) <br></span><span style="COLOR: #008080">33</span> <span style="COLOR: #000000">    long_bits     </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> len( pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">>L</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, 0) )    <br></span><span style="COLOR: #008080">34</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">35</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">__init__</span><span style="COLOR: #000000">(self, buffer):<br></span><span style="COLOR: #008080">36</span> <span style="COLOR: #000000">        self.buffer </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> buffer <br></span><span style="COLOR: #008080">37</span> <span style="COLOR: #000000">        self.pos </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> 0<br></span><span style="COLOR: #008080">38</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">39</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> _read_item(self, unpackstr, len):<br></span><span style="COLOR: #008080">40</span> <span style="COLOR: #000000">        v </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> unpack(unpackstr, self.buffer[self.pos:self.pos</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">len] )<br></span><span style="COLOR: #008080">41</span> <span style="COLOR: #000000">        self.pos </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> len <br></span><span style="COLOR: #008080">42</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> v <br></span><span style="COLOR: #008080">43</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">44</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> readChar(self, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">45</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> self._read_item(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><b</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><c</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, self.char_bits)<br></span><span style="COLOR: #008080">46</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">47</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> readShort(self, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):    <br></span><span style="COLOR: #008080">48</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> self._read_item(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><H</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><h</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, self.short_bits )<br></span><span style="COLOR: #008080">49</span> <span style="COLOR: #000000">        <br></span><span style="COLOR: #008080">50</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> readInt(self, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">51</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> self._read_item(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><I</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><i</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, self.int_bits )<br></span><span style="COLOR: #008080">52</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">53</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> readLong(self, unsigned</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">False):<br></span><span style="COLOR: #008080">54</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> self._read_item(unsigned </span><span style="COLOR: #0000ff">and</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><L</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">or</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><l</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, self.long_bits )<br></span><span style="COLOR: #008080">55</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">56</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> readString(self):<br></span><span style="COLOR: #008080">57</span> <span style="COLOR: #000000">        len </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> self.readInt()<br></span><span style="COLOR: #008080">58</span> <span style="COLOR: #000000">        v </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> self.buffer[self.pos:self.pos</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">len] <br></span><span style="COLOR: #008080">59</span> <span style="COLOR: #000000">        self.pos </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> len<br></span><span style="COLOR: #008080">60</span> <span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> v <br></span><span style="COLOR: #008080">61</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">62</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> PackMessage( record ):<br></span><span style="COLOR: #008080">63</span> <span style="COLOR: #000000">    bp </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> BufferPack()<br></span><span style="COLOR: #008080">64</span> <span style="COLOR: #000000">    bp.addChar(</span><span style="COLOR: #000000">2</span><span style="COLOR: #000000">, True) <br></span><span style="COLOR: #008080">65</span> <span style="COLOR: #000000">    bp.addChar(</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, True) <br></span><span style="COLOR: #008080">66</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">67</span> <span style="COLOR: #000000">    bp.addString(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">{log.servername}</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">) <br></span><span style="COLOR: #008080">68</span> <span style="COLOR: #000000">    bp.addString(record.name) <br></span><span style="COLOR: #008080">69</span> <span style="COLOR: #000000">    bp.addInt(record.levelno</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">1000</span><span style="COLOR: #000000">) <br></span><span style="COLOR: #008080">70</span> <span style="COLOR: #000000">    bp.addString(</span><span style="COLOR: #800000">""</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">71</span> <span style="COLOR: #000000">    bp.addString(record.msg)<br></span><span style="COLOR: #008080">72</span> <span style="COLOR: #000000">    bp.addString(str(record.threadName))<br></span><span style="COLOR: #008080">73</span> <span style="COLOR: #000000">    bp.addString(str(record.process))<br></span><span style="COLOR: #008080">74</span> <span style="COLOR: #000000">    bp.addInt( record.created ) <br></span><span style="COLOR: #008080">75</span> <span style="COLOR: #000000">    bp.addInt( record.msecs ) <br></span><span style="COLOR: #008080">76</span> <span style="COLOR: #000000">    bp.addString(record.filename)<br></span><span style="COLOR: #008080">77</span> <span style="COLOR: #000000">    bp.addInt( </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000"> )     <br></span><span style="COLOR: #008080">78</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">79</span> <span style="COLOR: #000000">    pkg </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> BufferPack()<br></span><span style="COLOR: #008080">80</span> <span style="COLOR: #000000">    pkg.addInt(len(bp.buffer), True) <br></span><span style="COLOR: #008080">81</span> <span style="COLOR: #000000">    pkg.addBuffer( bp ) <br></span><span style="COLOR: #008080">82</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">83</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> pkg.buffer<br></span><span style="COLOR: #008080">84</span> <span style="COLOR: #000000"><br></span><span style="COLOR: #008080">85</span> <span style="COLOR: #000000"></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">__name__</span><span style="COLOR: #000000">==</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">__main__</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">:<br></span><span style="COLOR: #008080">86</span> <span style="COLOR: #000000">    </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> logging, logging.handlers <br></span><span style="COLOR: #008080">87</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">88</span> <span style="COLOR: #000000">    logger </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> logging.getLogger()<br></span><span style="COLOR: #008080">89</span> <span style="COLOR: #000000">    logging.handlers.SocketHandler.makePickle </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #0000ff">lambda</span><span style="COLOR: #000000"> self,rc : PackMessage(rc) <br></span><span style="COLOR: #008080">90</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">91</span> <span style="COLOR: #000000">    hdlr </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> logging.handlers.SocketHandler(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">{logserver.ip}</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">8888</span><span style="COLOR: #000000">) <br></span><span style="COLOR: #008080">92</span> <span style="COLOR: #000000">    formatter </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> logging.Formatter(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">%(asctime)s %(levelname)s %(message)s</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">)<br></span><span style="COLOR: #008080">93</span> <span style="COLOR: #000000">    hdlr.setFormatter(formatter)<br></span><span style="COLOR: #008080">94</span> <span style="COLOR: #000000">    logger.addHandler(hdlr)<br></span><span style="COLOR: #008080">95</span> <span style="COLOR: #000000">    logger.setLevel(logging.NOTSET)<br></span><span style="COLOR: #008080">96</span> <span style="COLOR: #000000">    <br></span><span style="COLOR: #008080">97</span> <span style="COLOR: #000000">    logger.info(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">hello</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">)</span></div> <br>使用的时?<br>1. 在logging 创徏SocketHandler 的时? 需要修改logging.handlers.SocketHandler.makePickle 为方?PackMessage <br>logging.handlers.SocketHandler.makePickle = lambda self,rc : PackMessage(rc) <br><br>2. 需要修改代码中的两部分内容 {log.servername} ?{logserver.ip}<br> <img src ="http://www.shnenglu.com/bigsml/aggbug/69856.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bigsml/" target="_blank">泡?/a> 2008-12-19 18:13 <a href="http://www.shnenglu.com/bigsml/archive/2008/12/19/69856.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>BHO基础http://www.shnenglu.com/bigsml/archive/2008/12/04/68573.html泡?/dc:creator>泡?/author>Thu, 04 Dec 2008 09:26:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/12/04/68573.htmlhttp://www.shnenglu.com/bigsml/comments/68573.htmlhttp://www.shnenglu.com/bigsml/archive/2008/12/04/68573.html#Feedback0http://www.shnenglu.com/bigsml/comments/commentRss/68573.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/68573.htmlBHO是Browser Helper Object(览器辅助对?

BHO兌原理 (BHO兌的是SHDOCVW,也就是说不只兌IE,下面全部用IE来说?
1.IE的窗口打开?先寻找HKLM下的SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects\ 里的CLSID,q些CLSID,都对应着相应的BHO插gQ然后根据这个CLSID到HKCR下的CLSIDs里找到此插g的信息,包括文g位置{?br>2.IEҎ扑ֈ的CLSID信息创徏 BHO 对象,q且查找 IObjectWithSite 接口. (q个接口非常?只有SetSite和GetSite两个Ҏ)
3.IE把IWebBrowser2(览器插?传到 BHO ?SetSite ҎQ用户在此方法中可挂载自q事g处理Ҏ?br>4.H口关闭?IE?null 传到 BHO ?SetSite ҎQ此Ҏ用来L挂蝲的事件处理方法?/p>

~写BHO程
1.创徏IObjectWithSite昑ּ接口Q创?COM cdQ实现承IObjectWithSite接口
2.实现此接口ƈ在SetSiteҎ里加上所要挂载的事g
3.处理事g
4.注册此BHO到注册表中HKLM下的Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects;(HKCR下的CLSIDs是根据上面的路径自动注册?
5?net 下须讄此BHO目?配置属性_>生成 中ؓInterop注册为TrueQ这h能将.net cd文g注册到COM

删除BHO
打开注册表项?HKLM下的Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Browser Helper Objects 可以看到下面有一些CLSID?q些值对应相关的插g,点击可以在默认值后看到相关插g的名U?可以复制相关CLSID到注册表中搜索相关CLSID,扑ֈ后打开InprocServer32可以看到相关文g的\?至于DLL文g{可以用UEDIT32.exe工具打开查看具体信息,当然也可以用修改E序cȝeXeScope.exe研究一?
h据具体情况删除相关键值和相关文g!

REF:
BHO 的编?nbsp;
VCKBase 关于IE ~程文档中心
C++中用BHO来屏蔽特定网?/a>
览器集成教?自定义浏览器



]]>
36 steps to success as technical leadhttp://www.shnenglu.com/bigsml/archive/2008/10/29/65481.html泡?/dc:creator>泡?/author>Wed, 29 Oct 2008 13:45:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/10/29/65481.htmlhttp://www.shnenglu.com/bigsml/comments/65481.htmlhttp://www.shnenglu.com/bigsml/archive/2008/10/29/65481.html#Feedback0http://www.shnenglu.com/bigsml/comments/commentRss/65481.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/65481.htmlzz http://littletutorials.com/2008/07/07/success-as-technical-lead/ 
分ؓ3个部?
Set yourself up for success
Build your relationship with the team
Build your relationship with the management and business people

Set yourself up for success

1. Define early on what success means for you, the team and the business

You have to have a clear idea of what you want. You also have to understand what team members and the management want. You also have to be aware that what people really want, what they say the want and sometimes even what they think they want are very different things. Try to be very honest at least with yourself. Success has different definitions for different people. If there is a big disconnect between these definitions you have a problem before you start.

2. Believe in the project: idea, architecture, time, team

You cannot have any kind of success if you are convinced you lead a team of morons to implement a stupid idea using the wrong architecture in a ridiculously short time. You have to really believe in the project to have a chance to success. This does not mean lie to yourself. It means do whatever you can to understand your concerns and work on them with the management. As for the architecture, it is best if you have a heavy word or if you are the architect.

3. Understand the domain, the business requirements and the technical challenges

You should be an expert in the technologies used for implementation. You also have to become very knowledgeable in the problem domain and the business case. This will help you understand the business decisions dropped on your head from upstairs and also will help you stand a chance at negotiating them.

4. Know your team: strengths, weaknesses, ambitions and personalities

Software is created by people. Your job as a “tech lead” is to support them in doing that, both from a technical point of view and at a human level. You want to lead a team of motivated and enthusiastic people. But each person gets motivated by different things.

5. Have a plan as a result of a planning activity

“Plans are useless but planning is essential” - (Dwight D Eisenhower, US President, general 1890-1969). Planning will make you think about the problems you face in detail. Also keep in mind that “a plan is just a list of things that ain’t gonna happen” - (Benicio Del Torro in “The Way of the Gun”).

6. Be part in the design of everything

This does not mean do the whole design. You want to empower team members. But your job is to understand and influence each significant subsystem in order to maintain architectural integrity.

7. Get your hands dirty and code

Yes you should take parts of the code and implement them. Even the least glamorous parts. This will help you not getting stuck alone between management and the team. It will also help you gain respect in the team.

8. Act as a communication proxy for your team

In long complex projects with big teams communication is one of the most complicated aspects. The more people you have involved in solving a problem the bigger the communication matrix becomes. Since people need information to be able to make the right decisions this will lead to an exponential increase in the time consumed for communication. Agile methodologies alleviate this problem. But in the end it is up to you to propagate important information to the right people.

9. Make sure everybody understands the big picture: their work has implications

This will help you greatly because will allow team members to design and implement in a way that you don’t have to fight. It is also hard work from your part.

10. Fight for architecture and design consistency

Doing the right thing from the design and architecture point of view is not more costly. It is actually cheaper in every project longer than a couple of months. Every early investment in architecture pays for itself later during integration and maintenance. Even if you have to admit an occasional hack or prototype in the code base you should contain it in very specific modules.

11. Know the status of everybody’s work and detect slippage

This allows for corrective actions and for early communication with the management. You don’t want to be caught by surprise. Remember that during 90% of the allocated time for a task the code is 90% complete.

12. Record technical debt if you need shortcuts but try to maintain architectural integrity; report the debt

This one is very important for products that will have multiple releases. Technical debt should be analyzed at the beginning of each iteration.

13. Use the process that makes sense in your particular case

Tough one. Sometimes (most of the times?) the process is not up to you. In the enterprise usually the process is pre-decided. But always keep in mind that the process in itself means nothing. It is the people who give meaning to the process. Good people can make the worst process work while the wrong team cannot make any process work. Waterfall can be implemented in a very agile way and the agile methodologies can be applied with “rigor mortis” agility (see The Agile 800 Pounds Gorilla).

14. Avoid dogmas - question why everything is done the way is done; make sure everybody else knows the reasons

Sometimes I hear from programmers: we are agile and combine XP and Scrum and we also do TDD (Test Driven Development - I still hope for a TDD that means Thought Driven Development). The questions that pop up in my mind are: Do you need all those? Do you “really” do them by the book?
Anyway the point here is don’t do anything just because it is the way it has always been done. Understand why. Then explain the reasons to all team members. Rinse and repeat.

15. Avoid design by committee; listen to everybody but make your own decisions

No good design is born from referendum. There are lots of people making wild exotic suggestions when their a$$ is not on the line. There are also excessively prudent ideas born from fear. Even with good ideas you have to filter them and make them yours before you can include them in the design. A good architecture and a good design is usually born in one mind, an open mind that looks around. The obvious example is Linux.


Build your relationship with the team

16. Gain the team’s respect with the quality of your work and by doing what you are preaching17. Be fair
18. Admit your mistakes
19. Publicly recognize both team’s and individual members’ merits
20. Don’t blame anybody publicly for anything
21. Build morale and confidence by offering early victories to the team and to its individual members
22. Match people and tasks based on skills and their personal preference if possible; explain your decisions
23. Work the estimates with the team don’t come up with them
24. Mentor people
25. Listen to and learn from people
26. Explain your technical decisions

Build your relationship with the management and business people
27. Be sure you have authority along with responsibility
28. Be sure you get requirements and not architecture/design masked as requirements
29. Explain technical decisions in business terms
30. Try to be accurate in your estimates; avoid being too optimistic and don’t push it with hidden padding; explain the need for padding
31. Set reasonable expectations
32. Understand the relationships and dependencies with other teams or projects
33. Accurately report the status with alarms, explanations and solutions; report any technical debt
34. Resist pressure for change in requirements, and more important for shortcuts…
35. Be aware of politics
36. React to surprises with calm and with documented answers


]]>
Top 25 PHP template engines http://www.shnenglu.com/bigsml/archive/2008/10/29/65478.html泡?/dc:creator>泡?/author>Wed, 29 Oct 2008 13:28:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/10/29/65478.htmlhttp://www.shnenglu.com/bigsml/comments/65478.htmlhttp://www.shnenglu.com/bigsml/archive/2008/10/29/65478.html#Feedback1http://www.shnenglu.com/bigsml/comments/commentRss/65478.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/65478.htmlhttp://www.whenpenguinsattack.com/2006/07/19/php-template-engine-roundup/ 


该文ȝ?php 的一些模? 我用过的有smarty, template lib, q有后来用的 Savant. 感觉smarty 太复杂了, template lib 需要学习一些标{? q且不是很强? l合考虑q是Savant 最? 既可以用模板机? 另外面模板直接使用php 函数来输? 功能也还可以.

Smarty
Smarty is a template engine that compiles the templates into PHP scripts, then executes those scripts. Very fast, very flexible.

Savant
A powerful but lightweight PEAR-compliant template system. It is non-compiling, and uses PHP itself as its template language.

Heyes Template Class

A very easy to use, yet powerful and quick template engine that enables you to separate your page layout and design from your code.

FastTemplate
A simple variable interpolation template class that parses your templates for variables and spits out HTML with their values

ShellPage
A simple and easy to use class that lets you make whole websites based on template files for layouts. Change the template and your whole site changes.

STP Simple Template Parser
A simple, light weight and easy to use template parser class. It can assemble a page from several templates, output result pages to the browser or write them to the filesystem.

OO Template Class
An object oriented template class you can use in your own programs.

SimpleTemplate
A template engine to create and structure websites and applications. It can translate and compile the templates.

bTemplate
A small and fast template class that allows you to separate your PHP logic from your HTML presentation code.

ETS - easy template system
A template system that allows you to reshuffle templates with exactly the same data.

EasyTemplatePHP
A simple, yet powerful templating system for your site.

vlibTemplate
A fast, full featured template system that includes a caching and debugging class.

AvanTemplate
A template engine that is multi-byte safe and consumes little computing resource. It supports variable replacement and content blocks that can be set to hidden or shown.

Grafx Software’s Fast Template
A modification of the popular Fast Template system, this includes a cache function, debug console, and silent removal of unassigned dynamic blocks.

TemplatePower
A fast, simple and powerful template class. Features nested dynamic block support, block/file include support and show/hide unassigned variables.

TagTemplate
This library function was designed for use with template files and allows you to retrieve info from HTML files.

htmltmpl: templating engine
A templating engine for Python and PHP. Targeted to web application developers, who want to separate program code and design of their projects.

PHP Class for Parsing Dreamweaver templates
A simple class to parse a Dreamweaver template for use in custom mods for a Gallery 2 and a WordPress blog.

MiniTemplator (Template Engine)
A compact template engine for HTML files. It features a simple syntax for template variables and blocks. Blocks can be nested.

Layout Solution
Simplifies website development and maintenance. It holds commonly used variables and page elements so you don’t need to duplicate common layouts over and over.

Cached Fast Template
This inclusion into FastTemplate allows for caching of the template files, and can even cache with different specifications on separate blocks of content.

TinyButStrong
A template engine that supports MySQL, Odbc, Sql-Server and ADODB. It includes seven methods and two properties.

Brian Lozier’s php based template engine
Only 2k in size, very fast and object-orientated.

WACT
a template engine that separates code from design.

PHPTAL
a XML/XHTML template library for PHP.

ref:
http://www.sitepoint.com/forums/showthread.php?t=123769 对其他的php 模板q行了讨?/p>

]]>
深入理解Effictive C++ "条款38: 决不要重新定义承而来的缺省参数? http://www.shnenglu.com/bigsml/archive/2008/10/06/63327.html泡?/dc:creator>泡?/author>Mon, 06 Oct 2008 09:19:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/10/06/63327.htmlhttp://www.shnenglu.com/bigsml/comments/63327.htmlhttp://www.shnenglu.com/bigsml/archive/2008/10/06/63327.html#Feedback6http://www.shnenglu.com/bigsml/comments/commentRss/63327.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/63327.html看条?8 的时候不是很理解, 于是写了个测试代?

#include<iostream> 
using namespace std; 

class A{
public:
    
virtual void show(int a=145)
    {
        cout
<<"A: a="<<a<<endl; 
    }   
}; 

class B: public A 

public
    
void show(int b)
    { 
        cout
<<"B: b="<<b<<endl; 
    } 
}; 
class C: public B 

public
    
void show(int c=999)
    { 
        cout
<<"C: c="<<c<<endl; 
    } 
};
class D: public C 

public
    
void show()
    { 
        cout
<<"D:\n"
    }
}; 

void main() 
{
    A 
*pp;
    A a; 
    B b; 
    C c; 
    D d;
    
    a.show();
    pp 
= &a;    pp->show();

    
// b.show();  // error C2660: 'B::show' : function does not take 0 arguments
    pp = &b;    pp->show();
    
    c.show();
    pp 
= &c;    pp->show();

    d.show();
    pp 
= &d;    pp->show();
    
    C 
*pc= &d;
    pc
->show();

    system(
"pause"); 
}   
输出l果?br>
A: a=145
A: a=145
B: b=145
C: c=999
C: c=145
D:
C: c=145
C: c=999

回顾条款 
虚函数是动态绑定而缺省参数值是静态绑定的.  Z么C++坚持q种有违常规的做法呢Q答案和q行效率有关。如果缺省参数D动态绑定,~译器就必须惛_法ؓ虚函数在q行时确定合适的~省|q将比现在采用的在编译阶D늡定缺省值的机制更慢更复杂。做U选择是想求得速度上的提高和实C的简便,所以大家现在才能感受得到程序运行的高效Q?

所?
a. 静态绑?.vs. 动态绑?
A *pp = new B;
q里 pp 静态绑定是 A* , 而动态绑定却?B*
B *pb = new B;
q里 pb 静态绑定和动态绑定是一L都是 B*

b. ~省值是静态绑定的, 而非动态绑?
所?
d.show() 输出 D:  因ؓshow ?D override

pp = &d;    pp->show();  
pp 被动态绑定到D *, 但是show 的缺省值却是A* ?145, 所以输出的?C: c=145, 而不?99 ( 函数 show 被C loverride ? 

?nbsp;C *pc = &d; pc->show() , pc 静态绑定ؓC*, 而动态绑定ؓ D* , 所以输出的?C: c=999 , 999 ?C* 静态绑定的~省?

c. 所以调用b.show 的时候出C如下的错?
    // b.show();  // error C2660: 'B::show' : function does not take 0 arguments
因ؓ B* 没有静态绑定的函数

l论是 决不要重新定义承而来的缺省参数?nbsp;

ref: 
从这里学了不?) http://bbs.chinaunix.net/viewthread.php?tid=439188 


]]>
Python 操作黑莓(Blackberry)通信?/title><link>http://www.shnenglu.com/bigsml/archive/2008/10/03/63207.html</link><dc:creator>泡?/dc:creator><author>泡?/author><pubDate>Fri, 03 Oct 2008 14:18:00 GMT</pubDate><guid>http://www.shnenglu.com/bigsml/archive/2008/10/03/63207.html</guid><wfw:comment>http://www.shnenglu.com/bigsml/comments/63207.html</wfw:comment><comments>http://www.shnenglu.com/bigsml/archive/2008/10/03/63207.html#Feedback</comments><slash:comments>6</slash:comments><wfw:commentRss>http://www.shnenglu.com/bigsml/comments/commentRss/63207.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/bigsml/services/trackbacks/63207.html</trackback:ping><description><![CDATA[Zl黑莓导入iPhone 的通信?contacts) , 只能利用黑莓的桌面管理器, 通过ipd 来维? <br>但是发现 ABC Amber BlackBerry Converter 只能转换而无法修? IPDManager 只能l护铃声和音乐啥?(  只能自己写了个小E序 <br><br>ipd 的格式可以在 <a >http://na.blackberry.com/eng/developers/resources/journals/jan_2006/ipd_file_format.jsp</a> q里扑ֈ, 后面是代? 只是生成datablock 列表, q需要额外拷? 操作时最好只同步通信? <br><br>下面是代?<br> <div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><span style="COLOR: #008000">#</span><span style="COLOR: #008000">!/usr/local/bin/python2.5 </span><span style="COLOR: #008000"><br>#</span><span style="COLOR: #008000">-*- coding: gbk -*-</span><span style="COLOR: #008000"><br></span><span style="COLOR: #0000ff">from</span><span style="COLOR: #000000"> struct </span><span style="COLOR: #0000ff">import</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">*</span><span style="COLOR: #000000"> <br><br></span><span style="COLOR: #0000ff">class</span><span style="COLOR: #000000"> BBFile:    <br>    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">__init__</span><span style="COLOR: #000000">(self):<br>        </span><span style="COLOR: #0000ff">pass</span><span style="COLOR: #000000"><br>        <br>    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> _contactblock(self, name, phone, uid):<br>        s </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">''</span><span style="COLOR: #000000"><br>        </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> name </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        name </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> name.encode(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">utf-16be</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">)<br>        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><HB</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, len(name)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">0xa0</span><span style="COLOR: #000000">)<br>        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><B</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">0x01</span><span style="COLOR: #000000">) </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> name<br>        </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> ff * 8 </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><HB</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">0x54</span><span style="COLOR: #000000">)<br>        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">\xff</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">*</span><span style="COLOR: #000000">8</span><span style="COLOR: #000000"><br>        </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> uid </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><HBI</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">4</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">0x55</span><span style="COLOR: #000000">, uid)<br>        </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> phone</span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        phone </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> phone.encode(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">gbk</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">)<br>        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><HB</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, len(phone)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">0x08</span><span style="COLOR: #000000">)<br>        s </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> phone </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> </span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">\x00</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000"><br>        </span><span style="COLOR: #0000ff">return</span><span style="COLOR: #000000"> s <br>    <br>    </span><span style="COLOR: #0000ff">def</span><span style="COLOR: #000000"> save(self, filename, us, dbID</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0, dbVer</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">0):<br>        hf </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> open(filename, </span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">w+b</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">)<br>        rs, uid </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">, </span><span style="COLOR: #000000">363797835</span><span style="COLOR: #000000"> </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> 初始?/span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        </span><span style="COLOR: #0000ff">for</span><span style="COLOR: #000000"> u </span><span style="COLOR: #0000ff">in</span><span style="COLOR: #000000"> us:<br>            s </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> self._contactblock(u[0], u[</span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">], uid)<br>            h </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> pack(</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000"><HIBHI</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, dbID, len(s)</span><span style="COLOR: #000000">+</span><span style="COLOR: #000000">7</span><span style="COLOR: #000000">, dbVer, rs, uid)<br>            hf.write(h </span><span style="COLOR: #000000">+</span><span style="COLOR: #000000"> s)<br>            uid </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">8</span><span style="COLOR: #000000">    </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">            rs  </span><span style="COLOR: #000000">+=</span><span style="COLOR: #000000"> </span><span style="COLOR: #000000">1</span><span style="COLOR: #000000">    </span><span style="COLOR: #008000">#</span><span style="COLOR: #008000"> </span><span style="COLOR: #008000"><br></span><span style="COLOR: #000000">        hf.close()<br>        <br></span><span style="COLOR: #0000ff">if</span><span style="COLOR: #000000"> </span><span style="COLOR: #800080">__name__</span><span style="COLOR: #000000">==</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">__main__</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">:<br>    bb </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> BBFile()<br>    us </span><span style="COLOR: #000000">=</span><span style="COLOR: #000000"> [ (u</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">宝宝1</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, u</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">13888888888</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">),(u</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">宝宝2</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, u</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">13888888888</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">),(u</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">宝宝3</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">, u</span><span style="COLOR: #800000">'</span><span style="COLOR: #800000">13888888888</span><span style="COLOR: #800000">'</span><span style="COLOR: #000000">),  ]    <br>    bb.save(</span><span style="COLOR: #800000">"</span><span style="COLOR: #800000">bb.ipd</span><span style="COLOR: #800000">"</span><span style="COLOR: #000000">, us, 0, 0)<br></span></div> 1. 保存成文件就可以直接q行?) <br>2. 如果要真的生成可以导入bb 的文件的? 要用高U?> 只同步通讯? 然后这个文件生成的内容攑֜导出文g的头的后? q是有点ȝ.... 有空做个全自动的 呵呵   <br><br>因ؓ只是试, 所以很多硬~码?)    <br><br> <img src ="http://www.shnenglu.com/bigsml/aggbug/63207.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/bigsml/" target="_blank">泡?/a> 2008-10-03 22:18 <a href="http://www.shnenglu.com/bigsml/archive/2008/10/03/63207.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Http 基础http://www.shnenglu.com/bigsml/archive/2008/09/25/62754.html泡?/dc:creator>泡?/author>Thu, 25 Sep 2008 06:05:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/09/25/62754.htmlhttp://www.shnenglu.com/bigsml/comments/62754.htmlhttp://www.shnenglu.com/bigsml/archive/2008/09/25/62754.html#Feedback1http://www.shnenglu.com/bigsml/comments/commentRss/62754.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/62754.html= HTTP 基础
一个完整的 HTTP h可以分成4?
 1. 创徏TCP socket, q接到Web 服务?br> 2. 发送Http h?br> 3. 接受Web 响应数据
 4. 关闭socket q接
整个程可以通过telnet hostname 80 来模?br>一个完整的h例子如下
* About to connect() to www.baidu.com port 80 (#0)
*   Trying 202.108.22.5... connected
* Connected to www.baidu.com (202.108.22.5) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.16.4 (i586-pc-mingw32msvc) libcurl/7.16.4 OpenSSL/0.9.7e zlib/1.2.2
> Host: www.baidu.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Thu, 25 Sep 2008 05:14:30 GMT
< Server: BWS/1.0
< Content-Length: 3342
< Content-Type: text/html
< Cache-Control: private
< Expires: Thu, 25 Sep 2008 05:14:30 GMT
< Set-Cookie: BAIDUID=3A8165EF68FFEE5F605D33ADEF300BA1:FG=1; expires=Thu, 25-Sep-38 05:14:30 GMT; path=/; domain=.baidu.com
< P3P: CP=" OTI DSP COR IVA OUR IND COM "
<
<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>......

另外值得说明的是, HTTP h是无状态的Q表明在处理一个请求时QWeb服务器ƈ不记住来自同一客户端的h?/p>

= Http h?
包含4个部? h行、请求头、空行和h数据

1. h?br>׃个标记组成:hҎ、请求URI和HTTP版本Q它们用I格分隔, 如:GET /index.html HTTP/1.1

HTTP 规范定义?U请求方法:
GET   索URI中标识资源的一个简单请?br>HEAD   与GETҎ相同Q服务器只返回状态行和头标,q不q回h文档
POST   服务器接受被写入客户端输出流中的数据的请?br>PUT   服务器保存请求数据作为指定URI新内容的h
DELETE   服务器删除URI中命名的资源的请?br>OPTIONS  关于服务器支持的hҎ信息的请?br>TRACE   Web服务器反馈Httph和其头标的请?br>CONNECT  已文档化但当前未实现的一个方法,预留做隧道处?/p>

2. h?[ 可无 ]
由关键字及值对l成Q每行一对,关键字和值用冒号Q?Q分隔。如
> User-Agent: curl/7.16.4 (i586-pc-mingw32msvc) libcurl/7.16.4 OpenSSL/0.9.7e zlib/1.2.2
> Host: www.baidu.com
> Accept: */*
具体h头如后所?

3. I
最后一个请求头之后是一个空行,发送回车符和退行,通知服务器以下不再有头标?/p>

4. h数据 [ 可无 ]
使用POST传送数据,最怋用的是Content-Type和Content-Length头标


= Web 响应
由四个部分组? 状态行、响应头、空行、响应数? ?
< HTTP/1.1 200 OK
< Date: Thu, 25 Sep 2008 05:14:30 GMT
< Server: BWS/1.0
< Content-Length: 3342
< Content-Type: text/html
< Cache-Control: private
< Expires: Thu, 25 Sep 2008 05:14:30 GMT
< Set-Cookie: BAIDUID=3A8165EF68FFEE5F605D33ADEF300BA1:FG=1; expires=Thu, 25-Sep-38 05:14:30 GMT; path=/; domain=.baidu.com
< P3P: CP=" OTI DSP COR IVA OUR IND COM "
<
<html><head><meta http-equiv=Content-Type content="text/html;charset=gb2312"><title>......

1.状态行
׃个标记组成:HTTP版本、响应代码和响应描述
HTTP版本:: 向客L指明其可理解的最高版本?br>响应代码:: 3位的数字代码Q指求的成功或失败,如果p|则指出原因?br>响应描述:: 为响应代码的可读性解释?br>?
< HTTP/1.1 200 OK

HTTP响应码划分如?见?Q?br>1xxQ信息,h收到Ql处?br>2xxQ成功,行ؓ被成功地接受、理解和采纳
3xxQ重定向Qؓ了完成请求,必须q一步执行的动作
4xxQ客L错误


2.响应?br>跟请求头一P它们指出服务器的功能Q标识出响应数据的细节?/p>

3.I
最后一个响应头标之后是一个空行,发送回车符和退行,表明服务器以下不再有头标?/p>

4.响应数据
HTML文档和图像等Q就是HTML本n?


= HTTP?br>用以描述客户端或者服务器的属性、被传输的资源等, 分ؓ
1.通用头标Q即可用于请求,也可用于响应Q是作ؓ一个整体而不是特定资源与事务相关联?br>2.h头标Q允许客L传递关于自w的信息和希望的响应形式?br>3.响应头标Q服务器和于传递自w信息的响应?br>4.实体头标Q定义被传送资源的信息。即可用于请求,也可用于响应?/p>

下表描述在HTTP/1.1中用到的头标
Accept   定义客户端可以处理的媒体cdQ按优先U排序;
  在一个以逗号为分隔的列表中,可以定义多种cd和用通配W。例如:Accept: image/jpeg,image/png,*/*
Accept-Charset  定义客户端可以处理的字符集,按优先排序Q?br>  在一个以逗号为分隔的列表中,可以定义多种cd和用通配W。例如:Accept-Charset: iso-8859-1,*,utf-8
Accept-Encoding 定义客户端可以理解的~码机制。例如:Accept-Encoding:gzip,compress
Accept-Language 定义客户端乐于接受的自然语言列表。例如:Accept-Language: en,de
Accept-Ranges  一个响应头标,它允许服务器指明Q将在给定的偏移和长度处Qؓ资源l成部分的接受请求?br>  该头标的D理解求范围的度量单位。例如Accept-Ranges: bytes或Accept-Ranges: none
Age   允许服务器规定自服务器生成该响应以来所l过的时间长度,以秒为单位?br>  该头标主要用于缓存响应。例如:Age: 30
Allow   一个响应头标,它定义一个由位于hURI中的ơ源所支持的HTTPҎ列表。例如:Allow: GET,PUT
AUTHORIZATION  一个响应头标,用于定义讉K一U资源所必需的授权(域和被编码的用户ID与口令)?br>  例如QAuthorization: Basic YXV0aG9yOnBoaWw=
Cache-Control  一个用于定义缓存指令的通用头标。例如:Cache-Control: max-age=30
Connection  一个用于表明是否保存socketq接为开攄通用头标。例如:Connection: close或Connection: keep-alive
Content-Base  一U定义基本URI的实体头标,Z在实体范围内解析相对URLs?br>  如果没有定义Content-Base头标解析相对URLsQ用Content-Location URIQ存在且l对Q或使用URIh?br>  例如QContent-Base: Http://www.myweb.com
Content-Encoding 一U介质类型修饰符Q标明一个实体是如何~码的。例如:Content-Encoding: zip
Content-Language 用于指定在输入流中数据的自然语言cd。例如:Content-Language: en
Content-Length 指定包含于请求或响应中数据的字节长度。例如:Content-Length:382
Content-Location 指定包含于请求或响应中的资源定位QURIQ?br>  如果是一l。对URL它也作ؓ被解析实体的相对URL的出发点?br>  例如QContent-Location: http://www.myweb.com/news
Content-MD5  实体的一UMD5摘要Q用作校验和?br>  发送方和接受方都计MD5摘要Q接受方其计算的g此头标中传递的D行比较?br>  例如QContent-MD5: <base64 of 128 MD5 digest>
Content-Range  随部分实体一同发送;标明被插入字节的低位与高位字节偏U,也标明此实体的总长度?br>  例如QContent-Range: 1001-2000/5000
Contern-Type  标明发送或者接收的实体的MIMEcd。例如:Content-Type: text/html
Date   发送HTTP消息的日期。例如:Date: Mon,10PR 18:42:51 GMT
ETag   一U实体头标,它向被发送的资源分派一个唯一的标识符?br>  对于可以使用多种URLh的资源,ETag可以用于定实际被发送的资源是否为同一资源?br>  例如QETag: "208f-419e-30f8dc99"
Expires  指定实体的有效期。例如:Expires: Mon,05 Dec 2008 12:00:00 GMT
Form   一U请求头标,l定控制用户代理的h工用L电子邮g地址。例如:From: webmaster@myweb.com
Host   被请求资源的L名。对于用HTTP/1.1的请求而言Q此域是强制性的。例如:Host: www.myweb.com
If-Modified-Since 如果包含了GEThQ导致该h条g性地依赖于资源上ơ修Ҏ期?br>  如果出现了此头标Qƈ且自指定日期以来Q此资源已被修改Q应该反回一?04响应代码?br>  例如QIf-Modified-Since: Mon,10PR 18:42:51 GMT
  If-Match 如果包含于一个请求,指定一个或者多个实体标记。只发送其ETag与列表中标记区配的资源?br>  例如QIf-Match: "208f-419e-308dc99"
  If-None-Match 如果包含一个请求,指定一个或者多个实体标记。资源的ETag不与列表中的M一个条件匹配,操作才执行?br>  例如QIf-None-Match: "208f-419e-308dc99"
If-Range  指定资源的一个实体标讎ͼ客户端已l拥有此资源的一个拷贝。必MRange头标一同用?br>  如果此实体自上次被客L索以来,q不曾修改过Q那么服务器只发送指定的范围Q否则它发送整个资源?br>  例如QRange: byte=0-499<CRLF>If-Range:"208f-419e-30f8dc99"
If-Unmodified-Since 只有自指定的日期以来Q被h的实体还不曾被修改过Q才会返回此实体?br>  例如QIf-Unmodified-Since:Mon,10PR 18:42:51 GMT
Last-Modified  指定被请求资源上ơ被修改的日期和旉。例如:Last-Modified: Mon,10PR 18:42:51 GMT
Location  对于一个已l移动的资源Q用于重定向h者至另一个位|?br>  与状态编?02Q暂时移动)或?01Q永久性移动)配合使用?br>  例如QLocation: http://www2.myweb.com/index.jsp
Max-Forwards  一个用于TRACEҎ的请求头标,以指定代理或|关的最大数目,该请求通过|关才得以\由?br>  在通过h传递之前,代理或网兛_该减此数目。例如:Max-Forwards: 3
Pragma   一个通用头标Q它发送实现相关的信息。例如:Pragma: no-cache
Proxy-Authenticate cM于WWW-AuthenticateQ便是有意请求只来自h链(代理Q的下一个服务器的认证?br>  例如QProxy-Authenticate: Basic realm-admin
Proxy-Proxy-Authorization cM于授权,但ƈ非有意传递Q何比在即时服务器链中更进一步的内容?br>  例如QProxy-Proxy-Authorization: Basic YXV0aG9yOnBoaWw=
Public   列表昄服务器所支持的方法集。例如:Public: OPTIONS,MGET,MHEAD,GET,HEAD
Range   指定一U度量单位和一个部分被h资源的偏U范围。例如:Range: bytes=206-5513
Refener  一U请求头标域Q标明生请求的初始资源。对于HTML表单Q它包含此表单的Web面的地址?br>  例如QRefener: http://www.myweb.com/news/search.html
Retry-After  一U响应头标域Q由服务器与状态编?03Q无法提供服务)配合发送,以标明再ơ请求之前应该等待多长时间?br>  此时间即可以是一U日期,也可以是一U秒单位。例如:Retry-After: 18
Server   一U标明Web服务器Y件及其版本号的头标。例如:Server: Apache/2.0.46(Win32)
Transfer-Encoding 一U通用头标Q标明对应被接受方反向的消息体实施变换的cd。例如:Transfer-Encoding: chunked
Upgrade  允许服务器指定一U新的协议或者新的协议版本,与响应编?01Q切换协议)配合使用?br>  例如QUpgrade: HTTP/2.0
User-Agent  定义用于产生h的Y件类型(典型的如Web览器)?br>  例如QUser-Agent: Mozilla/4.0(compatible; MSIE 5.5; Windows NT; DigExt)
Vary   一个响应头标,用于表示使用服务器驱动的协商从可用的响应表示中选择响应实体。例如:Vary: *
Via   一个包含所有中间主机和协议的通用头标Q用于满求。例如:Via: 1.0 fred.com, 1.1 wilma.com
Warning  用于提供关于响应状态补充信息的响应头标。例如:Warning: 99 www.myweb.com Piano needs tuning
www-Authenticate 一个提C用户代理提供用户名和口令的响应头标Q与状态编?01Q未授权Q配合用。响应一个授权头标?br>  例如Qwww-Authenticate: Basic realm=zxm.mgmt

= HTTP码应?br>响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一? 分五U类型,由它们的W一位数字表C:
- 1xxQ信息,h收到Ql处?br>- 2xxQ成功,行ؓ被成功地接受、理解和采纳
- 3xxQ重定向Qؓ了完成请求,必须q一步执行的动作
- 4xxQ客L错误Q请求包含语法错误或者请求无法实?br>- 5xxQ服务器错误Q服务器不能实现一U明显无效的h

下表昄每个响应码及其含义:
100 l箋
101 分组交换?br>200 OK
201 被创?br>202 被采U?br>203 非授权信?br>204 无内?br>205 重置内容
206 部分内容
300 多选项
301 怹C?br>302 扑ֈ
303 参见其他
304 未改?br>305 使用代理
307 暂时重定?br>400 错误h
401 未授?br>402 要求付费
403 止
404 未找?br>405 不允许的Ҏ
406 不被采纳
407 要求代理授权
408 h时
409 冲突
410 q期?br>411 要求的长?br>412 前提不成?br>413 h实例太大
414 hURI太大
415 不支持的媒体cd
416 无法满的请求范?br>417 p|的预?br>500 内部服务器错?br>501 未被使用
502 |关错误
503 不可用的服务
504 |关时
505 HTTP版本未被支持


= 实例

== POST 数据

== 上传一个文?
假设接受文g的网늨序位?a
bb
ccc

客户端链?192.168.29.65 ? 应该发送如下http hQ?br>POST /upload_file/UploadFile HTTP/1.1
Accept: text/plain, */*
Accept-Language: zh-cn
Host: 192.168.29.65
Content-Type:multipart/form-data;boundary=---------------------------7d33a816d302b6
User-Agent: Mozilla/4.0 (compatible; OpenOffice.org)
Content-Length: 333
Connection: Keep-Alive

-----------------------------7d33a816d302b6
Content-Disposition: form-data; name="userfile1"; filename="E:s"
Content-Type: application/octet-stream
a
bb
ccc
-----------------------------7d33a816d302b6
Content-Disposition: form-data; name="text1"
foo
-----------------------------7d33a816d302b6
Content-Disposition: form-data; name="password1"
bar
-----------------------------7d33a816d302b6--

(上面有一个回?

此内容必M字不差,包括最后的回R?
注意QContent-Length: 333 q里?33是红色内容的总长度(包括最后的回RQ?
注意q一行:
Content-Type: multipart/form-data; boundary=---------------------------7d33a816d302b6
Ҏ rfc1867, multipart/form-data是必ȝ.
---------------------------7d33a816d302b6 是分隔符Q分隔多个文件、表单项。其?3a816d302b6 是即时生成的一个数字,用以保整个分隔W不会在文g或表单项的内容中出现?strong>Form每个部分用分隔符分割Q分隔符之前必须加上"--"着两个字符(?-{boundary})才能被http协议认ؓ是Form的分隔符Q表C结束的话用在正的分隔W后面添?--"表示l束?/strong>

前面?---------------------------7d ?IE Ҏ的标?Mozila ?--------------------------71.
每个分隔的数据的都可以用Content-Type来表CZ面数据的cdQ可以参考rfc1341 (
http://www.ietf.org/rfc/rfc1341.txt) 例如Q?
Contect-Type:application/octet-stream 表示下面的数据是二进制数?
Contect-Type:text/plain 表示下面的数据是ASSCII码数?
Contect-Type:text/richtext 表示下面的数据是RTF格式



]]>
?C++ 中?Python script http://www.shnenglu.com/bigsml/archive/2008/08/14/58859.html泡?/dc:creator>泡?/author>Thu, 14 Aug 2008 09:55:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/08/14/58859.htmlhttp://www.shnenglu.com/bigsml/comments/58859.htmlhttp://www.shnenglu.com/bigsml/archive/2008/08/14/58859.html#Feedback4http://www.shnenglu.com/bigsml/comments/commentRss/58859.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/58859.html惌在c++ 中嵌入script 代码, 除了自己写脚本引擎外, lua, python 都可以在c++ 中? 另外 MonoBind, AngelScript library 都是一些c++ script library, 可以嵌入到c++ 中?.
今天在c++ 中试着嵌入 python 代码 (CZ代码?Python-2.5.2\Demo\embed\ ?

#include <Python.h>
int main(int argc, char *argv[])
{
  
// Py_NoSiteFlag = 1;
  
// Py_SetPythonHome("D:\\usr\\Python"); // PYTHONHOME

  Py_Initialize();
  PyRun_SimpleString(
"from time import time,ctime\n"
                     
"print 'Today is',ctime(time())\n");
  Py_Finalize();
  
return 0;
}

在运行时可能会生类?'import site' failed; use -v for traceback 的错? 原因是python 在import module 的时候的路径问题. ?U方法可以解?以前通过讄环境变量 PYTHONPATH 好像?.5 已经无效?.
0. 取消注释 Py_NoSiteFlag = 1;
q个只是取消import site , 当然如果在代码中要import 啥的? q是会出现错误的.
a. 讄环境变量 PYTHONHOME = D:\usr\Python 
b. 在调?Py_Initialize 之前调用函数
Py_SetPythonHome("D:\\usr\\Python");  // 参数是python 的安装目?

2. 其他一些有用的资源
Python/C API Reference Manual (API 参? ,  Extending and Embedding the Python Interpreter (扩展及嵌入Python解释? 主要说明了如何扩展Python, lPython 写扩? 其中 5. Embedding Python in Another Application  一章讲qC在C++中嵌?调用Python 代码 )

使用C/C++扩展Python  Ҏ Extending and Embedding the Python Interpreter 作了_, 很不错的一文? 但是跌了一些基 .

Building Hybrid Systems with Boost.Python 介绍了用boost.python 方便python 插g开? pythonl定c++E序 是其中文版本.

Embedding Python in Multi-Threaded C/C++ Applications 讲了c++在多U程环境如何使用Python , ?nbsp;C++多线E中调用python api函数 提供了一个多U程的封?

SCXX - A Simple Python/C++ API
http://davidf.sjsoft.com/mirrors/mcmillan-inc/scxx.html

C++扩展和嵌入Python应用 (介绍了一些Python/C API 函数, 以及ext 例子, 一般般)
http://hi.baidu.com/yunsweet/blog/item/20b08aeebaa2b1282cf534c7.html


3. Python 多线E的使用

zz http://blog.csdn.net/liguangyi/archive/2007/06/20/1659697.aspx 
今天看了q一天关于多U程的应用中Q如何安全调用python斚w的资料,开始的时候看的简直头大如斗,被python语言的全局?Global Interpreter Lock)、线E状?Thread State ){都有点l晕了,后来l过各方面文章和帮助文档的相互参考,发现对于2.4/2.5版本Q提供了PyGILState_Ensure, PyGILState_ReleaseQ哎Q这下可方便大发了?/p>

一、首先定义一个封装类Q主要是保证PyGILState_Ensure, PyGILState_Release配对使用Q而且q个cL可以嵌套使用的?/p>

#include <python.h>

class PyThreadStateLock
{
public:
    PyThreadStateLock(void)
    {
        state = PyGILState_Ensure( );
    }

    ~PyThreadStateLock(void)
    {
         PyGILState_Release( state );
    }
private:
    PyGILState_STATE state;
};


二、在ȝE中Q这样处?/p>

    // 初始?br>    Py_Initialize();
    // 初始化线E支?br>    PyEval_InitThreads();
    // 启动子线E前执行Qؓ了释放PyEval_InitThreads获得的全局锁,否则子线E可能无法获取到全局锁?br>    PyEval_ReleaseThread(PyThreadState_Get());
  
    // 其他的处理,如启动子U程{?br>    ......
      
    // 保证子线E调用都l束?br>    PyGILState_Ensure();
    Py_Finalize();
    // 之后不能再调用Q何python的API

三、在ȝE,或者子U程中,调用python本n函数的都采用如下处理

    {
        class PyThreadStateLock PyThreadLock;
        // 调用python的API函数处理
        ......
    }

呵呵Q看q样是否非常单了?/p>


另外q有两个和全局锁有关的宏,Py_BEGIN_ALLOW_THREADS ?Py_END_ALLOW_THREADS。这两个宏是Z在较长时间的C函数调用前,临时释放全局锁,完成后重新获取全局锁,以避免阻塞其他python的线El运行。这两个宏可以这栯?/p>

    {
        class PyThreadStateLock PyThreadLock;
        // 调用python的API函数处理
        ......

        Py_BEGIN_ALLOW_THREADS
        // 调用需要长旉的C函数
        ......
        Py_END_ALLOW_THREADS

        // 调用python的API函数处理
        ......
    }

4. 可能的错误及解决
a. 在vs 200x ?debug 模式出现链接问题
extmodule.obj : error LNK2019: unresolved external symbol __imp___Py_Dealloc referenced in function _PySwigObject_format
extmodule.obj : error LNK2019: unresolved external symbol __imp___Py_NegativeRefcount referenced in function _PySwigObject_format
extmodule.obj : error LNK2001: unresolved external symbol __imp___Py_RefTotal
extmodule.obj : error LNK2019: unresolved external symbol __imp___PyObject_DebugFree referenced in function _PySwigObject_dealloc
extmodule.obj : error LNK2019: unresolved external symbol __imp___PyObject_DebugMalloc referenced in function _PySwigObject_New
extmodule.obj : error LNK2019: unresolved external symbol __imp__Py_InitModule4TraceRefs referenced in function _init_extmodule

主要是因?Py_DEBUG/Py_TRACE_REFS 引v, 修改 Python\include 下的 pyconfig.h, object.h 两个文gp?... 详见 http://www.nabble.com/link-error-in-debug-mode-td3126668.html 



]]>
使用 python ?COM http://www.shnenglu.com/bigsml/archive/2008/08/14/58851.html泡?/dc:creator>泡?/author>Thu, 14 Aug 2008 09:02:00 GMThttp://www.shnenglu.com/bigsml/archive/2008/08/14/58851.htmlhttp://www.shnenglu.com/bigsml/comments/58851.htmlhttp://www.shnenglu.com/bigsml/archive/2008/08/14/58851.html#Feedback0http://www.shnenglu.com/bigsml/comments/commentRss/58851.htmlhttp://www.shnenglu.com/bigsml/services/trackbacks/58851.html1. com 调用CZ(使用Windows Media Player 播放音乐)
from win32com.client import Dispatch
mp 
= Dispatch("WMPlayer.OCX")
tune 
= mp.newMedia("C:/WINDOWS/system32/oobe/images/title.wma")
mp.currentPlaylist.appendItem(tune)
mp.controls.play()

2. com server 的编?br>主要可以参?<<Python Programming on Win32 ?Chapter 12 Advanced Python and COM http://oreilly.com/catalog/pythonwin32/chapter/ch12.html >>
CZ(分割字符?
- 代码
class PythonUtilities:
    _public_methods_ 
= [ 'SplitString' ]
    _reg_progid_ 
= "PythonDemos.Utilities"
    
# NEVER copy the following ID 
    # Use "print pythoncom.CreateGuid()" to make a new one.
    _reg_clsid_ = "{41E24E95-D45A-11D2-852C-204C4F4F5020}"
    
    
def SplitString(self, val, item=None):
        
import string
        
if item != None: item = str(item)
        
return string.split(str(val), item)
 
# Add code so that when this script is run by
#
 Python.exe, it self-registers.
if __name__=='__main__':
    
print "Registering COM server"
    
import win32com.server.register
    win32com.server.register.UseCommandLine(PythonUtilities)

- 注册/注销Com

Command-Line Option

Description

 

The default is to register the COM objects.

--unregister

Unregisters the objects. This removes all references to the objects from the Windows registry.

--debug

Registers the COM servers in debug mode. We discuss debugging COM servers later in this chapter.

--quiet

Register (or unregister) the object quietly (i.e., don't report success).


- 使用COM
可以在python 命o行下q行
>>> import win32com.client
>>> s = win32com.client.Dispatch("PythonDemos.Utilities")
>>> s.SplitString("a,b,c"",")
((u
'a', u'a,b,c'),)
>>>

3. python server com 原理
其实在注册表中查扑ֈpython com 的实现内q?
Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}]
@
="PythonDemos.Utilities"

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\Debugging]
@
="0"

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\Implemented Categories]

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\Implemented Categories\{B3EF80D0-68E2-11D0-A689-00C04FD658FF}]

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\InprocServer32]
@
="pythoncom25.dll"
"ThreadingModel"="both"

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\LocalServer32]
@
="D:\\usr\\Python\\pythonw.exe \"D:\\usr\\Python\\lib\\site-packages\\win32com\\server\\localserver.py\" {41E24E95-D45A-11D2-852C-204C4F4F5020}"

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\ProgID]
@
="PythonDemos.Utilities"

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\PythonCOM]
@
="PythonDemos.PythonUtilities"

[HKEY_CLASSES_ROOT\CLSID\{41E24E95-D45A-11D2-852C-204C4F4F5020}\PythonCOMPath]
@
="D:\\"

inproc server 是通过pythoncom25.dll 实现
local server 通过localserver.py 实现
com 对应的python 源文件信息在 PythonCOMPath & PythonCOM

4. 使用问题
用PHP 或?c 调用com 的时?br>
<?php
$com = new COM("PythonDemos.Utilities");
$rs = $com->SplitString("a b c");
foreach($rs as $r)
    
echo $r."\n";
?>
会碰C面的一些错?
pythoncom error: PythonCOM Server - The 'win32com.server.policy' module could not be loaded.
<type 'exceptions.ImportError'>: No module named server.policy pythoncom error: CPyFactory::CreateInstance failed to create instance. (80004005)


可以通过2U方式解?
a. 讄环境 PYTHONHOME = D:\usr\Python
另外在c ++ 使用python 的时? 如果import module 出现错误 'import site' failed; use -v for traceback 的话, 也可以通过讄q个变量解决.

b. 为com 生exe, dll 可执行文? setup.py 代码如下 :
from distutils.core import setup 
import py2exe 

import sys 
import shutil 

# Remove the build tree ALWAYS do that! 
shutil.rmtree("build", ignore_errors=True) 

# List of modules to exclude from the executable 
excludes = ["pywin""pywin.debugger""pywin.debugger.dbgcon""pywin.dialogs""pywin.dialogs.list"

# List of modules to include in the executable 
includes = ["win32com.server"

# ModuleFinder can't handle runtime changes to __path__, but win32com uses them 
try
    
# if this doesn't work, try import modulefinder 
    import py2exe.mf as modulefinder 
    
import win32com 
    
    
for p in win32com.__path__[1:]: 
        modulefinder.AddPackagePath(
"win32com", p) 
    
    
for extra in ["win32com.shell""win32com.server"]: #,"win32com.mapi" 
        __import__(extra) 
        m 
= sys.modules[extra] 
        
for p in m.__path__[1:]: 
            modulefinder.AddPackagePath(extra, p) 

except ImportError: 
    
# no build path setup, no worries. 
    pass 

# Set up py2exe with all the options 
setup( 
    options 
= {"py2exe": {"compressed"2
                          
"optimize"2
                          
#"bundle_files": 1, 
                          "dist_dir""COMDist"
                          
"excludes": excludes, 
                          
"includes": includes}}, 
    
# The lib directory contains everything except the executables and the python dll. 
    # Can include a subdirectory name. 
    zipfile = None, 
    com_server 
= ['PythonDemos'], # 文g?!
    ) 


ref:
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html 
http://blog.donews.com/limodou/archive/2005/09/02/537571.aspx 


]]>
þһձɫۺϾþ| ҹ91þø| 99þùۺϾƷ| þþþþþþþ| ھƷþþĻ | ޾Ʒþþþ66| ɫۺϾþĻۺ| ƷþþþþþҹƬ | ƯޱгĻþ| Ʒ99þþþ| þþþþþþþѾƷ| þøһëƬ| ?VþþƷ | þۺϾƷþ| þ޹ӰԺ| ƷþþĻ| ޾þþþþ77777| ˾þۺ| þþ޾Ʒ| 99þþƷþþþþ崿| þþþþ޾Ʒ| ھƷþþþӰԺ޹²| ھƷþ| þøݾƷԴվ| þþþþþþþѾƷ| þþþAVվ| þѵľƷV| 99ھƷþþþþþ| þۺϹɫ88þþƷۺ| þۺϾþڹ| Ʒ99þþþþ| þ̳| ƷŮþþþ| þþþAV| þ޴ɫĻþþ | Ʒþþþþ| һŮȫƾþƬ | һۺϾþù| þùƷþ| ƷþþĻ| þþþþþùѿ|