def parse_tags(content, reference_id=None, canonicalize=True):
    """\
    Returns the TAGS of a cable.
    
    Acc. to the U.S. SD every cable needs at least one tag.

    `content`
        The content of the cable.
    `reference_id`
        The reference identifier of the cable.
    `canonicalize`
        Indicates if duplicates should be removed and malformed
        TAGs like "ECONEFIN" should be corrected (becomes "ECON", "EFIN").
        ``False`` indicates that the TAGs should be returned as found in
        cable.
    """
    max_idx = _MAX_HEADER_IDX
    m = _SUBJECT_MAX_PATTERN.search(content)
    if m:
        max_idx = m.start()
    m = _SUBJECT_PATTERN.search(content, 0, max_idx)
    if m:
        max_idx = min(max_idx, m.start())
    m = _TAGS_PATTERN.search(content, 0, max_idx)
    if not m:
        if reference_id not in _CABLES_WITHOUT_TAGS:
            logger.debug('No TAGS found in cable ID "%r", content: "%s"' % (reference_id, content))
        return []
    tags = _TAGS_CLEANUP_PATTERN.sub(u' ', m.group(1))
    min_idx = m.end()
    if tags.endswith(',') or tags.endswith(', ') or _TAGS_CONT_NEXT_LINE_PATTERN.match(content, min_idx, max_idx):
        m2 = _TAGS_CONT_PATTERN.match(content, m.end(), max_idx)
        if m2:
            tags = re.sub(ur'\s+', u' ', u' '.join([tags, _TAGS_CLEANUP_PATTERN.sub(u' ', m2.group(1))]))
    res = []
    if not canonicalize:
        return [u''.join(tag).upper() for tag in _TAG_PATTERN.findall(tags) if tag]
    for t in _TAG_PATTERN.findall(tags):
        tag = u''.join(t).upper().replace(u')', u'').replace(u'(', u'')
        if tag == u'SIPDIS':  # Found in 05OTTAWA3726 and 05OTTAWA3709. I think it's an error
            continue
        for tag in _TAG_FIXES.get(tag, (tag,)):
            if tag == u'ECONSOCIXR':  # 08BRASILIA1504
                for tag in _TAG_FIXES[tag]:
                    if not tag in res:
                        res.append(tag)
                continue
            if not tag in res:
                res.append(tag)
    return res
def parse_tags ( content , reference_id = None , canonicalize = True ) : max_idx = _MAX_HEADER_IDX m = _SUBJECT_MAX_PATTERN . search ( content ) if m : max_idx = m . start ( ) m = _SUBJECT_PATTERN . search ( content , 0 , max_idx ) if m : max_idx = min ( max_idx , m . start ( ) ) m = _TAGS_PATTERN . search ( content , 0 , max_idx ) if not m : if reference_id not in _CABLES_WITHOUT_TAGS : logger . debug ( 'No TAGS found in cable ID "%r", content: "%s"' % ( reference_id , content ) ) return [ ] tags = _TAGS_CLEANUP_PATTERN . sub ( u' ' , m . group ( 1 ) ) min_idx = m . end ( ) if tags . endswith ( ',' ) or tags . endswith ( ', ' ) or _TAGS_CONT_NEXT_LINE_PATTERN . match ( content , min_idx , max_idx ) : m2 = _TAGS_CONT_PATTERN . match ( content , m . end ( ) , max_idx ) if m2 : tags = re . sub ( ur '\s+' , u' ' , u' ' . join ( [ tags , _TAGS_CLEANUP_PATTERN . sub ( u' ' , m2 . group ( 1 ) ) ] ) ) res = [ ] if not canonicalize : return [ u'' . join ( tag ) . upper ( ) for tag in _TAG_PATTERN . findall ( tags ) if tag ] for t in _TAG_PATTERN . findall ( tags ) : tag = u'' . join ( t ) . upper ( ) . replace ( u')' , u'' ) . replace ( u'(' , u'' ) if tag == u'SIPDIS' : continue for tag in _TAG_FIXES . get ( tag , ( tag , ) ) : if tag == u'ECONSOCIXR' : for tag in _TAG_FIXES [ tag ] : if not tag in res : res . append ( tag ) continue if not tag in res : res . append ( tag ) return res
\
    Returns the TAGS of a cable.
    
    Acc. to the U.S. SD every cable needs at least one tag.

    `content`
        The content of the cable.
    `reference_id`
        The reference identifier of the cable.
    `canonicalize`
        Indicates if duplicates should be removed and malformed
        TAGs like "ECONEFIN" should be corrected (becomes "ECON", "EFIN").
        ``False`` indicates that the TAGs should be returned as found in
        cable.