twisted

twisted conch filetransfer

你离开我真会死。 提交于 2019-11-27 19:10:54
I am trying to implement a very simple file transfer client in python using twisted conch. The client should simply transfer a few files to a remote ssh/sftp server in a programatic way. The function is given username, password, file list, destination server:directory and just needs to carry out the authentication and copying in a cross-platform way. I have read some introductory material on twisted and have managed to make my own SSH client which just executes cat on the remote server. I am having a real difficult time extending this to moving the files over. I have taken a look at cftp.py

Force python to use an older version of module (than what I have installed now)

南笙酒味 提交于 2019-11-27 19:08:10
My employer has a dedicated module 1 we use for internal unit / system test; however, the author of this module no longer works here and I have been asked to test some devices with it. The problem is that pyfoo requires an ancient version of twisted (v8.2.0) and it imports twisted in 33 different files. I tried running pyfoo 's unit tests under v11.0.0 and I don't even see TCP SYN packets 2 . Unfortunately, I have already got twisted v11.0.0 installed on my lab linux server and I have my own code that depends on it. I have been wracking my brain for a way around this, but I can only come up

zg手册 之 twisted 开发(1)-- twisted 框架介绍

寵の児 提交于 2019-11-27 19:07:41
异步非阻塞框架 twisted 是一个事件驱动的网络开发框架,使用 python 开发。 twisted 框架编写的服务器有几个基本的元素: 应用程序对象(application):管理应用程序资源的对象,一个应用程序可以管理多个service对象。 服务(service),服务对象启动监听的端口, 协议工厂(factory):当客户端连接到服务器时,用来创建协议对象。 协议(protocol):每个协议对象对应一个网络连接。协议类处理网络协议(如http,ftp,自定义协议等) twisted 框架内部运行依赖的元素: reactor:异步事件的主要循环处理类,负责监控事件,调用注册的回调函数提供服务。(在linux上主要使用epoll/select来实现) defer: 异步回调序列,当序列被执行的时候,顺序执行注册的回调函数。 官方的一个例子 实现一个 echo server,创建文件 echoServ.py #!/usr/bin/env python # coding: utf-8 from twisted.internet.protocol import Protocol from twisted.internet.protocol import Factory from twisted.internet.endpoints import

(转) Twisted :第十部分 增强defer功能的客户端

妖精的绣舞 提交于 2019-11-27 19:07:06
现在我们将要向诗歌下载客户端添加一些新的处理逻辑,包括在第九部分提到要添加的功能。不过,首先我要说明一点:我并不知道如何实现 Byronification 引擎。那超出了我的编程能力范围。取而代之的,我想实现一个简单的功能,即 Cummingsifier 。其只是将诗歌内容转换成小写字母: def cummingsify(poem) return poem.lower() 这个方法如此之简单以至于它永远不会出错。版本 5.0 的实现代码在 twisted-client-5/get-poetry.py 文件中。我们使用了修改后的 cummingsify ,其会随机地选择以下行为: 1. 返回诗歌的小写版本 2. 抛出一个 GibberishError 异常 3. 抛出一个 ValueError 这样,我们便模拟出来一个会因为各种意料不到的问题而执行失败的复杂算法。其它部分的仅有的改变在方法 poetry_main 中: def poetry_main(): addresses = parse_args() from twisted.internet import reactor poems = [] errors = [] def try_to_cummingsify(poem): try: return cummingsify(poem) except GibberishError

[twisted] 使用 logfile

ⅰ亾dé卋堺 提交于 2019-11-27 19:06:30
怎么使用 Twisted 的 log,看这: http://twistedmatrix.com/documents/current/core/howto/logging.html Twisted 中还定义了常用的 logfile,下面来说说用法。 LogFile 支持 rotate log file,就是超过大小自动生成新的 log 文件。 -------------------------------------------------------------- from twisted.python.logfile import LogFile fout = LogFile("a.txt", "/home/kasicass/sandbox/twisted/log", rotateLength=100) for i in xrange(1, 20): fout.write("myhello = %d\n" % i) fout.close() -------------------------------------------------------------- 当文件超过 rotateLength 大小,则把生成: a.txt # 当前正在写的log a.txt.1 a.txt.2 ... a.txt.n # 最老的log 有个问题,就是每次 a.txt 达到

Getting py2exe to work with zope.interface

跟風遠走 提交于 2019-11-27 18:58:37
问题 I have a Python app based on Twisted and PyGTK. Twisted itself depends on zope.interface, and I don't import it directly. Unfortunately, when I try to run my app, the following error ends up in the error log: Traceback (most recent call last): File "tasks.py", line 4, in <module> File "ui\__init__.pyc", line 14, in <module> File "twisted\python\log.pyc", line 17, in <module> ImportError: No module named zope.interface Traceback (most recent call last): File "tasks.py", line 4, in <module>

How to build Twisted servers which are able to do hot code swap in Python?

廉价感情. 提交于 2019-11-27 18:56:18
问题 I've developed a set of audio streaming server, all of them are using Twisted, and they are in Python, of course. They work, but a problem keeps troubling me, when I found some bugs there in the running server, or I want add something into the server, I need to stop them and start. Unlike HTTP servers, it's okay to restart them whenever, but not okay with audio streaming servers. Once I restart my streaming server, it means my users will encounter a disconnection. I did try to setup a manhole

Twisted: Making code non-blocking

本秂侑毒 提交于 2019-11-27 18:49:56
I'm a bit puzzled about how to write asynchronous code in python/twisted. Suppose (for arguments sake) I am exposing a function to the world that will take a number and return True/False if it is prime/non-prime, so it looks vaguely like this: def IsPrime(numberin): for n in range(2,numberin): if numberin % n == 0: return(False) return(True) (just to illustrate). Now lets say there is a webserver which needs to call IsPrime based on a submitted value. This will take a long time for large numberin . If in the meantime another user asks for the primality of a small number, is there a way to run

Which Python async library would be best suited for my code? Asyncore? Twisted?

此生再无相见时 提交于 2019-11-27 18:02:30
I have a program I'm working on that will be reading from two 'network sources' simultaneously. I wanted to try out an asynchronous approach rather than use threading. This has lead me to wonder which library to use... I've come up with some simple example code that kind of demonstrates what my program will be doing: import sniffer def first(): for station in sniffer.sniff_wifi(): log(station.mac()) def second(): for station in sniffer.sniff_ethernet(): log(station.mac()) first() second() The two sniffer methods look somewhat like this: def sniff_wifi(self): while True: yield mac_address The

Twisted network client with multiprocessing workers?

谁说我不能喝 提交于 2019-11-27 16:39:59
问题 So, I've got an application that uses Twisted + Stomper as a STOMP client which farms out work to a multiprocessing.Pool of workers. This appears to work ok when I just use a python script to fire this up, which (simplified) looks something like this: # stompclient.py logging.config.fileConfig(config_path) logger = logging.getLogger(__name__) # Add observer to make Twisted log via python twisted.python.log.PythonLoggingObserver().start() # initialize the process pool. (child processes get