Esempio n. 1
0
string_find_internal(PyStringObject *self, PyObject *args, int dir)
{
    PyObject *subobj;
    const char *sub;
    Py_ssize_t sub_len;
    Py_ssize_t start=0, end=PY_SSIZE_T_MAX;

    if (!stringlib_parse_args_finds("find/rfind/index/rindex",
                                    args, &subobj, &start, &end))
        return -2;

    if (PyString_Check(subobj)) {
        sub = PyString_AS_STRING(subobj);
        sub_len = PyString_GET_SIZE(subobj);
    }
#ifdef Py_USING_UNICODE
    else if (PyUnicode_Check(subobj))
        return PyUnicode_Find(
            (PyObject *)self, subobj, start, end, dir);
#endif
    else if (PyObject_AsCharBuffer(subobj, &sub, &sub_len))
        /* XXX - the "expected a character buffer object" is pretty
           confusing for a non-expert.  remap to something else ? */
        return -2;

    if (dir > 0)
        return stringlib_find_slice(
            PyString_AS_STRING(self), PyString_GET_SIZE(self),
            sub, sub_len, start, end);
    else
        return stringlib_rfind_slice(
            PyString_AS_STRING(self), PyString_GET_SIZE(self),
            sub, sub_len, start, end);
}
Esempio n. 2
0
int should_trace_module(PyObject *module_str) {
  int i, len, found;
  PyObject *item;
#ifndef IS_PY3K
  char *filter, *module;
#endif

  if (NULL == filter_modules) {
    return TRUE;
  }

#ifndef IS_PY3K
  module = PyString_AsString(module_str);
#endif

  found = FALSE;
  len = PyList_Size(filter_modules);
  for (i = 0; i < len && FALSE == found; i++) {
    item = PyList_GetItem(filter_modules, i);
#ifdef IS_PY3K
    found = PyUnicode_Find(module_str, item, 0, PyUnicode_GetSize(item), 1) >= 0 ? TRUE : FALSE ;
#else
    filter = PyString_AsString(item);
    found = strncmp(module, filter, strlen(filter)) == 0 ? TRUE : FALSE;
#endif
  }

  return found;
}