~ubuntu-branches/debian/sid/python-biopython/sid

« back to all changes in this revision

Viewing changes to Bio/triemodule.c

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2014-06-08 10:25:35 UTC
  • mfrom: (1.1.22)
  • Revision ID: package-import@ubuntu.com-20140608102535-ebgnhcpcrum3i3w8
Tags: 1.64+dfsg-1
* New upstream version
* Build-Depends raxml only on those architectures where it is available
  Closes: #750845

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
{
67
67
    const char *key;
68
68
    PyObject *py_value;
69
 
#ifdef IS_PY3K
70
 
    PyObject* bytes;
71
 
#endif
72
69
 
73
70
    /* Make sure key is a string. */
74
71
#ifdef IS_PY3K
80
77
        return NULL;
81
78
    }
82
79
#ifdef IS_PY3K
83
 
    bytes = PyUnicode_AsASCIIString(py_key);
84
 
    if(!bytes) {
85
 
        PyErr_SetString(PyExc_TypeError, "key must be an ASCII string");
86
 
        return NULL;
87
 
    }
88
 
    key = PyBytes_AsString(bytes);
 
80
    /* TODO - Review next line for buffer usage */
 
81
    key = PyBytes_AS_STRING(PyUnicode_AsASCIIString(py_key));
89
82
#else
90
83
    key = PyString_AS_STRING(py_key);
91
84
#endif
92
85
    py_value = Trie_get(mp->trie, key);
93
 
#ifdef IS_PY3K
94
 
    Py_DECREF(bytes);
95
 
#endif
96
86
    if(py_value == NULL)
97
87
        PyErr_SetString(PyExc_KeyError, key);
98
88
    else
606
596
    if(!length)
607
597
        return 1;
608
598
 
609
 
    if(!(py_retval = PyObject_CallMethod(py_handle, "write", "s#",
 
599
#ifdef IS_PY3K
 
600
    if(!(py_retval = PyObject_CallMethod(py_handle, "write", "y#",
610
601
                                         towrite, length)))
 
602
#else
 
603
      if(!(py_retval = PyObject_CallMethod(py_handle, "write", "s#",
 
604
                                           towrite, length)))
 
605
#endif
611
606
        goto _write_to_handle_cleanup;
612
607
    success = 1;
613
608
 
687
682
{
688
683
    PyObject *py_handle = (PyObject *)handle;
689
684
    PyObject *py_retval = NULL;
690
 
#ifdef IS_PY3K
691
 
    PyObject* bytes = NULL;
692
 
#endif
693
685
    int success = 0;
694
686
    char* buffer;
695
687
 
700
692
 
701
693
    py_retval = PyObject_CallMethod(py_handle, "read", "i", length);
702
694
#ifdef IS_PY3K
703
 
    if(!PyUnicode_Check(py_retval)) {
 
695
    if(!PyBytes_Check(py_retval)) {
704
696
#else
705
697
    if(!PyString_Check(py_retval)) {
706
698
#endif
707
 
        PyErr_SetString(PyExc_TypeError, "expected a string");
 
699
        PyErr_SetString(PyExc_TypeError, "expected a bytes string");
708
700
        goto error;
709
701
    }
710
702
#ifdef IS_PY3K
711
 
    bytes = PyUnicode_AsASCIIString(py_retval);
712
 
    if(!bytes) {
713
 
        PyErr_SetString(PyExc_TypeError, "expected an ASCII string");
714
 
        goto error;
715
 
    }
716
 
    buffer = PyBytes_AsString(bytes);
 
703
    buffer = PyBytes_AS_STRING(py_retval);
717
704
#else
718
705
    buffer = PyString_AS_STRING(py_retval);
719
706
#endif
720
707
    memcpy(wasread, buffer, length);
721
708
    success = 1;
722
709
error:
723
 
#ifdef IS_PY3K
724
 
    Py_XDECREF(bytes);
725
 
#endif
726
710
    Py_XDECREF(py_retval);
727
711
    return success;
728
712
}