def fieldgetter(*fieldspecs):
    """
    Similar to `valuegetter`, except this returns (`pymarc.Field`, value)
    tuples. Takes any number of fieldspecs.
    """
    pattern = r'(?P<field>[^.]+)(.(?P<subfield>[^.]+))?'

    def fields(record):
        for s in fieldspecs:
            match = re.match(pattern, s)
            if not match:
                continue
            grp = match.groupdict()
            for field in record.get_fields(grp['field']):
                if grp['subfield']:
                    for value in field.get_subfields(grp['subfield']):
                        yield field, value
                else:
                    if int(grp['field']) < 10:
                        yield field, field.value()
                    else:
                        for value in field.subfields[1::2]:
                            yield field, value
    fields.__doc__ = 'returns a field generator over %s' % (
        ', '.join(fieldspecs))
    return fields
def fieldgetter ( * fieldspecs ) : pattern = r'(?P<field>[^.]+)(.(?P<subfield>[^.]+))?' def fields ( record ) : for s in fieldspecs : match = re . match ( pattern , s ) if not match : continue grp = match . groupdict ( ) for field in record . get_fields ( grp [ 'field' ] ) : if grp [ 'subfield' ] : for value in field . get_subfields ( grp [ 'subfield' ] ) : yield field , value else : if int ( grp [ 'field' ] ) < 10 : yield field , field . value ( ) else : for value in field . subfields [ 1 : : 2 ] : yield field , value fields . __doc__ = 'returns a field generator over %s' % ( ', ' . join ( fieldspecs ) ) return fields
Similar to `valuegetter`, except this returns (`pymarc.Field`, value)
    tuples. Takes any number of fieldspecs.