本文整理汇总了Python中sender.Sender类的典型用法代码示例。如果您正苦于以下问题:Python Sender类的具体用法?Python Sender怎么用?Python Sender使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sender类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, config, log):
Sender.__init__(self, config, log)
self.access_key = config.get('Messenger', 'gcm_access_key')
self.base_deeplink_url = config.get('Messenger', 'base_deeplink_url')
self.gcm = GCM(self.access_key)
self.canonical_ids = []
self.unregistered_devices = []
示例2: main
def main():
# TODO: parse configuration file to retreive
# sender's and receiver's ip addresses
config_dict = parse_config()
if not config_dict:
print 'no config params'
return
sender_name = config_dict['IP'] + '_sender'
recv_name = config_dict['IP'] + '_receiver'
print 'sender name: ' + sender_name
print 'receiver name: ' + recv_name
s_obj = Sender()
r_obj = Receiver()
s_obj.ip_address = config_dict['IP']
r_obj.ip_address = config_dict['IP']
s_obj.multicast_address = config_dict['multicast']
r_obj.multicast_address = config_dict['multicast']
Pyro4.Daemon.serveSimple(
{
s_obj: sender_name,
r_obj: recv_name
},
ns=False,
port=45000,
host=config_dict["IP"]
)
示例3: OnActionStart
def OnActionStart(self, event):
handler = rt.RichTextHTMLHandler()
handler.SetFlags(rt.RICHTEXT_HANDLER_SAVE_IMAGES_TO_BASE64)
handler.SetFontSizeMapping([7,9,11,12,14,22,100])
import cStringIO
stream = cStringIO.StringIO()
if not handler.SaveStream(self.richTextPanel.rtc.GetBuffer(), stream):
return
htmldata = stream.getvalue()
text = content.mime_message(htmldata, "hello hello this is a test", "this is a test", "[email protected]",
"[email protected]").as_string()
with open('email-example.eml', 'w') as f:
f.write(text)
#start send
listctrl = self.list_ctrl
_count = listctrl.GetItemCount()
_host = config.read_config(config.HOST)
_port = config.read_config(config.PORT)
_user = config.read_config(config.ACCOUNT_NAME)
_password = config.read_config(config.PASSWORD)
_from = config.read_config(config.FROM)
sender = Sender(_host, _port)
sender.login(_user, _password)
for i in range(_count):
sender.send(_from, listctrl.GetItem(i, 1).GetText(), text)
示例4: postIpDel
def postIpDel(request):
form = IpForm(request.REQUEST, request.FILES)
if not form.is_valid():
return json_response({"status": FORM_ERR, "result": 'Ошибка формы'})
login = form.cleaned_data['user_login']
del_ips = json.loads(form.cleaned_data['ip_list'])
kwargs = {'action': 'del_ip', 'user': login, 'ip_list': '{ip_list:' + json.dumps(del_ips) + '}'}
from models import WebApiSetting
web_api_settings = WebApiSetting.objects.all();
if len(web_api_settings)>0:
sd = Sender(web_api_settings[0].host,web_api_settings[0].port, web_api_settings[0].users_url)
status, reason, resp = sd.sendData(kwargs)
if status == ERROR400:
return json_response({"status":LOGIN_ERR, "result": "Неверное указано имя пользователя"})
elif status != SUCCESS:
logging.error("videoclient.configuration.web_api_users.wiews.postIpDel(connection failed) :" + 'Ошибка соединения при получении списка ip адресов пользователя')
return json_response({"status":ERROR, "result": "Повторите запрос позже"})
else:
logging.error("videoclient.configuration.web_api_users.wiews.postIpDel(connection failed) :" + 'Отсутствуют настройки для WEB API')
return json_response({"status":ERROR, "result": "Повторите запрос позже"})
return json_response({"status": OK, "result": "IP-адреса удалены (" + str(len(del_ips)) + ')'})
示例5: postTableStatistics
def postTableStatistics(request):
form = StatisticForm(request.REQUEST, request.FILES)
if not form.is_valid():
return json_response({"status": FORM_ERR, "result": 'Повторите запрос позже'})
data = dict()
login = form.cleaned_data['user_login']
s_date = form.cleaned_data['start_date']
e_date = form.cleaned_data['end_date']
query = form.cleaned_data['query']
sorto = form.cleaned_data["sorto"]
data['sorto'] = sorto
data['up'] = form.cleaned_data['up']
kwargs = {'user': login, 'query': query, 'start_date': s_date, 'end_date': e_date}
from models import WebApiSetting
web_api_settings = WebApiSetting.objects.all();
if len(web_api_settings)==0:
logging.error("videoclient.configuration.web_api_users.wiews.postIpDel(connection failed) :" + 'Отсутствуют настройки для WEB API')
return json_response({"status": ERROR, "result": 'Стастистика временно недоступна. Повторите запрос позже.'})
sd = Sender(web_api_settings[0].host,web_api_settings[0].port, web_api_settings[0].stat_url)
status, reason, resp = sd.sendData(kwargs)
del sd
if status == ERROR400:
return json_response({"status": LOGIN_ERR, "result": 'Неизвестный пользователь'})
if status != SUCCESS:
return json_response({"status": ERROR, "result": 'Стастистика временно недоступна. Повторите запрос позже.'})
ipstat = json.loads(resp)
#вычисляем суммы столбцов и строк таблицы
total = {}
column_list = ['detect', 'detect_and_identification', 'fanstudio']
for column_name in column_list:
total[column_name] = 0
total['total'] = 0
for host in ipstat:
host['total'] = 0
for column_name in column_list:
total[column_name] += host[column_name]
total['total'] += host[column_name]
host['total'] += host[column_name]
#сортируем
sort_fields = ["ip", 'detect', 'detect_and_identification', 'fanstudio', 'total']
if sorto > 0 and sorto <= len(sort_fields):
sort = [[sort_fields[sorto - 1]]]
ipstat = GlobalSortUser(ipstat, sort, 1, up=form.cleaned_data["up"])
data['table'] = ipstat
data['total'] = total
from django.template import loader
if ipstat:
result = loader.render_to_string('stat_table.html', data)
else:
result = False
return json_response({'result': result, 'status': OK})
示例6: __init__
def __init__(self, config, log):
Sender.__init__(self, config, log)
self.sandbox = config.getboolean('Messenger', 'apns_sandbox')
self.certificate_path = config.get('Messenger', 'apns_certificate_path')
self.topic = config.get('Messenger', 'apns_topic')
self.apn = APNsClient(self.certificate_path, use_sandbox=self.sandbox, log=log)
self.canonical_ids = []
self.unregistered_devices = []
示例7: submit
def submit(d):
header = Header(d["method"], d["path"], d["httpversion"])
for i in d['headers']:
header.add_header(i['header_name'], i['header_value'])
header.build_from_text()
print(header.payload)
s = Sender()
r = Response()
resp = r.input_text(s.send(d["protocol"], d["hostname"], header.payload))
return resp
示例8: stream_sdata
def stream_sdata(self, datasize, cl_port):
if self.state != 2:
logging.error('stream_sdata: unexpected cur_state=%s', self.state)
return
#
to_addr = (self.cl_ip, cl_port)
sender = Sender(dst_addr = to_addr,
proto = self.proto,
datasize = datasize,
tx_type = self.tx_type,
file_url = self.file_url )
sender.init_send()
示例9: main
def main():
users = Users()
receiver = Receiver()
sender = Sender()
while True:
receiver.read_emails(users)
for user in users.users_map.values():
if user.modified:
sender.send_news(user.email, list(user.topics_set))
user.modified = False
print ('Sleeping')
sleep(10)
print ('Waking up')
示例10: __send_broadcast_frame
def __send_broadcast_frame(self, frame):
"""
Method that send broadcast frame if possible or push the frame to the queue of all Workers.
This is necessary because we are not able to identify ACK frames because of the missing sequence number on WiWo
frames.
"""
if self.__are_workers_available_for_broadcast_frame():
self.__set_workers_to_wait_response(frame)
Sender.send(frame, self.__iface_name)
else:
time.sleep(1) # TODO: Fix this code, it's not clear.
if self.__are_workers_available_for_broadcast_frame():
self.__set_workers_to_wait_response(frame)
Sender.send(frame, self.__iface_name)
示例11: getTableIp
def getTableIp(request):
form = UserForm(request.REQUEST, request.FILES)
data = dict()
ips = []
if form.is_valid():
login = form.cleaned_data["user_login"]
sorto = form.cleaned_data["sorto"]
up = form.cleaned_data["up"]
data.update(form.cleaned_data)
kwargs = {'action': 'get_ip', 'user': login}
from models import WebApiSetting
web_api_settings = WebApiSetting.objects.all();
if len(web_api_settings)>0:
sd = Sender(web_api_settings[0].host,web_api_settings[0].port, web_api_settings[0].users_url)
status, reason, resp_str = sd.sendData(kwargs)
if status == ERROR400:
data["error"] = LOGIN_ERR
elif status != SUCCESS:
data["error"] = ERROR
else:
resp = json.loads(resp_str)
if 'ip_list' in resp:
ips = resp['ip_list']
else:
logging.error("videoclient.configuration.web_api_users.wiews.getTableIp(connection failed) :" + 'Отсутствуют настройки для WEB API')
data["error"] = ERROR
else:
data["user_login"] = ''
data["error"] = FORM_ERR
if 'error' in data:
return json_response({'status': data["error"], 'result': ''})
#сортируем
sort_fields = ["ip"]
sorto = form.cleaned_data["sorto"]
if sorto > 0 and sorto <= len(sort_fields):
ips = sorted(ips, reverse=(up == 0))
data["ip_list"] = ips
from django.template import loader
result = loader.render_to_string('ip_table.html', data, context_instance=RequestContext(request))
return json_response({'status': OK, 'result': result})
示例12: main
def main():
sender = Sender('localhost')
sender.connect()
sender.create_queue('inbox')
sender.send_message('inbox', 'hello')
sender.disconnect()
receiver = Receiver('localhost')
receiver.connect()
receiver.receive('inbox')
receiver.disconnect()
示例13: sender_query
def sender_query(self, mac=None, sort='last_seen', time_window=None, advanced=None, count=None):
"""Query the database for a sender by it's MAC address.
If mac is None - return a list of all senders.
sort can start with `-' to change sort direction
time_window - recently seen (X seconds) senders only
"""
# Parse sorting order
direction = 1
if sort.startswith('-'):
direction = -1
sort = sort[1:]
# Build query
where = {}
if mac is not None:
where['mac'] = mac.lower()
if time_window:
now = time()
where['aggregate.last_seen'] = {
'$gt': now - time_window
}
if advanced is not None:
where.update(advanced)
senders = self.knowledge.find(where).sort(sort, direction)
if count is not None:
senders = senders[:count]
return Sender.create_from_db(senders)
示例14: _send
def _send(self, frame, iface_name):
self.__communication_status = Worker.COMMUNICATION_WAITING
self.__last_frame_sent = frame
frame = Sender.send(frame, iface_name)
log_line = "- [SENT]: %s" % repr(frame)
self.__frame_log.append(log_line)
return frame
示例15: __init__
def __init__(self, config, log):
"""
APNs Push Sender uses MODIFIED (watch out if you want to update it) PyAPNs module: https://github.com/djacobs/PyAPNs
APNs documentation: https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/CommunicatingWIthAPS.html#//apple_ref/doc/uid/TP40008194-CH101-SW4
"""
Sender.__init__(self, config, log)
self.sent_queue = {}
self.batch_size = int(config.get('Messenger', 'apns_batch_size'))
self.sandbox = config.get('Messenger', 'apns_sandbox') == 'true'
self.certificate_path = config.get('Messenger', 'apns_certificate_path')
set_logger(log)
self.apns = APNs(use_sandbox=self.sandbox, cert_file=self.certificate_path, enhanced=True,
write_retries=self.connection_error_retries)
self.apns.gateway_server.register_response_listener(self.process_malformed_notification)
self.apns.gateway_server.register_error_listener(self.process_failed_notification)