mirror of
https://github.com/ralsina/tartrazine.git
synced 2024-11-10 05:22:23 +00:00
python: expose is_vendor()
Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
parent
be583cad06
commit
6cf5bf2ca4
@ -4,6 +4,8 @@ Python library calling enry Go implementation trough cFFI (API, out-of-line) and
|
||||
|
||||
from _c_enry import ffi, lib
|
||||
|
||||
## Helpers
|
||||
|
||||
|
||||
def go_str_to_py(go_str):
|
||||
str_len = go_str.n
|
||||
@ -19,6 +21,13 @@ def py_str_to_go(py_str):
|
||||
return go_str[0]
|
||||
|
||||
|
||||
def go_bool_to_py(go_bool):
|
||||
return go_bool == 1
|
||||
|
||||
|
||||
## API
|
||||
|
||||
|
||||
def language_by_extension(filename: str) -> str:
|
||||
fName = py_str_to_go(filename)
|
||||
guess = lib.GetLanguageByExtension(fName)
|
||||
@ -33,11 +42,19 @@ def language_by_filename(filename: str) -> str:
|
||||
return lang
|
||||
|
||||
|
||||
## Test
|
||||
def is_vendor(filename: str) -> bool:
|
||||
fName = py_str_to_go(filename)
|
||||
guess = lib.IsVendor(fName)
|
||||
return go_bool_to_py(guess)
|
||||
|
||||
|
||||
## Tests
|
||||
|
||||
|
||||
def main():
|
||||
files = ["Parse.hs", "some.cpp", "and.go", "type.h", ".bashrc"]
|
||||
files = [
|
||||
"Parse.hs", "some.cpp", "and.go", "type.h", ".bashrc", ".gitignore"
|
||||
]
|
||||
|
||||
print("strategy: extension")
|
||||
for filename in files:
|
||||
@ -49,6 +66,11 @@ def main():
|
||||
lang = language_by_filename(filename)
|
||||
print("file: {:10s} language: '{}'".format(filename, lang))
|
||||
|
||||
print("\ncheck: is vendor?")
|
||||
for filename in files:
|
||||
vendor = is_vendor(filename)
|
||||
print("file: {:10s} vendor: '{}'".format(filename, vendor))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
@ -23,6 +23,8 @@ struct GetLanguageByFilename_return {
|
||||
};
|
||||
|
||||
extern struct GetLanguageByFilename_return GetLanguageByFilename(GoString p0);
|
||||
|
||||
extern GoUint8 IsVendor(GoString p0);
|
||||
""")
|
||||
|
||||
# set_source() gives the name of the python extension module to
|
||||
|
Loading…
Reference in New Issue
Block a user