# Copyright 2015 Abhijit Menon-Sen # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type import re from ansible.errors import AnsibleParserError, AnsibleError # Components that match a numeric or alphanumeric begin:end or begin:end:step # range expression inside square brackets. numeric_range = r''' \[ (?:[0-9]+:[0-9]+) # numeric begin:end (?::[0-9]+)? # numeric :step (optional) \] ''' hexadecimal_range = r''' \[ (?:[0-9a-f]+:[0-9a-f]+) # hexadecimal begin:end (?::[0-9]+)? # numeric :step (optional) \] ''' alphanumeric_range = r''' \[ (?: [a-z]:[a-z]| # one-char alphabetic range [0-9]+:[0-9]+ # ...or a numeric one ) (?::[0-9]+)? # numeric :step (optional) \] ''' # Components that match a 16-bit portion of an IPv6 address in hexadecimal # notation (0..ffff) or an 8-bit portion of an IPv4 address in decimal notation # (0..255) or an [x:y(:z)] numeric range. ipv6_component = r''' (?: [0-9a-f]{{1,4}}| # 0..ffff {range} # or a numeric range ) '''.format(range=hexadecimal_range) ipv4_component = r''' (?: [01]?[0-9]{{1,2}}| # 0..199 2[0-4][0-9]| # 200..249 25[0-5]| # 250..255 {range} # or a numeric range ) '''.format(range=numeric_range) # A hostname label, e.g. 'foo' in 'foo.example.com'. Consists of alphanumeric # characters plus dashes (and underscores) or valid ranges. The label may not # start or end with a hyphen or an underscore. This is interpolated into the # hostname pattern below. We don't try to enforce the 63-char length limit. label = r''' (?:[\w]|{range}) # Starts with an alphanumeric or a range (?:[\w_-]|{range})* # Then zero or more of the same or [_-] (?