Exemple #1
0
class RecvMessage:
  def __init__(self, messageheader):
    self.messageheader = messageheader
    self.id = self.messageheader.id
    self.buffer = Buffer()
    self.received = -1
    self.completed = False
    self.message = ""
    self.mime = messageheader.mime
    self.name = messageheader.name

  def feed(self, frame):
    if frame.id != self.messageheader.id:
      return False
    
    if self.received >= self.messageheader.parts:
      return False
    
    self.received += 1

    self.buffer.write(str(buffer(frame.message, 0, frame.length)))
    
    if self.received == self.messageheader.parts:
      self.completed = True
      self.message = self.buffer.read()
      
      f = open('/tmp/%s'%(self.name), 'w')
      f.write(self.message)
      f.close()
      
      del self.buffer
    
    return True
Exemple #2
0
class SendMessage:
  PART_SIZE = 2**15
  
  def __init__(self, message, mime, name):
    self.id = uuid.uuid1().hex
    self.length = len(message)
    self.parts = self.length / self.PART_SIZE
    self.sent = -1
    self.buffer = Buffer()
    self.buffer.write(message)
    self.mime = mime
    self.name = name
  
  def getHead(self):
    return frames.MessageHead(id=self.id, length=self.length, parts=self.parts, mime=self.mime, name=self.name)
  
  def getPart(self):
    if self.sent >= self.parts:
      return None
    
    self.sent += 1
    
    if self.buffer.has(self.PART_SIZE):
      length = self.PART_SIZE
      data = self.buffer.read(self.PART_SIZE);
    else:
      length = self.buffer.size
      data = self.buffer.read();
    
    return frames.MessagePart(id=self.id, part=self.sent, message=data, length=length)
Exemple #3
0
 def __init__(self, messageheader):
   self.messageheader = messageheader
   self.id = self.messageheader.id
   self.buffer = Buffer()
   self.received = -1
   self.completed = False
   self.message = ""
   self.mime = messageheader.mime
   self.name = messageheader.name
Exemple #4
0
 def __init__(self, message, mime, name):
   self.id = uuid.uuid1().hex
   self.length = len(message)
   self.parts = self.length / self.PART_SIZE
   self.sent = -1
   self.buffer = Buffer()
   self.buffer.write(message)
   self.mime = mime
   self.name = name