kafka_neu-1778570057504.zip-extract/kafka-4.2.0-src/release/textfiles.py

Path
kafka_neu-1778570057504.zip-extract/kafka-4.2.0-src/release/textfiles.py
Status
scanned
Type
file
Name
textfiles.py
Extension
.py
Programming language
Python
Mime type
text/x-script.python
File type
Python script, ASCII text executable
Tag

      
    
Rootfs path

      
    
Size
2033 (2.0 KB)
MD5
99a95363139e6b4caf7b0efc9ef26592
SHA1
811518f9bdf7c1e8502a276d1cd9a8aa4b361781
SHA256
e2b9c799f35bc259895a18200c60db6bc9f1da7b76dcc5b9b79c8bbfed3ac078
SHA512

      
    
SHA1_git
20752659c4bd2c8397717f97cfae278a6ea3217d
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
textfiles.py | 2.0 KB |

# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ Auxiliary functions to access and manipulate text files. """ import re from jproperties import Properties def read(file_path): with open(file_path) as f: return f.read() def write(file_path, content): with open(file_path, "w") as f: f.write(content) def props(properties_text): """ Load the keys and values into a dictionary from a .properties file. """ props = Properties() props.load(properties_text, "utf-8") return props def prop(filepath, propname): """ Read the value for a given key in a .properties file. """ values = props(read(filepath)) value, _ = values[propname] return value def replace(path, pattern, replacement, **kwargs): """ Replace all occurrences of a text pattern in a text file. """ is_regex = kwargs.get("regex", False) updated = [] with open(path, "r") as f: for line in f: modified = line if is_regex: modified = re.sub(pattern, replacement, line) elif line.startswith(pattern): modified = replacement + " " updated.append(modified) with open(path, "w") as f: for line in updated: f.write(line)
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
43.75
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9