anyconfig/backend/properties.py
def load(stream, container=dict, comment_markers=_COMMENT_MARKERS):
    """
    Load and parse Java properties file given as a fiel or file-like object
    `stream`.

    :param stream: A file or file like object of Java properties files
    :param container:
        Factory function to create a dict-like object to store properties
    :param comment_markers: Comment markers, e.g. '#' (hash)
    :return: Dict-like object holding properties

    >>> to_strm = anyconfig.compat.StringIO
    >>> s0 = "calendar.japanese.type: LocalGregorianCalendar"
    >>> load(to_strm(''))
    {}
    >>> load(to_strm("# " + s0))
    {}
    >>> load(to_strm("! " + s0))
    {}
    >>> load(to_strm("calendar.japanese.type:"))
    {'calendar.japanese.type': ''}
    >>> load(to_strm(s0))
    {'calendar.japanese.type': 'LocalGregorianCalendar'}
    >>> load(to_strm(s0 + "# ..."))
    {'calendar.japanese.type': 'LocalGregorianCalendar# ...'}
    >>> s1 = r"key=a\\:b"
    >>> load(to_strm(s1))
    {'key': 'a:b'}
    >>> s2 = '''application/postscript: \\
    ...         x=Postscript File;y=.eps,.ps
    ... '''
    >>> load(to_strm(s2))
    {'application/postscript': 'x=Postscript File;y=.eps,.ps'}
    """
    ret = container()
    prev = ""

    for line in stream.readlines():
        line = _pre_process_line(prev + line.strip().rstrip(),
                                 comment_markers)
        # I don't think later case may happen but just in case.
        if line is None or not line:
            continue

        prev = ""  # re-initialize for later use.

        if line.endswith("\\"):
            prev += line.rstrip(" \\")
            continue

        (key, val) = _parseline(line)
        if key is None:
            LOGGER.warning("Failed to parse the line: %s", line)
            continue

        ret[key] = unescape(val)

    return ret

    Load and parse Java properties file given as a fiel or file-like object
    `stream`.

    :param stream: A file or file like object of Java properties files
    :param container:
        Factory function to create a dict-like object to store properties
    :param comment_markers: Comment markers, e.g. '#' (hash)
    :return: Dict-like object holding properties

    >>> to_strm = anyconfig.compat.StringIO
    >>> s0 = "calendar.japanese.type: LocalGregorianCalendar"
    >>> load(to_strm(''))
    {}
    >>> load(to_strm("# " + s0))
    {}
    >>> load(to_strm("! " + s0))
    {}
    >>> load(to_strm("calendar.japanese.type:"))
    {'calendar.japanese.type': ''}
    >>> load(to_strm(s0))
    {'calendar.japanese.type': 'LocalGregorianCalendar'}
    >>> load(to_strm(s0 + "# ..."))
    {'calendar.japanese.type': 'LocalGregorianCalendar# ...'}
    >>> s1 = r"key=a\\:b"
    >>> load(to_strm(s1))
    {'key': 'a:b'}
    >>> s2 = '''application/postscript: \\
    ...         x=Postscript File;y=.eps,.ps
    ... '''
    >>> load(to_strm(s2))
    {'application/postscript': 'x=Postscript File;y=.eps,.ps'}
    
Load and parse Java properties file given as a fiel or file-like object
`stream`.
Load and parse Java properties file given as a fiel or file - like object ` stream ` .
def load(stream, container=dict, comment_markers=_COMMENT_MARKERS):
    ret = container()
    prev = ""
    for line in stream.readlines():
        line = _pre_process_line(prev + line.strip().rstrip(),
                                 comment_markers)
        if line is None or not line:
            continue
        prev = ""  
        if line.endswith("\\"):
            prev += line.rstrip(" \\")
            continue
        (key, val) = _parseline(line)
        if key is None:
            LOGGER.warning("Failed to parse the line: %s", line)
            continue
        ret[key] = unescape(val)
    return ret
def load ( stream , container = dict , comment_markers = _COMMENT_MARKERS ) : ret = container ( ) prev = "" for line in stream . readlines ( ) : line = _pre_process_line ( prev + line . strip ( ) . rstrip ( ) , comment_markers ) if line is None or not line : continue prev = "" if line . endswith ( "\\" ) : prev += line . rstrip ( " \\" ) continue ( key , val ) = _parseline ( line ) if key is None : LOGGER . warning ( "Failed to parse the line: %s" , line ) continue ret [ key ] = unescape ( val ) return ret
Load and parse Java properties file given as a fiel or file-like object
`stream`.
Load and parse Java properties file given as a fiel or file - like object ` stream ` .
"""
    Load and parse Java properties file given as a fiel or file-like object
    `stream`.

    :param stream: A file or file like object of Java properties files
    :param container:
        Factory function to create a dict-like object to store properties
    :param comment_markers: Comment markers, e.g. '#' (hash)
    :return: Dict-like object holding properties

    >>> to_strm = anyconfig.compat.StringIO
    >>> s0 = "calendar.japanese.type: LocalGregorianCalendar"
    >>> load(to_strm(''))
    {}
    >>> load(to_strm("# " + s0))
    {}
    >>> load(to_strm("! " + s0))
    {}
    >>> load(to_strm("calendar.japanese.type:"))
    {'calendar.japanese.type': ''}
    >>> load(to_strm(s0))
    {'calendar.japanese.type': 'LocalGregorianCalendar'}
    >>> load(to_strm(s0 + "# ..."))
    {'calendar.japanese.type': 'LocalGregorianCalendar# ...'}
    >>> s1 = r"key=a\\:b"
    >>> load(to_strm(s1))
    {'key': 'a:b'}
    >>> s2 = '''application/postscript: \\
    ...         x=Postscript File;y=.eps,.ps
    ... '''
    >>> load(to_strm(s2))
    {'application/postscript': 'x=Postscript File;y=.eps,.ps'}
    """ # I don't think later case may happen but just in case. # re-initialize for later use.
Dict-like object holding properties
>>> to_strm = anyconfig.compat.StringIO
>>> s0 = "calendar.japanese.type: LocalGregorianCalendar"
>>> load(to_strm(''))
{}
>>> load(to_strm("# " + s0))
{}
>>> load(to_strm(". " + s0))
{}
>>> load(to_strm("calendar.japanese.type:"))
{'calendar.japanese.type': ''}
>>> load(to_strm(s0))
{'calendar.japanese.type': 'LocalGregorianCalendar'}
>>> load(to_strm(s0 + "# ..."))
{'calendar.japanese.type': 'LocalGregorianCalendar# ...'}
>>> s1 = r"key=a\\:b"
>>> load(to_strm(s1))
{'key': 'a:b'}
>>> s2 = '''application/postscript:
x=Postscript File;y=.eps,.ps
'''
>>> load(to_strm(s2))
{'application/postscript': 'x=Postscript File;y=.eps,.ps'}
Dict - like object holding properties >>> to_strm = anyconfig . compat . StringIO >>> s0 = " calendar . japanese . type : LocalGregorianCalendar " >>> load ( to_strm ( ' ' )) {} >>> load ( to_strm ( " # " + s0 )) {} >>> load ( to_strm ( " . " + s0 )) {} >>> load ( to_strm ( " calendar . japanese . type : " )) { ' calendar . japanese . type ' : ' ' } >>> load ( to_strm ( s0 )) { ' calendar . japanese . type ' : ' LocalGregorianCalendar ' } >>> load ( to_strm ( s0 + " # ... " )) { ' calendar . japanese . type ' : ' LocalGregorianCalendar# ... ' } >>> s1 = r " key = a \\ : b " >>> load ( to_strm ( s1 )) { ' key ' : ' a : b ' } >>> s2 = ' ' ' application / postscript : x = Postscript File ; y = . eps . ps ' ' ' >>> load ( to_strm ( s2 )) { ' application / postscript ' : ' x = Postscript File ; y = . eps . ps ' }
stream
A file or file like object of Java properties files
A file or file like object of Java properties files
container
Factory function to create a dict-like object to store properties
Factory function to create a dict - like object to store properties
comment_markers
Comment markers, e.g.
Comment markers e . g .