本文整理匯總了Python中Files.add_editor方法的典型用法代碼示例。如果您正苦於以下問題:Python Files.add_editor方法的具體用法?Python Files.add_editor怎麽用?Python Files.add_editor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Files
的用法示例。
在下文中一共展示了Files.add_editor方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: tcp_link
# 需要導入模塊: import Files [as 別名]
# 或者: from Files import add_editor [as 別名]
def tcp_link(skt, addr):
print('Accept new connection from %s:%s...' % addr)
# sock.send(b'Welcome!')
data = ''
login = 0
upload_filename = ''
while True:
if not skt:
break
data = data + skt.recv(1024)
# time.sleep(1)
if not data or data.decode('utf-8') == 'exit':
break
# sendToAll(skt, data)
# data = ''
while True:
try:
pos = data.index('\n')
except:
break
print [data[:pos]]
msg = json.loads(data[:pos])
reply = dict()
query = msg['type']
reply['type'] = query
if query == 'register':
error = Users.insert_user(msg['user'], msg['password'])
reply['error'] = error
send(skt, json.dumps(reply))
elif query == 'login':
username = msg['name']
u = Users.get_user(username)
if len(u) < 2:
error = 1
elif u[2] != hash(msg['password']):
error = 1
else:
error = 0
login = 1
onlineList.append(skt)
name_list[skt] = username
reply['error'] = error
send(skt, json.dumps(reply))
elif login == 0:
continue
if query == 'logout':
login = 0
onlineList.remove(skt)
break
elif query == 'create':
filename = msg['filename']
error = Files.create_file(filename)
reply['error'] = error
if error == 0:
Auth.change(filename, name_list[skt], 2, name_list[skt])
send(skt, json.dumps(reply))
elif query == 'edit':
filename = msg['filename']
if not Files.exist(filename):
reply['error'] = 1
send(skt, json.dumps(reply))
continue
if not Auth.have_edit_auth(filename, name_list[skt]):
reply['error'] = 2
send(skt, json.dumps(reply))
continue
reply['error'] = 0
send(skt, json.dumps(reply))
reply.clear()
reply['type'] = 'edit_content'
reply['filename'] = 'filename'
reply['isend'] = 1
content = dict()
content['oldRange'] = {'start': {'row': 0, 'column': 0}, 'end': {'row': 0, 'column': 0}}
content['oldText'] = ''
(file_content, r, c) = Files.edit_file(filename)
content['newText'] = file_content
content['newRange'] = {'start': {'row': 0, 'column': 0}, 'end': {'row': r, 'column': c}}
reply['content'] = content
send(skt, json.dump(reply))
Files.add_editor(filename, skt)
elif query == 'upload':
filename = msg['filename']
error = Files.create_file(filename)
reply['error'] = error
send(skt, json.dumps(reply))
if error == 1:
continue
upload_filename = filename
Auth.change(filename, name_list[sock], 2, name_list[skt])
#.........這裏部分代碼省略.........
示例2: tcp_link
# 需要導入模塊: import Files [as 別名]
# 或者: from Files import add_editor [as 別名]
def tcp_link(skt, addr):
syn_time = time.time()
# try:
print('Accept new connection from %s:%s...' % addr)
global cnt
cnt += 1
data = ''
login = 0
while True:
if not skt:
break
data = data + skt.recv(1024)
# time.sleep(1)
if not data or data.decode('utf-8') == 'exit':
break
# sendToAll(skt, data)
# data = ''
while True:
try:
pos = data.index('\n')
except:
break
# print [data[:pos]]
msg = json.loads(data[:pos])
data = data[pos + 1:]
reply = dict()
query = msg['type']
reply['type'] = query
# if msg['type'] == 'modify':
# print msg['newText']
if query == 'login':
pwd = msg['pwd']
if pwd != host_pwd:
error = 1
else:
error = 0
login = 1
online_list.append(skt)
Files.add_editor(host_filename, skt)
reply['content'] = Files.edit_file(host_filename)
reply['error'] = error
send(skt, json.dumps(reply))
elif login == 0:
continue
if query == 'logout':
login = 0
break
elif query == 'modify':
modify = msg
print modify
filename = host_filename
# print Files.editing[host_filename]
send_to_all(skt, json.dumps(msg), host_filename)
print '=========================='
print Files.edit_file(host_filename)
Files.change_file(filename, modify)
print '====>'
print Files.edit_file(host_filename)
print '=========================='
elif query == 'move':
msg['id'] = cnt
send_to_all(skt, json.dumps(msg), host_filename)
# now = time.time()
# if now - syn_time > 5:
# print 'syn'
# syn_time = now
# reply = dict()
# reply['type'] = 'syn'
# reply['content'] = Files.edit_file(host_filename)
# send(skt, json.dumps(reply))
save_all()
Files.del_editor(host_filename, skt)
online_list.remove(skt)
skt.close()
del lock[skt]
print('Connection from %s:%s closed.' % addr)