本文整理汇总了Python中sleekxmpp.util.misc_ops.setdefaultencoding函数的典型用法代码示例。如果您正苦于以下问题:Python setdefaultencoding函数的具体用法?Python setdefaultencoding怎么用?Python setdefaultencoding使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setdefaultencoding函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(args=None, _bot_cls=MucChatBot, _cmd_cls=JibberCmd):
if args is None:
args = sys.argv[1:]
_default = 'console'
parser, sp = get_argparsers()
# workaround for python2.7's incorrect(?) default usage.
# won't be needed in python3.3.
if not set.intersection(set(args), set(sp.choices.keys())):
args.append(_default)
parsed_args = parser.parse_args(args)
# Python versions before 3.0 do not use UTF-8 encoding
# by default. To ensure that Unicode is handled properly
# throughout SleekXMPP, we will set the default encoding
# ourselves to UTF-8.
if sys.version_info < (3, 0): # pragma: no cover
from sleekxmpp.util.misc_ops import setdefaultencoding
setdefaultencoding('utf8')
bot = _bot_cls()
if bot.load_server_config_from_path(parsed_args.server_config) is None:
print("Server config file `%s` not found." % parsed_args.server_config)
return
if bot.load_client_config_from_path(parsed_args.client_config) is None:
print("Client config file `%s` not found." % parsed_args.client_config)
return
c = _cmd_cls(bot)
# TODO make these logging configurable from the client_config
logging.basicConfig(
level='INFO',
format='%(asctime)s %(levelname)s %(name)s %(message)s'
)
try:
import readline
except ImportError: # pragma: no cover
pass
if parsed_args.command and parsed_args.command != _default:
cmdarg = getattr(parsed_args, 'cmdarg', '')
return c.onecmd(parsed_args.command + ' ' + cmdarg)
else: # interactive mode
c.cmdloop()
示例2: setdefaultencoding
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import firenado.core
import firenado.core.websocket
import logging
import tornado.escape
import uuid
import sys
from diaspora_jetpack.handlers import JetpackHandler
# Study this https://gist.github.com/mywaiting/4643396
if sys.version_info < (3, 0):
from sleekxmpp.util.misc_ops import setdefaultencoding
setdefaultencoding('utf8')
else:
raw_input = input
class ChatHandler(firenado.core.TornadoHandler):
def get(self):
cache = []
if self.session.id in self.component.xmpp_manager.connections:
cache = self.component.xmpp_manager.connections[
self.session.id]['cache']
self.render("jetpack:chat/demo.html", messages=cache)
class ChatSocketHandler(firenado.core.websocket.TornadoWebSocketHandler, JetpackHandler):
示例3: setdefaultencoding
from glob import glob
from os.path import splitext, basename, join as pjoin
from optparse import OptionParser
from urllib import urlopen
import sleekxmpp
# Python versions before 3.0 do not use UTF-8 encoding
# by default. To ensure that Unicode is handled properly
# throughout SleekXMPP, we will set the default encoding
# ourselves to UTF-8.
if sys.version_info < (3, 0):
from sleekxmpp.util.misc_ops import setdefaultencoding
setdefaultencoding("utf8")
else:
raw_input = input
from sleekxmpp.plugins.xep_0323.device import Device
# from sleekxmpp.exceptions import IqError, IqTimeout
class IoT_TestDevice(sleekxmpp.ClientXMPP):
"""
A simple IoT device that can act as server or client
"""
def __init__(self, jid, password):