日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python能做哪些客户端_发布一个Httpsqs的Python客户端

發布時間:2024/7/5 python 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python能做哪些客户端_发布一个Httpsqs的Python客户端 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這款軟件有幾種客戶端, Java/Perl/C,卻沒有Python的客戶端.

故,本人奉上一個實現,歡迎指正!!

代碼:

#Verion 1.0

#Author wendal(wendal1985@gmail.com)

#If you find a bug, pls mail me

import sys,httplib

ERROR = 'HTTPSQS_ERROR'

GET_END = 'HTTPSQS_GET_END'

PUT_OK = 'HTTPSQS_PUT_OK'

PUT_ERROR = 'HTTPSQS_PUT_ERROR'

PUT_END = 'HTTPSQS_PUT_END'

RESET_OK = 'HTTPSQS_RESET_OK'

RESET_ERROR = 'HTTPSQS_RESET_ERROR'

MAXQUEUE_OK = 'HTTPSQS_MAXQUEUE_OK'

MAXQUEUE_CANCEL = 'HTTPSQS_MAXQUEUE_CANCEL'

SYNCTIME_OK = 'HTTPSQS_SYNCTIME_OK'

SYNCTIME_CANCEL = 'HTTPSQS_SYNCTIME_CANCEL'

class Httpsqs(object):

def __init__(self,host,port=1218):

self.host = host

self.port = port

def get(self,poolName):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("GET", "/?opt=get&name;=" + poolName)

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

conn.close()

return data

return ''

def put(self,poolName,data):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("POST", "/?opt=put&name;="+poolName,data)

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

return data

return ''

def status(self,poolName):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("GET", "/?opt=status&name;="+poolName)

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

return data

return ''

def status_json(self,poolName):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("GET", "/?opt=status_json&name;="+poolName)

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

return data

return ''

def reset(self,poolName):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("GET", "/?opt=reset&name;="+poolName)

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

return data

return ''

def maxlen(self,poolName,num):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("GET", "/?opt=maxqueue&name;="+poolName+"#="+str(num))

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

return data

return ''

def synctime(self,poolName,num):

conn = httplib.HTTPConnection(self.host,self.port)

conn.request("GET", "/?opt=synctime&name;="+poolName+"#="+str(num))

r = conn.getresponse()

if r.status == httplib.OK :

data = r.read()

return data

return ''

def isOK(data):

if data is '' :

return False

if data is ERROR :

return False

if data is GET_END :

return False

if data is PUT_ERROR :

return False

if data is RESET_ERROR :

return False

if data is MAXQUEUE_CANCEL :

return False

if data is SYNCTIME_CANCEL :

return False

return True

測試代碼就不貼,需要的話就下載zip包吧.

因為Httpsqs本身就是基于Http協議的,故各種客戶端實現都只是封裝一下,本python客戶端也不例外.

blog comments powered by Disqus

總結

以上是生活随笔為你收集整理的python能做哪些客户端_发布一个Httpsqs的Python客户端的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。