Пример #1
0
def setprop(escaped, separator, outfile, preserve_timestamp, file, key, value,
            encoding):
    """ Set values in a Java .properties file """
    if escaped:
        key = unescape(key)
        value = unescape(value)
    with click.open_file(file, encoding=encoding) as fpin:
        with click.open_file(outfile, 'w', encoding=encoding) as fpout:
            setproperties(fpin, fpout, {key: value}, preserve_timestamp,
                          separator)
Пример #2
0
def setprop(
    escaped,
    separator,
    outfile,
    preserve_timestamp,
    file,
    key,
    value,
    encoding,
    ensure_ascii,
):
    """Set values in a Java .properties file"""
    if escaped:
        key = unescape(key)
        value = unescape(value)
    with click.open_file(file, encoding=encoding) as fpin:
        with click.open_file(
                outfile,
                "w",
                encoding=encoding,
                errors="javapropertiesreplace",
        ) as fpout:
            setproperties(fpin, fpout, {key: value}, preserve_timestamp,
                          separator, ensure_ascii)
Пример #3
0
def getselect(file, key, defaults, default_value, encoding, escaped):
    if escaped:
        key = list(map(unescape, key))
        if default_value is not None:
            default_value = unescape(default_value)
    with click.open_file(file, encoding=encoding) as fp:
        props = getproperties(fp, key)
    if defaults is not None:
        with click.open_file(defaults, encoding=encoding) as fp:
            defaults = getproperties(fp, key)
    else:
        defaults = {}
    for k in key:
        v = default_value
        if k in props:
            v = props[k]
        elif k in defaults:
            v = defaults[k]
        yield (k,v)
Пример #4
0
# clean old format database
oldDbFilename = args.database + '/db.json.gz'
if os.path.isfile(oldDbFilename):
    print('Removing deprecated database file: ' + oldDbFilename)
    os.remove(oldDbFilename)

# get server.properties motd if no server name is set
if not args.server_name:
    p = re.compile('^motd=(.+)$')
    with open(args.server + '/server.properties', encoding='utf-8') as f:
        for line in f:
            m = p.match(line)
            if m:
                args.server_name = javaproperties.unescape(
                                       m.group(1)
                                   ).replace('\n', '<br>')
                break

# try and load usercache
usercache = dict()
try:
    with open(args.server + '/usercache.json') as f:
        for entry in json.load(f):
            usercache[entry['uuid']] = entry['name']
except:
    print('Cannot use usercache.json for offline player lookup')

# initialize database
if not os.path.isdir(args.database):
    os.mkdir(args.database)
Пример #5
0
def test_unescape_invalid_u_escape(s, esc):
    with pytest.raises(InvalidUEscapeError) as excinfo:
        unescape(s)
    assert excinfo.value.escape == esc
    assert str(excinfo.value) == 'Invalid \\u escape sequence: ' + esc
Пример #6
0
def test_unescape(sin, sout):
    assert unescape(sin) == sout
Пример #7
0
dbPlayerListActiveFilename = dbPlayerListPath + '/active{}.json.gz'

# clean old format database
oldDbFilename = args.database + '/db.json.gz'
if os.path.isfile(oldDbFilename):
    print('Removing deprecated database file: ' + oldDbFilename)
    os.remove(oldDbFilename)

# get server.properties motd if no server name is set
if not args.server_name:
    p = re.compile('^motd=(.+)$')
    with open(args.server + '/server.properties', encoding='utf-8') as f:
        for line in f:
            m = p.match(line)
            if m:
                args.server_name = javaproperties.unescape(m.group(1))
                break

# try and load usercache
usercache = dict()
try:
    with open(args.server + '/usercache.json') as f:
        for entry in json.load(f):
            usercache[entry['uuid']] = entry['name']
except:
    print('Cannot use usercache.json for offline player lookup')

# initialize database
if not os.path.isdir(args.database):
    os.mkdir(args.database)