示例#1
0
    def reflowed(self, width):
        """ Return a reflowed-for-width copy of the buffer as a list. """
        reflowed_buffer = []

        for raw_line in self:
            reflowed_buffer.append([])
            line_length = 0
            line = raw_line[:]
            line.reverse()  # reverse the line so we can use it as a stack
            while len(line) > 0:
                block = line.pop()
                try:  # attempt to consider possibly different unicode length vs. ascii length
                    block_len = len(block[0].encode(
                        sys.getfilesystemencoding()))
                except:
                    block_len = len(block)
                if (block_len + line_length) > width:
                    split_point = helpers.find_split_point(
                        block[0], width - line_length)
                    reflowed_buffer[-1].append(
                        (block[0][:split_point],
                         block[1]))  # add the first half of the block as usual
                    reflowed_buffer.append([])
                    line.append(
                        (block[0][split_point:], block[1]
                         ))  # put the rest of the block back on the stack
                    line_length = 0
                else:
                    reflowed_buffer[-1].append(block)
                    line_length += block_len

        return reflowed_buffer
示例#2
0
    def reflowed(self, width):
        """ Return a reflowed-for-width copy of the buffer as a list. """
        reflowed_buffer = []

        for raw_line in self:
            reflowed_buffer.append([])
            line_length = 0
            line = raw_line[:]
            line.reverse()  # reverse the line so we can use it as a stack
            while len(line) > 0:
                block = line.pop()
                try:  # attempt to consider possibly different unicode length vs. ascii length
                    block_len = len(block[0].encode(sys.getfilesystemencoding()))
                except:
                    block_len = len(block)
                if line_length < block[2]:  # block would be to the left of its min x offset
                    line_length = block[2]
                if (block_len + line_length) > width:
                    split_point = helpers.find_split_point(block[0], width - line_length)
                    reflowed_buffer[-1].append((block[0][:split_point], block[1], block[2]))  # add the first half of the block as usual
                    reflowed_buffer.append([])
                    line.append((block[0][split_point:], block[1], block[2]))  # put the rest of the block back on the stack
                    line_length = 0
                else:
                    reflowed_buffer[-1].append(block)
                    line_length += block_len

        return reflowed_buffer
示例#3
0
 def statuses_update(self, status, source="", in_reply_to_status_id=0, latitude=-200, longitude=-200, place_id="", display_coordinates=False, long_dent="split", dup_first_word=False):
     print "called"
     status = "".join([s.strip(" ") for s in status.split("\n")])  # rejoin split lines back to 1 line
     params = {'status':status}
     if not (source == ""):
         params['source'] = source
     if not (in_reply_to_status_id == 0):
         params['in_reply_to_status_id'] = in_reply_to_status_id
     if not (latitude == -200):
         params['lat'] = latitude
     if not (longitude == -200):
         params['long'] = longitude
     if not (place_id == ""):
         params['place_id'] = place_id
     if display_coordinates:
         params['display_coordinates'] = "true"
     if len(status) > self.length_limit and self.length_limit != 0:
         if long_dent=="truncate":
             params['status'] = status[:self.length_limit]
         elif long_dent=="split":
             status_next = status[helpers.find_split_point(status, self.length_limit - 3):]
             status = status.encode('utf-8')[:helpers.find_split_point(status, self.length_limit - 3)] + u".."
             if dup_first_word or (not (in_reply_to_status_id == 0)):
                 status_next = status.split(" ")[0].encode('utf-8') + " .. " + status_next
             else:
                 status_next = ".. " + status_next
             params['status'] = status
             dents = [self.__makerequest("statuses/update", params)] # post the first piece as normal
             next_dent = self.statuses_update(status_next, source=source, in_reply_to_status_id=dents[-1]["id"], latitude=latitude, longitude=longitude, place_id=place_id, display_coordinates=display_coordinates, long_dent=long_dent) # then hand the rest off for potential further splitting
             if isinstance(next_dent, list):
                 for dent in next_dent:
                     dents.append(dent)
             else:
                 dents.append(next_dent)
         else:
             raise Exception("Maximum status length exceeded by %d characters." % (len(status) - self.length_limit))
     return self.__makerequest("statuses/update", params)
示例#4
0
 def statuses_update(self, status, source="", in_reply_to_status_id=0, latitude=-200, longitude=-200, place_id="", display_coordinates=False, long_dent="split", dup_first_word=False):
     status = "".join([s.strip(" ") for s in status.split("\n")])  # rejoin split lines back to 1 line
     params = {'status':status}
     if not (source == ""):
         params['source'] = source
     if not (in_reply_to_status_id == 0):
         params['in_reply_to_status_id'] = in_reply_to_status_id
     if not (latitude == -200):
         params['lat'] = latitude
     if not (longitude == -200):
         params['long'] = longitude
     if not (place_id == ""):
         params['place_id'] = place_id
     if display_coordinates:
         params['display_coordinates'] = "true"
     if len(status) > self.length_limit and self.length_limit != 0:
         if long_dent=="truncate":
             params['status'] = status[:self.length_limit]
         elif long_dent=="split":
             status_next = status[helpers.find_split_point(status, self.length_limit - 3):]
             status = status.encode('utf-8')[:helpers.find_split_point(status, self.length_limit - 3)] + u".."
             if dup_first_word or (not (in_reply_to_status_id == 0)):
                 status_next = status.split(" ")[0].encode('utf-8') + " .. " + status_next
             else:
                 status_next = ".. " + status_next
             params['status'] = status
             dents = [self.__makerequest("statuses/update", params)] # post the first piece as normal
             next_dent = self.statuses_update(status_next, source=source, in_reply_to_status_id=dents[-1]["id"], latitude=latitude, longitude=longitude, place_id=place_id, display_coordinates=display_coordinates, long_dent=long_dent) # then hand the rest off for potential further splitting
             if isinstance(next_dent, list):
                 for dent in next_dent:
                     dents.append(dent)
             else:
                 dents.append(next_dent)
         else:
             raise Exception("Maximum status length exceeded by %d characters." % (len(status) - self.length_limit))
     return self.__makerequest("statuses/update", params)