本文整理汇总了Python中FileSync.put_file方法的典型用法代码示例。如果您正苦于以下问题:Python FileSync.put_file方法的具体用法?Python FileSync.put_file怎么用?Python FileSync.put_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FileSync
的用法示例。
在下文中一共展示了FileSync.put_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: import FileSync [as 别名]
# 或者: from FileSync import put_file [as 别名]
print "Num Msg Parts: %d" % num_msg_parts
break
print "Message Header: %s" % msg_header
print "Message Body: %s" % msg_body
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, '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 != '':
示例2: run
# 需要导入模块: import FileSync [as 别名]
# 或者: from FileSync import put_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"