Skip to content
Snippets Groups Projects
Commit f296d6d1 authored by Konstantin Shulgin's avatar Konstantin Shulgin
Browse files

Blueprint 'Test memcached mode of box':

Write method in the MemcachedConnection class was overlapped for correct
work with memcached protocols. Memcached tests was cleanupped.
parent e69838a1
No related branches found
No related tags found
No related merge requests found
import socket
import struct
import sys
import re
from tarantool_connection import TarantoolConnection
......@@ -25,17 +26,34 @@ class MemcachedCommandBuffer:
class MemcachedConnection(TarantoolConnection):
def write(self, fragment):
"""This is to support print >> admin, "command" syntax.
For every print statement, write is invoked twice: one to
write the command itself, and another to write \n. We should
accumulate all writes until we receive \n. When we receive it,
we execute the command, and rewind the stream."""
self.stream.write(fragment)
statement = self.stream.getvalue()
sys.stdout.write(statement)
if fragment != '\n':
# execute only commands
sys.stdout.write(self.execute(statement))
self.stream.seek(0)
self.stream.truncate()
def execute_no_reconnect(self, commands, silent = True):
self.send_commands(commands, silent)
return self.recv_reply(silent)
self.send(commands, silent)
return self.recv(silent)
def send_commands(self, commands, silent = True):
def send(self, commands, silent = True):
self.commands = commands
self.socket.sendall(commands + MEMCACHED_SEPARATOR)
self.socket.sendall(commands)
if not silent:
print self.commands
def recv_reply(self, silent = True):
def recv(self, silent = True):
self.recv_buffer = ''
self.command_buffer = MemcachedCommandBuffer(self.commands)
self.reply = ''
......
......@@ -15,7 +15,7 @@ def tarantool_translate(readline):
if type == tokenize.NAME and name == "exec":
next_token = next(token_stream)
type, name = next_token[:2]
if type == tokenize.NAME and name in [ "sql", "admin", "memcached"]:
if type == tokenize.NAME and name in [ "sql", "admin", "memcached" ]:
yield (tokenize.NAME, 'print') + token[2:]
yield (tokenize.OP, '>>') + token[2:]
yield next_token
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment