Exemple #1
0
def validate_id(id_candidate, description="id", reporter=None):
    """
    Validate a pacemaker id, raise LibraryError on invalid id.

    id_candidate id's value
    description id's role description (default "id")
    """
    # see NCName definition
    # http://www.w3.org/TR/REC-xml-names/#NT-NCName
    # http://www.w3.org/TR/REC-xml/#NT-Name
    if len(id_candidate) < 1:
        report = reports.invalid_id_is_empty(id_candidate, description)
        if reporter:
            reporter.add(report)
            return
        else:
            raise LibraryError(report)
    if _ID_FIRST_CHAR_NOT_RE.match(id_candidate[0]):
        report = reports.invalid_id_bad_char(id_candidate, description,
                                             id_candidate[0], True)
        if reporter:
            reporter.add(report)
        else:
            raise LibraryError(report)
    for char in id_candidate[1:]:
        if _ID_REST_CHARS_NOT_RE.match(char):
            report = reports.invalid_id_bad_char(id_candidate, description,
                                                 char, False)
            if reporter:
                reporter.add(report)
            else:
                raise LibraryError(report)
Exemple #2
0
def validate_id(id_candidate, description="id", reporter=None):
    """
    Validate a pacemaker id, raise LibraryError on invalid id.

    id_candidate id's value
    description id's role description (default "id")
    """
    # see NCName definition
    # http://www.w3.org/TR/REC-xml-names/#NT-NCName
    # http://www.w3.org/TR/REC-xml/#NT-Name
    if not id_candidate:
        report = reports.invalid_id_is_empty(id_candidate, description)
        if reporter is None:
            # we check for None so it works with an empty list as well
            raise LibraryError(report)
        reporter.append(report)
        return
    if _ID_FIRST_CHAR_NOT_RE.match(id_candidate[0]):
        report = reports.invalid_id_bad_char(id_candidate, description,
                                             id_candidate[0], True)
        if reporter is not None:
            reporter.append(report)
        else:
            raise LibraryError(report)
    for char in id_candidate[1:]:
        if _ID_REST_CHARS_NOT_RE.match(char):
            report = reports.invalid_id_bad_char(id_candidate, description,
                                                 char, False)
            if reporter is not None:
                reporter.append(report)
            else:
                raise LibraryError(report)
Exemple #3
0
def validate_id(id_candidate, description="id", reporter=None):
    """
    Validate a pacemaker id, raise LibraryError on invalid id.

    id_candidate id's value
    description id's role description (default "id")
    """
    # see NCName definition
    # http://www.w3.org/TR/REC-xml-names/#NT-NCName
    # http://www.w3.org/TR/REC-xml/#NT-Name
    if len(id_candidate) < 1:
        report = reports.invalid_id_is_empty(id_candidate, description)
        if reporter:
            reporter.add(report)
            return
        else:
            raise LibraryError(report)
    if _ID_FIRST_CHAR_NOT_RE.match(id_candidate[0]):
        report = reports.invalid_id_bad_char(
            id_candidate, description, id_candidate[0], True
        )
        if reporter:
            reporter.add(report)
        else:
            raise LibraryError(report)
    for char in id_candidate[1:]:
        if _ID_REST_CHARS_NOT_RE.match(char):
            report = reports.invalid_id_bad_char(
                id_candidate, description, char, False
            )
            if reporter:
                reporter.add(report)
            else:
                raise LibraryError(report)
Exemple #4
0
def validate_id(id_candidate, description="id", reporter=None):
    """
    Validate a pacemaker id, raise LibraryError on invalid id.

    id_candidate id's value
    description id's role description (default "id")
    """
    # see NCName definition
    # http://www.w3.org/TR/REC-xml-names/#NT-NCName
    # http://www.w3.org/TR/REC-xml/#NT-Name
    if not id_candidate:
        report = reports.invalid_id_is_empty(id_candidate, description)
        if reporter is None:
            # we check for None so it works with an empty list as well
            raise LibraryError(report)
        reporter.append(report)
        return
    if _ID_FIRST_CHAR_NOT_RE.match(id_candidate[0]):
        report = reports.invalid_id_bad_char(
            id_candidate, description, id_candidate[0], True
        )
        if reporter is not None:
            reporter.append(report)
        else:
            raise LibraryError(report)
    for char in id_candidate[1:]:
        if _ID_REST_CHARS_NOT_RE.match(char):
            report = reports.invalid_id_bad_char(
                id_candidate, description, char, False
            )
            if reporter is not None:
                reporter.append(report)
            else:
                raise LibraryError(report)
Exemple #5
0
def validate_id(id_candidate, description="id"):
    """
    Validate a pacemaker id, raise LibraryError on invalid id.

    id_candidate id's value
    description id's role description (default "id")
    """
    # see NCName definition
    # http://www.w3.org/TR/REC-xml-names/#NT-NCName
    # http://www.w3.org/TR/REC-xml/#NT-Name
    if len(id_candidate) < 1:
        raise LibraryError(reports.invalid_id_is_empty(
            id_candidate, description
        ))
    first_char_re = re.compile("[a-zA-Z_]")
    if not first_char_re.match(id_candidate[0]):
        raise LibraryError(reports.invalid_id_bad_char(
            id_candidate, description, id_candidate[0], True
        ))
    char_re = re.compile("[a-zA-Z0-9_.-]")
    for char in id_candidate[1:]:
        if not char_re.match(char):
            raise LibraryError(reports.invalid_id_bad_char(
                id_candidate, description, char, False
            ))
Exemple #6
0
def validate_id(id_candidate, description="id"):
    """
    Validate a pacemaker id, raise LibraryError on invalid id.

    id_candidate id's value
    description id's role description (default "id")
    """
    # see NCName definition
    # http://www.w3.org/TR/REC-xml-names/#NT-NCName
    # http://www.w3.org/TR/REC-xml/#NT-Name
    if len(id_candidate) < 1:
        raise LibraryError(
            reports.invalid_id_is_empty(id_candidate, description))
    first_char_re = re.compile("[a-zA-Z_]")
    if not first_char_re.match(id_candidate[0]):
        raise LibraryError(
            reports.invalid_id_bad_char(id_candidate, description,
                                        id_candidate[0], True))
    char_re = re.compile("[a-zA-Z0-9_.-]")
    for char in id_candidate[1:]:
        if not char_re.match(char):
            raise LibraryError(
                reports.invalid_id_bad_char(id_candidate, description, char,
                                            False))