From 2918f5f233606b12ddf15e547e2b891c06071440 Mon Sep 17 00:00:00 2001 From: Aiwota Programmer Date: Thu, 14 Sep 2006 12:12:05 +0900 Subject: [PATCH] Uri matching looser. --- src/FukuiNoNamari/BbsType/bbs_type_2ch.py | 2 +- src/FukuiNoNamari/BbsType/bbs_type_jbbs.py | 2 +- src/FukuiNoNamari/BbsType/bbs_type_other.py | 19 +++++++++++++++++-- src/FukuiNoNamari/BbsType/bbs_type_yy.py | 2 +- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/FukuiNoNamari/BbsType/bbs_type_2ch.py b/src/FukuiNoNamari/BbsType/bbs_type_2ch.py index d9916a0..88f9c5a 100644 --- a/src/FukuiNoNamari/BbsType/bbs_type_2ch.py +++ b/src/FukuiNoNamari/BbsType/bbs_type_2ch.py @@ -24,7 +24,7 @@ from bbs_type_base import BaseType # default name for morningcoffee moco_name = u'\u540d\u7121\u3057\u52df\u96c6\u4e2d\u3002\u3002\u3002' -_base_reg_expr = re.compile("http://(?P[^./]+\.2ch\.net)/(?P[^/]+)/$") +_base_reg_expr = re.compile("http://(?P[^./]+\.2ch\.net)/(?P[^/]+)(?:/[^/]*){0,1}$") _cgi_reg_expr = re.compile("http://(?P[^./]+\.2ch\.net)/test/read.cgi/(?P[^/]+)/(?P[^/]+)/.*") diff --git a/src/FukuiNoNamari/BbsType/bbs_type_jbbs.py b/src/FukuiNoNamari/BbsType/bbs_type_jbbs.py index bc0252e..53841ec 100644 --- a/src/FukuiNoNamari/BbsType/bbs_type_jbbs.py +++ b/src/FukuiNoNamari/BbsType/bbs_type_jbbs.py @@ -22,7 +22,7 @@ import time from bbs_type_exception import BbsTypeError from bbs_type_base import BaseType -_base_reg_expr = re.compile("http://(?Pjbbs\.livedoor\.jp)/(?P(?P[^/]+)/(?P[^/]+))/$") +_base_reg_expr = re.compile("http://(?Pjbbs\.livedoor\.jp)/(?P(?P[^/]+)/(?P[^/]+))(?:/[^/]*){0,1}$") _cgi_reg_expr = re.compile("http://(?Pjbbs\.livedoor\.jp)/bbs/read\.cgi/(?P(?P[^/]+)/(?P[^/]+))/(?P[^/]+)/.*") subject_reg_expr = re.compile("(?P.*)\.cgi,(?P.*)\((?P<res>\d*)\)") dat_reg_expr = re.compile("(?P<num>\d+)<>(?P<name>.*)<>(?P<mail>.*)<>(?P<date>.*)<>(?P<msg>.*)<>(?P<title>.*)<>(?P<id>.*)") diff --git a/src/FukuiNoNamari/BbsType/bbs_type_other.py b/src/FukuiNoNamari/BbsType/bbs_type_other.py index f821505..0725adc 100644 --- a/src/FukuiNoNamari/BbsType/bbs_type_other.py +++ b/src/FukuiNoNamari/BbsType/bbs_type_other.py @@ -31,7 +31,7 @@ try: except IOError: traceback.print_exc() -_board_reg_expr = re.compile("http://(?P<host>.+)/(?P<board>[^/]+)/$") +_board_reg_expr = re.compile("http://(?P<host>.+)/(?P<board>[^/]+)(?:/[^/]*){0,1}$") class TypeOther(BaseType): @@ -39,12 +39,27 @@ class TypeOther(BaseType): _board_reg = _board_reg_expr def _parse_uri(self, uri): + + def uri_base_match(uri, iru): + iru = iru.rstrip("/") + if uri.startswith(iru): + uri = uri[len(iru):] + if not uri: + return True + elif uri[0] == "/": + uri = uri[1:] + if not uri: + return True + elif uri.find("/") == -1: + return True + return False + for iru in _whitelist: match = self._board_reg.match(iru) if match: host = match.group("host") board = match.group("board") - if uri == iru: + if uri_base_match(uri, "http://%s/%s" % (host, board)): self.host = host self.board = board return diff --git a/src/FukuiNoNamari/BbsType/bbs_type_yy.py b/src/FukuiNoNamari/BbsType/bbs_type_yy.py index 68f3aa5..f2e8861 100644 --- a/src/FukuiNoNamari/BbsType/bbs_type_yy.py +++ b/src/FukuiNoNamari/BbsType/bbs_type_yy.py @@ -19,7 +19,7 @@ import re from bbs_type_2ch import BaseType -_base_reg_expr = re.compile("http://(?P<host>yy\d{2}\.(?:kakiko\.com|60\.kg))/(?P<board>[^/]+)/$") +_base_reg_expr = re.compile("http://(?P<host>yy\d{2}\.(?:kakiko\.com|60\.kg))/(?P<board>[^/]+)(?:/[^/]*){0,1}$") _cgi_reg_expr = re.compile("http://(?P<host>yy\d{2}\.(?:kakiko\.com|60\.kg))/test/read.cgi/(?P<board>[^/]+)/(?P<thread>[^/]+)/.*") -- 2.11.0