Revision 25942a6c lib/luxi.py

b/lib/luxi.py
122 122

  
123 123
  """
124 124

  
125
  def __init__(self, address, timeouts=None, eom=None):
125
  def __init__(self, address, timeouts=None):
126 126
    """Constructor for the Client class.
127 127

  
128 128
    Arguments:
129 129
      - address: a valid address the the used transport class
130 130
      - timeout: a list of timeouts, to be used on connect and read/write
131
      - eom: an identifier to be used as end-of-message which the
132
        upper-layer will guarantee that this identifier will not appear
133
        in any message
134 131

  
135 132
    There are two timeouts used since we might want to wait for a long
136 133
    time for a response, but the connect timeout should be lower.
......
153 150
    self._buffer = ""
154 151
    self._msgs = collections.deque()
155 152

  
156
    if eom is None:
157
      self.eom = '\3'
158
    else:
159
      self.eom = eom
160

  
161 153
    try:
162 154
      self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
163 155

  
......
203 195
    This just sends a message and doesn't wait for the response.
204 196

  
205 197
    """
206
    if self.eom in msg:
198
    if constants.LUXI_EOM in msg:
207 199
      raise EncodingError("Message terminator found in payload")
208 200
    self._CheckSocket()
209 201
    try:
210 202
      # TODO: sendall is not guaranteed to send everything
211
      self.socket.sendall(msg + self.eom)
203
      self.socket.sendall(msg + constants.LUXI_EOM)
212 204
    except socket.timeout, err:
213 205
      raise TimeoutError("Sending timeout: %s" % str(err))
214 206

  
......
238 230
        break
239 231
      if not data:
240 232
        raise ConnectionClosedError("Connection closed while reading")
241
      new_msgs = (self._buffer + data).split(self.eom)
233
      new_msgs = (self._buffer + data).split(constants.LUXI_EOM)
242 234
      self._buffer = new_msgs.pop()
243 235
      self._msgs.extend(new_msgs)
244 236
    return self._msgs.popleft()

Also available in: Unified diff