anyconfig.backend.properties.builtin
¶
A backend module to load and dump (Java) properties files.
Format to support: Java Properties file, e.g. http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Properties.html
Requirements: None (built-in)
Development Status :: 4 - Beta
Limitations:
Key and value separator of white spaces is not supported
Keys contain escaped white spaces is not supported
Special options: None
Changelog:
Changed in version 0.7.0:
Fix handling of empty values, pointed by @ajays20078
Fix handling of values contain strings start with ‘#’ or ‘!’ by @ajays20078
Added in version 0.2:
Added native Java properties parser instead of a plugin utilizes pyjavaproperties module.
- anyconfig.backend.properties.builtin.parseline(line)¶
Parse a line of Java properties file.
- Parameters:
line (
str
) – A string to parse, must not start with ‘ ‘, ‘#’ or ‘!’ (comment)- Return type:
tuple
[Optional
[str
],str
]- Returns:
A tuple of (key, value), both key and value may be None
- anyconfig.backend.properties.builtin._pre_process_line(line, cmarkers=('#', '!'))¶
Preprocess a line in properties; strip comments, etc.
- Parameters:
line (
str
) – A string not starting w/ any white spaces and ending w/ line breaks. It may be empty. see also:load()
.cmarkers (
tuple
[str
,...
]) – Comment markers, e.g. ‘#’ (hash)
- Return type:
Optional
[str
]
- anyconfig.backend.properties.builtin.unescape(in_s)¶
Un-escape and take out the content from given str
in_s
.- Return type:
str
- anyconfig.backend.properties.builtin._escape_char(in_c)¶
Escape some special characters in java .properties files.
- Return type:
str
- anyconfig.backend.properties.builtin.escape(in_s)¶
Escape special characters in given str.
- Return type:
str
- anyconfig.backend.properties.builtin.load(stream, container=<class 'dict'>, **kwargs)¶
Load data from a java properties files given as
stream
.- Parameters:
stream (
IO
) – A file or file like object of Java properties filescontainer (
Callable
[...
,dict
[str
,Any
]]) – Factory function to create a dict-like object to store propertiescomment_markers – Comment markers, e.g. ‘#’ (hash)
- Return type:
dict
[str
,Any
]- Returns:
Dict-like object holding properties
- class anyconfig.backend.properties.builtin.Parser¶
Bases:
StreamParser
Parser for Java properties files.
-
_cid:
ClassVar
[str
] = 'properties.builtin'¶
-
_type:
ClassVar
[str
] = 'properties'¶
-
_extensions:
tuple
[str
,...
] = ('properties',)¶
-
_ordered:
ClassVar
[bool
] = True¶
-
_dict_opts:
tuple
[str
,...
] = ('ac_dict',)¶
- load_from_stream(stream, container, **kwargs)¶
Load config from given file like object ‘stream’.
- Parameters:
stream (
IO
) – A file or file like object of Java properties filescontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container objectkwargs – optional keyword parameters (ignored)
- Return type:
dict
[str
,Any
]- Returns:
Dict-like object holding config parameters
- dump_to_stream(cnf, stream, **_kwargs)¶
Dump config ‘cnf’ to a file or file-like object ‘stream’.
- Parameters:
cnf (
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]) – Java properties config data to dumpstream (
IO
) – Java properties file or file like objectkwargs – backend-specific optional keyword parameters :: dict
- Return type:
None
- __annotations__ = {'_allow_primitives': 'typing.ClassVar[bool]', '_cid': 'typing.ClassVar[str]', '_dict_opts': 'tuple[str, ...]', '_dump_opts': 'tuple[str, ...]', '_extensions': 'tuple[str, ...]', '_load_opts': 'tuple[str, ...]', '_open_read_mode': 'typing.ClassVar[str]', '_open_write_mode': 'typing.ClassVar[str]', '_ordered': 'typing.ClassVar[bool]', '_priority': 'typing.ClassVar[int]', '_type': 'typing.ClassVar[str]'}¶
- __module__ = 'anyconfig.backend.properties.builtin'¶
-
_cid: