python: expose is_vendor()

Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
Alexander Bezzubov 2019-06-01 21:30:07 +02:00
parent be583cad06
commit 6cf5bf2ca4
No known key found for this signature in database
GPG Key ID: 8039F5787EFCD05D
2 changed files with 26 additions and 2 deletions

View File

@ -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()

View File

@ -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