bluefile.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:core-framework 作者: RedhawkSDR 项目源码 文件源码
def pack_main_header_keywords(hdr):
    """
    Replace the 'keywords' field of the given BLUE header dictionary
    with the X-Midas packed (str) form of the main header keywords.
    The order of the key value pairs is indeterminate.

    In packed form, keys are separated from values by a single '=',
    key-value pairs are separated from one another by a single '\0'
    and all values are stringized using str(). Hence, each key value
    pair takes up keylength + stringized value length + 2 characters.
    If the resulting packed string is longer than the max allowed for
    the BLUE header main keywords (96 characters) the string is
    truncated.  If no 'keywords' field is present or if it is an empty
    dict, then the keyword fields are updated to represent an empty
    main header keywords section.
    """
    keydict = hdr.get('keywords', {})
    if keydict:
        hdr['keywords'] = '\0'.join([k + '=' + str(v)
                                     for k,v in keydict.items()]) + '\0'
        hdr['keylength'] = min(len(hdr['keywords']),
                               struct.calcsize(_bluestructs['HEADER']
                                               ['lookups']['keywords'][1]))
        if hdr['keylength'] < len(hdr['keywords']):
            print "WARNING: Main header keywords truncated"
    else:
        hdr['keywords'] = '\0'
        hdr['keylength'] = 0
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号