feature/handle-python-exceptions #5
					 1 changed files with 10 additions and 6 deletions
				
			
		|  | @ -63,16 +63,16 @@ def parse_command_line(argv): | |||
|     try: | ||||
|         opts, args = getopt.getopt(argv, "f:") | ||||
|     except getopt.GetoptError as e: | ||||
|         raise LookupException("Error parsing command line") from e | ||||
|         raise LookupException("Error parsing command line. Usage: geoip-lookup.py -f /path/to/geoip2-database.mmdb 192.168.1.1") from e | ||||
| 
 | ||||
|     for opt, arg in opts: | ||||
|         if opt == "-f": | ||||
|             dbfile = arg | ||||
|         else: | ||||
|             raise LookupException("Unknown command line argument") | ||||
|             raise LookupException("Unknown command line argument. Usage: geoip-lookup.py -f /path/to/geoip2-database.mmdb 192.168.1.1") | ||||
| 
 | ||||
|     if len(args) == 0: | ||||
|         raise LookupException("No address given on command line") | ||||
|         raise LookupException("No address given on command line. Usage: geoip-lookup.py -f /path/to/geoip2-database.mmdb 192.168.1.1") | ||||
|     return dbfile, args[0] | ||||
| 
 | ||||
| 
 | ||||
|  | @ -83,9 +83,13 @@ def main(argv): | |||
|     :param argv: Format: "-f /path/to/database.mmdb ip.v4.add.ress" | ||||
|     :return: | ||||
|     """ | ||||
|     try | ||||
|         (dbfile, ipaddress) = parse_command_line(argv) | ||||
|         code = get_county_code(ipaddress, dbfile) | ||||
|         print(code) | ||||
|     except LookupException as e: | ||||
|         print(e, file=sys.stderr) | ||||
|         print("Unknown") | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue