Пример #1
0
 def DoQuote(include_mode, quote_file, for_post):
     if (quote_file == ""):
         return ""
     if (include_mode == 'N'):
         return "\n"
     quser = ""
     result = ""
     with open(quote_file, "rb") as inf:
         buf = Post.SkipAttachFgets(inf)
         match_user = re.match('[^:]*: *(.*\))[^)]*$', buf)
         if (match_user):
             quser = match_user.group(1)
         if (include_mode != 'R'):
             if (for_post):
                 result = result + (u"\n【 在 %s 的大作中提到: 】\n".encode('gbk') %
                                    quser)
             else:
                 result = result + (u"\n【 在 %s 的来信中提到: 】\n".encode('gbk') %
                                    quser)
         if (include_mode == 'A'):
             while (True):
                 buf = Post.SkipAttachFgets(inf)
                 if (buf == ""): break
                 result += ": %s" % buf
         else:
             # skip header
             while (True):
                 buf = Post.SkipAttachFgets(inf)
                 if (buf == "" or buf[0] == '\n'): break
             if (include_mode == 'R'):
                 while (True):
                     buf = Post.SkipAttachFgets(inf)
                     if (buf == ""): break
                     if (not Post.IsOriginLine(buf)):
                         result += buf
             else:
                 line_count = 0
                 while (True):
                     buf = Post.SkipAttachFgets(inf)
                     if (buf == "" or buf == "--\n"): break
                     if (len(buf) > 250):
                         buf = Util.CutLine(buf, 250) + "\n"
                     if (not Post.IsGarbageLine(buf)):
                         result += ": %s" % buf
                         if (include_mode == 'S'):
                             line_count += 1
                             if (line_count >= Config.QUOTED_LINES):
                                 result += ": ..................."
                                 break
     result += "\n"
     return result
Пример #2
0
    def DoQuote(include_mode, quote_file, for_post, include_data=None):
        """ Quote modes:
            R: full text
            C: full text, add comment
            N: empty
            S: short quote, limited lines
            A: full quote
            """

        if (quote_file == ""):
            return ""
        if (include_mode == 'N'):
            return "\n"
        quser = ""
        result = ""
        with open(quote_file, "rb") as inf:
            buf = Post.SkipAttachFgets(inf)
            match_user = re.match('[^:]*: *(.*\))[^)]*$', buf)
            if (match_user):
                quser = match_user.group(1)
            if include_mode != 'R' and include_mode != 'C':
                if (for_post):
                    result = result + (u"\n【 在 %s 的大作中提到: 】\n".encode('gbk') %
                                       quser)
                else:
                    result = result + (u"\n【 在 %s 的来信中提到: 】\n".encode('gbk') %
                                       quser)
            if (include_mode == 'A'):
                while (True):
                    buf = Post.SkipAttachFgets(inf)
                    if (buf == ""):
                        break
                    result += ": %s" % buf
            else:
                # skip header
                while (True):
                    buf = Post.SkipAttachFgets(inf)
                    if (buf == "" or buf[0] == '\n'):
                        break
                if include_mode == 'R':
                    while (True):
                        buf = Post.SkipAttachFgets(inf)
                        if (buf == ""):
                            break
                        if (not Post.IsOriginLine(buf)):
                            result += buf
                elif include_mode == 'C':
                    while True:
                        buf = Post.SkipAttachFgets(inf)
                        if buf == "" or buf == "--\n":
                            break
                        if not Post.IsOriginLine(buf):
                            result += buf
                else:
                    line_count = 0
                    while (True):
                        buf = Post.SkipAttachFgets(inf)
                        if (buf == "" or buf == "--\n"):
                            break
                        if (len(buf) > 250):
                            buf = Util.CutLine(buf, 250) + "\n"
                        if (not Post.IsGarbageLine(buf)):
                            result += ": %s" % buf
                            if (include_mode == 'S'):
                                line_count += 1
                                if (line_count >= Config.QUOTED_LINES):
                                    result += ": ..................."
                                    break
        if include_mode == 'C' and include_data is not None:
            result += Util.gbkEnc(include_data['comment'])
        result += "\n"
        return result