Parse the '229' response for an EPSV request. Raises error_proto if it does not contain '(|||port|)' Return ('host.addr.as.numbers', port#) tuple.
(resp, peer)
| 851 | |
| 852 | |
| 853 | def parse229(resp, peer): |
| 854 | '''Parse the '229' response for an EPSV request. |
| 855 | Raises error_proto if it does not contain '(|||port|)' |
| 856 | Return ('host.addr.as.numbers', port#) tuple.''' |
| 857 | if resp[:3] != '229': |
| 858 | raise error_reply(resp) |
| 859 | left = resp.find('(') |
| 860 | if left < 0: raise error_proto(resp) |
| 861 | right = resp.find(')', left + 1) |
| 862 | if right < 0: |
| 863 | raise error_proto(resp) # should contain '(|||port|)' |
| 864 | if resp[left + 1] != resp[right - 1]: |
| 865 | raise error_proto(resp) |
| 866 | parts = resp[left + 1:right].split(resp[left+1]) |
| 867 | if len(parts) != 5: |
| 868 | raise error_proto(resp) |
| 869 | host = peer[0] |
| 870 | port = int(parts[3]) |
| 871 | return host, port |
| 872 | |
| 873 | |
| 874 | def parse257(resp): |
no test coverage detected