<s> import socket <EOL> import argparse <EOL> import re <EOL> class RegexMatch ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pattern , statement = None ) : <EOL> self . string_pattern = pattern <EOL> self . pattern = re . compile ( pattern ) <EOL> self . statement = statement <EOL> if not self . statement : <EOL> self . statement = "<STR_LIT>" % self . string_pattern <EOL> def __call__ ( self , string ) : <EOL> match = self . pattern . search ( string ) <EOL> if match : <EOL> raise argparse . ArgumentError ( None , self . statement ) <EOL> return string <EOL> class Hostname ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , _socket = None ) : <EOL> self . socket = _socket or socket <EOL> def __call__ ( self , string ) : <EOL> parts = string . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> name = parts [ <NUM_LIT:0> ] <EOL> host = parts [ - <NUM_LIT:1> ] <EOL> try : <EOL> self . socket . getaddrinfo ( host , <NUM_LIT:0> ) <EOL> except self . socket . gaierror : <EOL> msg = "<STR_LIT>" % host <EOL> raise argparse . ArgumentError ( None , msg ) <EOL> try : <EOL> self . socket . getaddrinfo ( name , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , self . socket . AI_NUMERICHOST ) <EOL> except self . socket . gaierror : <EOL> return string <EOL> else : <EOL> msg = '<STR_LIT>' % name <EOL> raise argparse . ArgumentError ( None , msg ) <EOL> return string <EOL> class Subnet ( object ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , string ) : <EOL> ip = string . split ( '<STR_LIT:/>' ) [ <NUM_LIT:0> ] <EOL> ip_parts = ip . split ( '<STR_LIT:.>' ) <EOL> if len ( ip_parts ) != <NUM_LIT:4> : <EOL> err = "<STR_LIT>" % string <EOL> raise argparse . ArgumentError ( None , err ) <EOL> if [ i for i in ip_parts [ : <NUM_LIT:4> ] if i . isalpha ( ) ] : <EOL> err = "<STR_LIT>" % string <EOL> raise argparse . ArgumentError ( None , err ) <EOL> if len ( string . split ( '<STR_LIT:/>' ) ) != <NUM_LIT:2> : <EOL> err = "<STR_LIT>" % string <EOL> raise argparse . ArgumentError ( None , err ) <EOL> return string </s>
