#!/usr/bin/env python3 """Strip dead USDC quote/open paths from options_register.py.""" from __future__ import annotations from pathlib import Path P = Path(__file__).resolve().parents[1] / "lib" / "options" / "options_register.py" text = P.read_text(encoding="utf-8") MARKER_Q = 'return jsonify({"ok": False, "msg": f"币本位报价失败: {e}"})' MARKER_O = 'return jsonify({"ok": False, "msg": f"币本位开仓失败: {e}"})' ROUTE_OPEN = ' @app.route("/api/options/open", methods=["POST"])' ROUTE_PENDING = ' @app.route("/api/options/orders/pending")' iq = text.find(MARKER_Q) io = text.find(MARKER_O) i_open = text.find(ROUTE_OPEN) i_pending = text.find(ROUTE_PENDING) if min(iq, io, i_open, i_pending) < 0: raise SystemExit(f"anchors missing q={iq} o={io} open={i_open} pending={i_pending}") # after quote coin except → reject; drop USDC quote body q_end = text.find("\n", iq) + 1 new_q = ( text[:q_end] + "\n return jsonify({\"ok\": False, \"msg\": \"CoinOX 仅支持币本位期权\"})\n\n" + text[i_open:] ) # recompute open anchors on new text io = new_q.find(MARKER_O) i_pending = new_q.find(ROUTE_PENDING) o_end = new_q.find("\n", io) + 1 new_text = ( new_q[:o_end] + "\n return jsonify({\"ok\": False, \"msg\": \"CoinOX 仅支持币本位期权\"})\n\n" + new_q[i_pending:] ) # Replace convert + spot swap handlers with 410 stubs (keep route names for old UI) import re def stub_route(src: str, route_sig: str, stub_body: str) -> str: m = re.search( rf"( @app\.route\({re.escape(route_sig)}.*?\)\n @lr\n def \w+\(.*?\):\n)", src, flags=re.S, ) if not m: print("warn: route not found", route_sig) return src start = m.end() # find next route at same indent n = re.search(r"\n @app\.route\(", src[start:]) end = start + n.start() + 1 if n else len(src) return src[:start] + stub_body + src[end:] stub = ' return jsonify({"ok": False, "msg": "CoinOX 已移除 USDC 兑换"}), 410\n\n' for sig in ('"/api/options/convert/quote", methods=["POST"]', '"/api/options/convert/execute", methods=["POST"]', '"/api/options/spot/swap", methods=["POST"]'): new_text = stub_route(new_text, sig, stub) # transfer default USDC -> USDT new_text = new_text.replace( 'ccy = (data.get("ccy") or "USDC").upper()', 'ccy = (data.get("ccy") or "USDT").upper()', ) P.write_text(new_text, encoding="utf-8") print("updated", P) print("size", len(text), "->", len(new_text))