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


Python FileSync.get_file方法代码示例

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


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

示例1:

# 需要导入模块: import FileSync [as 别名]
# 或者: from FileSync import get_file [as 别名]
                 fullpath = './static/data/' + request_path
                 response_code = FileSync.put_file(fullpath, 'text/plain', msg_body)
                 client_sock.send('HTTP/1.1 ' + response_code + '\n')
                 files_received += 1
             elif request_type == "GET":
                 
                 fullpath = './static/data/' + request_path
                 if os.path.isdir(fullpath):
                     file_list = FileSync.get_file_list(fullpath)
                     response_body = ''
                     for file_name in file_list:
                         response_body += file_name + '\n'
                     client_sock.send('HTTP/1.1 ' + '200 OK' + '\n\n')
                     client_sock.send(response_body + '\n')
                 else:
                     response_body = FileSync.get_file(fullpath)
                     if response_body != '':
                         client_sock.send('HTTP/1.1 ' + '200 OK' + '\n\n')
                         client_sock.send(response_body + '\n\n')
                     else:
                         client_sock.send('HTTP/1.1 ' + '404 Not Found' + '\n\n')
                             
             print "Request Complete\n"
 
             
     except IOError:
         pass
 
     print "disconnected"
 
     client_sock.close()
开发者ID:mbhoude,项目名称:ScoutingAppCentral,代码行数:33,代码来源:ScoutingAppMain.py

示例2: run

# 需要导入模块: import FileSync [as 别名]
# 或者: from FileSync import get_file [as 别名]
 def run(self):
     server_sock=BluetoothSocket( RFCOMM )
     server_sock.bind(("",PORT_ANY))
     server_sock.listen(1)
     
     port = server_sock.getsockname()[1]
     
     uuid = "00001073-0000-1000-8000-00805F9B34F7"
     
     advertise_service( server_sock, "TTTService",
                        service_id = uuid,
                        service_classes = [ uuid, SERIAL_PORT_CLASS ],
                        profiles = [ SERIAL_PORT_PROFILE ] )
                        
     while not self.shutdown:
         
         print "Waiting for connection on RFCOMM channel %d" % port
     
         client_sock, client_info = server_sock.accept()
         print "Accepted connection from ", client_info
 
         files_received = 0
     
         try:
             while True:                  
                 msg_header, msg_body, content_type = self.read_request( client_sock )
                 if len(msg_header) == 0:
                     break
                 
                 print "Message Header: %s" % msg_header
                 print "Message Body Length: %d" % len(msg_body)
                     
                 msg_header_lines = msg_header.splitlines()
                 request_type, request_path = msg_header_lines[0].split(' ',1)
                 
                 print "Request Type: %s" % request_type
                 print "Request Path: %s" % request_path
                 
                 if request_type == "PUT":
                     fullpath = './static/data/' + request_path
                     response_code = FileSync.put_file(fullpath, content_type, msg_body)
                     client_sock.send('HTTP/1.1 ' + response_code + '\r\n')
                     files_received += 1
                 elif request_type == "GET":
                     
                     fullpath = './static/data/' + request_path
                     
                     if os.path.isdir(fullpath):
                         file_list = FileSync.get_file_list(fullpath)
                         response_body = ''
                         for file_name in file_list:
                             response_body += file_name + '\n'
                         client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n')
                         client_sock.send('Content-Length: %d\r\n' % len(response_body))
                         client_sock.send('\r\n')
                         client_sock.send(response_body + '\r\n')
                     else:
                         response_body = FileSync.get_file(fullpath)
                         if response_body != '':
                             client_sock.send('HTTP/1.1 ' + '200 OK' + '\r\n')
                             client_sock.send('Content-Length: %d\r\n' % len(response_body))
                             client_sock.send('\r\n')
                             client_sock.send(response_body + '\r\n')
                         else:
                             client_sock.send('HTTP/1.1 ' + '404 Not Found' + '\r\n\r\n')
                                 
                 print "Request Complete\n"
      
         except IOError:
             pass
     
         print "disconnected"
     
         client_sock.close()
         
     server_sock.close()
     print "Bluetooth Sync Server Terminated"
开发者ID:mbhoude,项目名称:ScoutingAppCentral,代码行数:79,代码来源:BluetoothSyncServer.py


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