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


Python Session.startTransfer方法代码示例

本文整理汇总了Python中session.Session.startTransfer方法的典型用法代码示例。如果您正苦于以下问题:Python Session.startTransfer方法的具体用法?Python Session.startTransfer怎么用?Python Session.startTransfer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在session.Session的用法示例。


在下文中一共展示了Session.startTransfer方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SessionTestCase

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import startTransfer [as 别名]
class SessionTestCase(unittest.TestCase):
    
    def setUp(self):
        self.fileName = os.path.join(os.path.expanduser("~"), "teiler/test/test.txt")
        self.address = '127.0.0.1'
        self.port = 8989
        self.config = FakeConfig()
        self.teilerWindow = FakeTeilerWindow()
        self.receiverConfig = FakeConfig()
        self.session = Session(self.fileName, self.config, self.address, self.port)
        
        factory = FileReceiverFactory(self.config, self.teilerWindow)
        self.receiverProto = factory.buildProtocol((self.address, self.port))
        self.tr = proto_helpers.StringTransport()
        self.receiverProto.makeConnection(self.tr)
    
    def test_startTransfer(self):
        self.session.startTransfer()
        self.assertEqual(self.tr.value(), "{\"sessionID\": \"" + self.session.id + "\", \"command\": \"BEGIN\", \"fileName\": \"" + self.fileName + "\"}")
    
    '''     
    def test_processResponse(self):
        self.fail()
        
        log.msg("Response received: {0}".format(msg))
        message = json.loads(msg)
        if message['command'] == acceptMsg and self.status == 1:
            self.status = 2
            reactor.callLater(0, self.startFileSend)
        elif message['command'] == rejectMsg and self.status == 1:
            log.msg("File transfer was rejected.  Closing.")
        elif message['command'] == receivedMsg and self.status == 2:
            log.msg("Receipt from receiver")
            reactor.callLater(0, self.processTransferQueue)
        else:
            log.msg("NOT RECOGNIZED!")  
        '''
    
    '''    
    def test_sendBeginning(self):
        self.fail()
        
        beginMessage = Message(beginMsg, self.id)
        beginMessage.fileName = self.fileName
        log.msg("Sending BEGIN")
        log.msg("Message is {0}".format(beginMsg))
        f = SessionMessageFactory(self, beginMessage)
        self.status = 1
        reactor.connectTCP(self.address, self.port, f)
        '''
    
    '''    
    def test_sendEnd(self):
        self.fail()
        
        endMessage = Message(endMsg, self.id)
        log.msg("Sending EOT")
        f = SessionMessageFactory(endMessage)
        self.status = "finished"
        reactor.connectTCP(self.address, self.port, f)
        self.config.closeSession(self)
        '''
        
    '''
    def test_sendFile(self):
        self.fail()
        
        controller = type('test', (object,), {'cancel':False, 'total_sent':0, 'completed':Deferred()})
        f = FileSenderClientFactory(path, controller, self.id)
        reactor.connectTCP(address, port, f)
        return controller.completed
        '''
    
    '''    
    def test_startFileSend(self):
        self.fail()
       
            log.msg("Calculating files...")
            self.transferQueue.put(self.fileName)
            if os.path.isdir(self.fileName):
                for root, dirs, files in os.walk(self.fileName, topdown=True):
                    for name in dirs:
                        self.transferQueue.put(os.path.join(root, name))
                        log.msg("QUEUE: Adding dir {0}".format(name))
                    for name in files:
                        self.transferQueue.put(os.path.join(root, name))
                        log.msg("QUEUE: Adding file {0}".format(name))
                reactor.callLater(0, self.processTransferQueue)
       '''
    '''    
    def test_processTransferQueue(self):
        self.fail()
                remaining = self.transferQueue.qsize()
        log.msg("Processing queue.  Queue items remaining: {0}".format(remaining))
        if remaining == 0:
            endMessage = Message(endMsg, self.id)
            f = SessionMessageFactory(self, endMessage)
            reactor.connectTCP(self.address, self.port, f)
        else:
            path = self.transferQueue.get()
#.........这里部分代码省略.........
开发者ID:arminhammer,项目名称:teiler,代码行数:103,代码来源:test_session.py

示例2: sendFileToPeer

# 需要导入模块: from session import Session [as 别名]
# 或者: from session.Session import startTransfer [as 别名]
 def sendFileToPeer(self, fileName, peerID, peerAddress, peerPort):
     log.msg("File dropped {0}".format(fileName))
     session = Session(str(fileName), self.config, peerAddress, peerPort)
     self.config.sessions[str(session.id)] = session
     session.startTransfer()
开发者ID:arminhammer,项目名称:teiler,代码行数:7,代码来源:teiler.py


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