View | Details | Raw Unified | Return to bug 25463 | Differences between
and this patch

Collapse All | Expand All

(-)modules/univention/admin/syntax.py (-4 / +27 lines)
 Lines 1081-1094    Link Here 
1081
	choices = ( ( 'ethernet', _( 'Ethernet' ) ), ( 'fddi', _( 'FDDI' ) ), ( 'token-ring', _( 'Token-Ring' ) ) )
1081
	choices = ( ( 'ethernet', _( 'Ethernet' ) ), ( 'fddi', _( 'FDDI' ) ), ( 'token-ring', _( 'Token-Ring' ) ) )
1082
1082
1083
class MAC_Address( simple ):
1083
class MAC_Address( simple ):
1084
	regex = re.compile( '^([0-9a-fA-F]{1,2}[:-]){5}[0-9a-fA-F]{1,2}$' )
1084
	regexFormats = {
1085
	error_message = _( 'This is not a valid MAC address. It must have 6 two digit hexadecimal numbers separated by \"-\" or \":\"' )
1085
		'linuxFormat' : '^([0-9a-fA-F]{2}:){5}[0-9a-fA-F]{2}$', # linux format
1086
		'windowsFormat' :'^([0-9a-fA-F]{2}-){5}[0-9a-fA-F]{2}$', # windows format
1087
		'rawFormat' : '^[0-9a-fA-F]{12}$', # raw format
1088
		'ciscoFormat' : '^([0-9a-fA-F]{4}.){2}[0-9a-fA-F]{4}$', # cisco format
1089
	}
1090
	regexLinuxFormat = re.compile( regexFormats['linuxFormat'] )
1091
	regexWindowsFormat = re.compile( regexFormats['windowsFormat'] )
1092
	regexRawFormat = re.compile( regexFormats['rawFormat'] )
1093
	regexCiscoFormat = re.compile( regexFormats['ciscoFormat'] )
1094
	error_message = _( 'That is not a valid MAC address.' )
1086
	size = 'TwoThirds'
1095
	size = 'TwoThirds'
1087
1096
1088
	@classmethod
1097
	@classmethod
1089
	def parse( self, text ):
1098
	def parse( self, text ):
1090
		simple.parse( text )
1099
		if self.regexLinuxFormat.match(text) is not None:
1091
		return text.replace( '-', ':' ).lower()
1100
			return  text.lower()
1101
		elif self.regexWindowsFormat.match(text) is not None:
1102
			return  text.replace('-', ':').lower()
1103
		elif self.regexRawFormat.match(text) is not None:
1104
			temp = []
1105
			for i in range(0, len(text)-1, 2):
1106
				temp.append(text[i:i+2])
1107
			return ':'.join(temp).lower()
1108
		elif self.regexCiscoFormat.match(text) is not None:
1109
			temp = []
1110
			for i in range(0, len(text.translate(None, '.'))-1, 2):
1111
				temp.append(text.translate(None, '.')[i:i+2])
1112
			return ':'.join(temp).lower()
1113
		else:
1114
			raise univention.admin.uexceptions.valueError( self.error_message )
1092
1115
1093
class DHCP_HardwareAddress( complex ):
1116
class DHCP_HardwareAddress( complex ):
1094
	subsyntaxes = ( ( _( 'Type' ), NetworkType ), ( _( 'Address' ), MAC_Address ) )
1117
	subsyntaxes = ( ( _( 'Type' ), NetworkType ), ( _( 'Address' ), MAC_Address ) )

Return to bug 25463