履修申請を取り消す

def unregister_course (self, course_id):
        """ 履修申請を取り消す """
        course_id = course_id.upper()

        # 何モジュール開講か取得
        kdb = twins.kdb.Kdb()
        first_module = kdb.get_course_info(course_id)["modules"][:2]
        if not first_module.startswith("春") and \
           not first_module.startswith("秋"):
            raise RequestError()
        module_code, gakkiKbnCode = {
                                      "春A": (1, "A"),
                                      "春B": (2, "A"),
                                      "春C": (3, "A"),
                                      "秋A": (4, "B"),
                                      "秋B": (5, "B"),
                                      "秋C": (6, "B")
                                    }.get(first_module)

        # 履修登録照会画面から時限、曜日とかを取り出す
        courses = {}
        self.req("RSW0001000-flow")
        r = self.get({
                       "_eventId":   "search",
                       "moduleCode": module_code,
                       "gakkiKbnCode": gakkiKbnCode
                     })

        for js_args in re.findall("DeleteCallA\(([\'\ \,A-Z0-9]+)\)", r.text):
            js_args = js_args.replace("'", "").split(",")
            if js_args[2] in courses:
                continue  # 1-2限,2-3限など、連続してあるやつ
            courses[js_args[2]] = {
                                    "yobi":  js_args[3],
                                    "jigen": js_args[4],
                                    "nendo": js_args[0],
                                    "jikanwariShozokuCode": js_args[1]
                                  }

        if course_id not in courses:
            raise RequestError()

        r = self.post({
                        "_eventId": "delete",
                        "yobi":     courses[course_id]["yobi"],
                        "jigen":    courses[course_id]["jigen"],
                        "nendo":    courses[course_id]["nendo"],
                        "jikanwariShozokuCode": courses[course_id]
                                                  ["jikanwariShozokuCode"],
                        "jikanwariCode": course_id,
                      }, True)

        r = self.post({"_eventId": "delete"}, True)

        errmsg = pq(r.text)(".error").text()
        if errmsg != "":
            raise RequestError()