当前位置: 首页>>代码示例>>Python>>正文


Python static.File方法代码示例

本文整理汇总了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
## 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:bm35protocol.py

示例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
## -------------------- 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:palmacqprotocol.py

示例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
## -------------------- 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:kernprotocol.py

示例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") 
开发者ID:geomagpy,项目名称:magpy,代码行数:18,代码来源:callprotocol.py

示例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
## -------------------- 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:arduinoprotocol.py

示例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
## -------------------- 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:envprotocol.py

示例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") 
开发者ID:geomagpy,项目名称:magpy,代码行数:18,代码来源:owprotocol.py

示例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") 
开发者ID:geomagpy,项目名称:magpy,代码行数:20,代码来源:cobs_ws_protocols.py

示例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
## 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:csprotocol.py

示例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
## 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:gsm19protocol.py

示例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
## ------------- 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:pos1protocol.py

示例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
## 
开发者ID:geomagpy,项目名称:magpy,代码行数:24,代码来源:gsmp20protocol.py

示例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)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:19,代码来源:test_tap.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:20,代码来源:test_static.py

示例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 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:22,代码来源:test_static.py


注:本文中的twisted.web.static.File方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。