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
20 from bbs_type_exception import BbsTypeError
23 _base_reg_expr = re.compile("http://(?P<host>[^./]+\.2ch\.net)/(?P<board>[^/]+)/$")
24 _cgi_reg_expr = re.compile("http://(?P<host>[^./]+\.2ch\.net)/test/read.cgi/(?P<board>[^/]+)/(?P<thread>[^/]+)/.*")
29 def __init__(self, host=None, board=None, thread=None, uri=None):
33 if not host or not board:
34 raise BbsTypeError, "host and board, or uri must be specified"
40 def _parse_uri(self, uri):
47 m = _base_reg_expr.match(self.uri)
50 self.host = m.group("host")
51 self.board = m.group("board")
53 m = _cgi_reg_expr.match(self.uri)
56 self.host = m.group("host")
57 self.board = m.group("board")
58 self.thread = m.group("thread")
61 return not self.thread
66 def clone_with_thread(self, thread):
68 raise ValueError, "parameter must not be empty"
69 return Type2ch(self.host, self.board, thread)
71 def get_uri_base(self):
72 return "http://" + self.host + "/" + self.board + "/"
74 def get_subject_txt_uri(self):
75 return self.get_uri_base() + "subject.txt"
77 def get_dat_uri(self):
79 raise BbsTypeError, "not specified thread"
80 return self.get_uri_base() + "dat/" + self.thread + ".dat"
82 def get_thread_uri(self):
84 raise BbsTypeError, "not specified thread"
85 return "http://" + self.host + "/test/read.cgi/" + \
86 self.board + "/" + self.thread + "/"