本文整理汇总了Python中twisted.web.static.File方法的典型用法代码示例。如果您正苦于以下问题:Python static.File方法的具体用法?Python static.File怎么用?Python static.File使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.static
的用法示例。
在下文中一共展示了static.File方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("Protocol: Error while saving file")
## meteolabor BM35 protocol
##
示例2: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("PalmAcq - Protocol: Error while saving file")
## PalmAcq protocol
## --------------------
示例3: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("KERN - Protocol: Error while saving file")
## Environment protocol
## --------------------
示例4: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(self, sensorid, filedate, bindata, header):
# File Operations
try:
path = os.path.join(self.outputdir,self.hostname,sensorid)
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("SERIAL - datatofile: Error while saving file")
示例5: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("Arduino - Protocol: Error while saving file")
## Arduino protocol
## --------------------
示例6: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("OW - Protocol: Error while saving file")
## Environment protocol
## --------------------
示例7: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(self, sensorid, filedate, bindata, header):
# File Operations
try:
path = os.path.join(self.outputdir,self.hostname,sensorid)
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("OW - datatofile: Error while saving file")
示例8: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(sensorid, filedate, bindata, header):
# File Operations
try:
subdirname = socket.gethostname()
path = os.path.join(outputdir,subdirname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("OW - Protocol: Error while saving file")
示例9: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("OW - Protocol: Error while saving file")
## Caesium protocol
##
示例10: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("Protocol: Error while saving file")
## GEM -GSM19 protocol
##
示例11: _dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def _dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("OW - Protocol: Error while saving file")
## POS1 protocol
## -------------
示例12: dataToFile
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def dataToFile(outputdir, sensorid, filedate, bindata, header):
# File Operations
try:
hostname = socket.gethostname()
path = os.path.join(outputdir,hostname,sensorid)
# outputdir defined in main options class
if not os.path.exists(path):
os.makedirs(path)
savefile = os.path.join(path, sensorid+'_'+filedate+".bin")
if not os.path.isfile(savefile):
with open(savefile, "wb") as myfile:
myfile.write(header + "\n")
myfile.write(bindata + "\n")
else:
with open(savefile, "a") as myfile:
myfile.write(bindata + "\n")
except:
log.err("GSMP20 - Protocol: Error while saving file")
## GEM -GSMP-20S3 protocol -- North-South
##
示例13: test_pathServer
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def test_pathServer(self):
"""
The I{--path} option to L{makeService} causes it to return a service
which will listen on the server address given by the I{--port} option.
"""
path = FilePath(self.mktemp())
path.makedirs()
port = self.mktemp()
options = Options()
options.parseOptions(['--port', 'unix:' + port, '--path', path.path])
service = makeService(options)
service.startService()
self.addCleanup(service.stopService)
self.assertIsInstance(service.services[0].factory.resource, File)
self.assertEqual(service.services[0].factory.resource.path, path.path)
self.assertTrue(os.path.exists(port))
self.assertTrue(stat.S_ISSOCK(os.stat(port).st_mode))
示例14: test_securityViolationNotFound
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def test_securityViolationNotFound(self):
"""
If a request is made which encounters a L{File} before a final segment
which cannot be looked up in the filesystem due to security
considerations, a not found response is sent.
"""
base = FilePath(self.mktemp())
base.makedirs()
file = static.File(base.path)
request = DummyRequest([b'..'])
child = resource.getChildForRequest(file, request)
d = self._render(child, request)
def cbRendered(ignored):
self.assertEqual(request.responseCode, 404)
d.addCallback(cbRendered)
return d
示例15: test_forbiddenResource
# 需要导入模块: from twisted.web import static [as 别名]
# 或者: from twisted.web.static import File [as 别名]
def test_forbiddenResource(self):
"""
If the file in the filesystem which would satisfy a request cannot be
read, L{File.render} sets the HTTP response code to I{FORBIDDEN}.
"""
base = FilePath(self.mktemp())
base.setContent(b'')
# Make sure we can delete the file later.
self.addCleanup(base.chmod, 0o700)
# Get rid of our own read permission.
base.chmod(0)
file = static.File(base.path)
request = DummyRequest([b''])
d = self._render(file, request)
def cbRendered(ignored):
self.assertEqual(request.responseCode, 403)
d.addCallback(cbRendered)
return d