def cable_page_by_id(reference_id):
    """\
    Experimental: Returns the HTML page of the cable identified by `reference_id`.

    >>> cable_page_by_id('09BERLIN1167') is not None
    True
    >>> cable_page_by_id('22BERLIN1167') is None
    True
    >>> cable_page_by_id('09MOSCOW3010') is not None
    True
    >>> cable_page_by_id('10MADRID87') is not None
    True
    >>> cable_page_by_id('10MUSCAT103') is not None
    True
    """
    global _CABLEID2MONTH
    def wikileaks_id(reference_id):
        if reference_id in consts.INVALID_CABLE_IDS.values():
            for k, v in consts.INVALID_CABLE_IDS.iteritems():
                if v == reference_id:
                    return k
        return reference_id

    def wikileaks_url(wl_id):
        m = _CABLEID2MONTH.get(wl_id)
        if m is None:
            return None
        y = wl_id[:2]
        y = u'19' + y if int(y) > 10 else u'20' + y
        return u'https://wikileaks.org/cable/%s/%s/%s' % (y, m.zfill(2), wl_id)

    if _CABLEID2MONTH is None:
        with gzip.open(os.path.join(os.path.dirname(__file__), 'cable2month.csv.gz'), 'r') as f:
            reader = csv.reader(f)
            _CABLEID2MONTH = dict(reader)
    wl_id = wikileaks_id(reference_id)
    wl_url = wikileaks_url(wl_id)
    if wl_url is None:
        # The cable reference is not known, try to consult Cablegatesearch.
        html = _fetch_url(_CGSN_BASE + wl_id)
        m = _CGSN_WL_SOURCE_SEARCH(html)
        wl_url = m.group(1) if m else None
    if wl_url is None:
        return None
    return _fetch_url(wl_url)
def cable_page_by_id ( reference_id ) : global _CABLEID2MONTH def wikileaks_id ( reference_id ) : if reference_id in consts . INVALID_CABLE_IDS . values ( ) : for k , v in consts . INVALID_CABLE_IDS . iteritems ( ) : if v == reference_id : return k return reference_id def wikileaks_url ( wl_id ) : m = _CABLEID2MONTH . get ( wl_id ) if m is None : return None y = wl_id [ : 2 ] y = u'19' + y if int ( y ) > 10 else u'20' + y return u'https://wikileaks.org/cable/%s/%s/%s' % ( y , m . zfill ( 2 ) , wl_id ) if _CABLEID2MONTH is None : with gzip . open ( os . path . join ( os . path . dirname ( __file__ ) , 'cable2month.csv.gz' ) , 'r' ) as f : reader = csv . reader ( f ) _CABLEID2MONTH = dict ( reader ) wl_id = wikileaks_id ( reference_id ) wl_url = wikileaks_url ( wl_id ) if wl_url is None : html = _fetch_url ( _CGSN_BASE + wl_id ) m = _CGSN_WL_SOURCE_SEARCH ( html ) wl_url = m . group ( 1 ) if m else None if wl_url is None : return None return _fetch_url ( wl_url )
\
    Experimental: Returns the HTML page of the cable identified by `reference_id`.

    >>> cable_page_by_id('09BERLIN1167') is not None
    True
    >>> cable_page_by_id('22BERLIN1167') is None
    True
    >>> cable_page_by_id('09MOSCOW3010') is not None
    True
    >>> cable_page_by_id('10MADRID87') is not None
    True
    >>> cable_page_by_id('10MUSCAT103') is not None
    True