本文整理汇总了Python中connection.Connection.write方法的典型用法代码示例。如果您正苦于以下问题:Python Connection.write方法的具体用法?Python Connection.write怎么用?Python Connection.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类connection.Connection
的用法示例。
在下文中一共展示了Connection.write方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import write [as 别名]
def handle(self):
connection = Connection(self.request)
command = connection.read(1)
if command == "l":
list(connection)
else:
sys.stderr.write("bad command: " + repr(command) + "\n")
connection.write(b"b")
connection.write_string("you suck")
示例2: Sensor
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import write [as 别名]
#.........这里部分代码省略.........
try:
# print 'Sensor.__getattr__(%s)' % name
attr = self._connection.read(object.__getattribute__(self, "_attrs")[name])
except:
raise AttributeError, name
return attr
def __setattr__(self, name, value):
"""
Set the value of a sensor attribute. This is accomplished by
first determining if the physical sensor has the named
attribute. If it does, then the value is written to the
name. Otherwise, the Sensor's dictionary is updated with the
name and value.
Usage:
s = ownet.Sensor('/1F.5D0B01000000')
s.PIO_1 = '1'
will set the value of PIO.1 to 1.
"""
# print 'Sensor.__setattr__(%s, %s)' % (name, value)
# Life can get tricky when using __setattr__. Self doesn't
# have an _attrs atribute when it's initially created. _attrs
# is only there after it's been set in __init__. So we can
# only reference it if it's already been added.
if hasattr(self, "_attrs"):
if name in self._attrs:
self._connection.write(self._attrs[name], value)
else:
self.__dict__[name] = value
else:
self.__dict__[name] = value
def useCache(self, use_cache):
"""
Set the sensor to use the underlying owfs cache (or not)
depending on the use_cache parameter.
Usage:
s = ownet.Sensor('/1F.5D0B01000000')
s.useCache(False)
will set the internal sensor path to /uncached/1F.5D0B01000000.
Also:
s = ownet.Sensor('/uncached/1F.5D0B01000000')
s.useCache(True)
will set the internal sensor path to /1F.5D0B01000000.
"""
# print 'Sensor.useCache(%s)' % str(use_cache)
self._useCache = use_cache
if self._useCache:
self._usePath = self._path
else:
if self._path == "/":
self._usePath = "/uncached"
示例3: Request
# 需要导入模块: from connection import Connection [as 别名]
# 或者: from connection.Connection import write [as 别名]
class Request(object):
def __init__(self):
self.subprocess_env = []
self.uri = get_request_header("uri")
self.headers_in = {}
self.ap_auth_type = None
self.clength = 0
self.content_type = get_request_header("Content-Type")
self.path_info = self.uri
self.args = get_request_header("opts")
self.connection = Connection()
self.user = ""
self.method = get_request_header("cmd")
self.server = Server()
self.headers_out = {}
self.next = None
self.prev = None
self.main = None
self.the_request = self.method + " " + self.uri + " HTTP/1.1"
self.protocol = "HTTP"
self.__headers_sent = False
self.assbackwards = False
self.proxyreq = False
self.header_only = False
self.proto_num = 1001
self.hostname = ""
self.request_time = 0
self.status_line = "200 OK"
self.status = ""
self.method_number = 0
self.allowed = 0
self.allowed_xmethods = 0
self.allowed_methods = 0
self.sent_bodyct = 0
self.bytes_sent = 0
self.mtime = 0
self.chunked = False
self.range = ""
self.remaining = 0
self.read_length = 0
self.read_body = 1
self.read_chunked = False
self.expecting_100 = False
self.err_headers_out = {}
self.notes = None
self.phase = 0
self.interpreter = "python"
self.content_languages = []
self.handler = ""
self.content_encoding = ""
self.vlist_validator = 0
self.no_cache = True
self.no_local_copy = True
self.unparsed_uri = ""
self.filename = ""
self.canonical_filename = ""
self.finfo = None
self.parsed_uri = {}
self.used_path_info = ""
self.eos_sent = False
self.__cleanups = ()
self.__allowed = ()
def get_cleanups(self):
return self.__cleanups
def send_headers(self):
if len(self.__allowed) > 0:
set_response_header("Allowed", self.__allowed)
send_header()
def write(self, str, flush=False):
if not self.__headers_sent:
self.send_headers()
self.__headers_sent = True
ret = self.connection.write(str)
if flush:
self.flush()
return ret
def add_common_vars(self):
self.subprocess_env = []
def add_handler(self, type, handler, *dir):
pass
def add_input_filter(self, filter_name):
pass
def add_output_filter(self, filter_name):
pass
def allow_methods(self, methods, reset=False):
if reset:
self.__allowed = methods
else:
self.__allowed = self.__allowed + ", " + methods
#.........这里部分代码省略.........