__res.pyx 730 B

123456789101112131415161718192021222324252627282930313233343536
  1. from _codecs import utf_8_decode, utf_8_encode
  2. from libcpp cimport bool
  3. from util.generic.string cimport TString, TStringBuf
  4. cdef extern from "library/cpp/resource/resource.h" namespace "NResource":
  5. cdef size_t Count() except +
  6. cdef TStringBuf KeyByIndex(size_t idx) except +
  7. cdef bool FindExact(const TStringBuf key, TString* result) nogil except +
  8. def count():
  9. return Count()
  10. def key_by_index(idx):
  11. cdef TStringBuf ret = KeyByIndex(idx)
  12. return ret.Data()[:ret.Size()]
  13. def find(s):
  14. cdef TString res
  15. if isinstance(s, str):
  16. s = utf_8_encode(s)[0]
  17. if FindExact(TStringBuf(s, len(s)), &res):
  18. return res.c_str()[:res.length()]
  19. return None
  20. include "importer.pxi"