Parse the '227' response for a PASV request. Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)' Return ('host.addr.as.numbers', port#) tuple.
(resp)
| 832 | _227_re = None |
| 833 | |
| 834 | def parse227(resp): |
| 835 | '''Parse the '227' response for a PASV request. |
| 836 | Raises error_proto if it does not contain '(h1,h2,h3,h4,p1,p2)' |
| 837 | Return ('host.addr.as.numbers', port#) tuple.''' |
| 838 | if resp[:3] != '227': |
| 839 | raise error_reply(resp) |
| 840 | global _227_re |
| 841 | if _227_re is None: |
| 842 | import re |
| 843 | _227_re = re.compile(r'(\d+),(\d+),(\d+),(\d+),(\d+),(\d+)', re.ASCII) |
| 844 | m = _227_re.search(resp) |
| 845 | if not m: |
| 846 | raise error_proto(resp) |
| 847 | numbers = m.groups() |
| 848 | host = '.'.join(numbers[:4]) |
| 849 | port = (int(numbers[4]) << 8) + int(numbers[5]) |
| 850 | return host, port |
| 851 | |
| 852 | |
| 853 | def parse229(resp, peer): |
no test coverage detected