1 # Copyright (C) 2006 by Aiwota Programmer
2 # aiwotaprog@tetteke.tk
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 from bbs_type_exception import BbsTypeError
25 subject_reg_expr = re.compile("(?P<id>.*).dat<>(?P<title>.*)\((?P<res>\d*)\)")
26 dat_reg_expr = re.compile("(?P<name>.*)<>(?P<mail>.*)<>(?P<date>.*)<>(?P<msg>.*)<>(?P<title>.*)")
30 """Base of bbs type. Do not instantiate directly"""
35 subject_reg = subject_reg_expr
36 dat_reg = dat_reg_expr
39 def __init__(self, uri):
47 def _parse_uri(self, uri):
49 m = self._base_reg.match(self.uri)
51 self.host = m.group("host")
52 self.board = m.group("board")
54 m = self._cgi_reg.match(self.uri)
56 self.host = m.group("host")
57 self.board = m.group("board")
58 self.thread = m.group("thread")
61 "the uri %s does not represent %s" \
62 % (self.uri, self.bbs_type)
65 return not self.thread
70 def is_same_board(self, another):
71 return self.bbs_type == another.bbs_type \
72 and self.host == another.host \
73 and self.board == another.board
75 def clone_with_thread(self, thread):
77 raise ValueError, "parameter must not be empty"
78 another = copy.copy(self)
79 another.thread = thread
80 another.uri = another.get_thread_uri()
83 def get_uri_base(self):
84 return "http://" + self.host + "/" + self.board + "/"
86 def get_subject_txt_uri(self):
87 return self.get_uri_base() + "subject.txt"
89 def get_dat_uri(self):
91 raise BbsTypeError, "not specified thread"
92 return self.get_uri_base() + "dat/" + self.thread + ".dat"
94 def get_thread_uri(self):
96 raise BbsTypeError, "not specified thread"
97 return "http://" + self.host + "/test/read.cgi/" + \
98 self.board + "/" + self.thread + "/"
100 def get_post_uri(self):
101 return "http://" + self.host + "/test/bbs.cgi"
103 def build_post_dict(self, name, mail, msg):
105 post_dict["bbs"] = self.board
106 post_dict["key"] = self.thread
107 post_dict["time"] = str(int(time.time()))
108 post_dict["submit"] = u"\u66f8\u304d\u8fbc\u3080".encode(
110 post_dict["FROM"] = name.encode("cp932", "replace")
111 post_dict["mail"] = mail.encode("cp932", "replace")
112 post_dict["MESSAGE"] = msg.encode("cp932", "replace")
115 def set_extra_post(self, post_dict):
118 def set_extra_dat_request(self, request, thread):
121 def get_title_from_dat(self, line):
123 line = line.decode(self.encoding, "replace")
124 m = self.dat_reg.match(line)
126 return m.group("title")
129 def get_board_dir_path(self):
130 """Returns board dir path from logs dir downward, not full path"""
132 return self.bbs_type + "/" + self.host + "/" + self.board