/* Generated by Pyrex 0.9.8.5 on Thu Jan 13 22:04:37 2011 */

#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include "structmember.h"
#ifndef PY_LONG_LONG
  #define PY_LONG_LONG LONG_LONG
#endif
#if PY_VERSION_HEX < 0x02050000
  typedef int Py_ssize_t;
  #define PY_SSIZE_T_MAX INT_MAX
  #define PY_SSIZE_T_MIN INT_MIN
  #define PyInt_FromSsize_t(z) PyInt_FromLong(z)
  #define PyInt_AsSsize_t(o)	PyInt_AsLong(o)
#endif
#if !defined(WIN32) && !defined(MS_WINDOWS)
  #ifndef __stdcall
    #define __stdcall
  #endif
  #ifndef __cdecl
    #define __cdecl
  #endif
#endif
#ifdef __cplusplus
#define __PYX_EXTERN_C extern "C"
#else
#define __PYX_EXTERN_C extern
#endif
#include <math.h>
#include "python-compat.h"
#include "stdlib.h"
#include "string.h"
#include "_static_tuple_c.h"


typedef struct {PyObject **p; int i; char *s; long n;} __Pyx_StringTabEntry; /*proto*/

static PyObject *__pyx_m;
static PyObject *__pyx_b;
static int __pyx_lineno;
static char *__pyx_filename;
static char **__pyx_f;

static char __pyx_mdoc[] = "Pyrex extensions to btree node parsing.";

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/

static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/

static void __Pyx_WriteUnraisable(char *name); /*proto*/

static PyObject *__Pyx_GetItemInt(PyObject *o, Py_ssize_t i); /*proto*/

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/

static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/

static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size);  /*proto*/

static PyObject *__Pyx_ImportModule(char *name); /*proto*/

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/

static void __Pyx_AddTraceback(char *funcname); /*proto*/

/* Declarations from bzrlib._static_tuple_c */

static PyTypeObject *__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple = 0;

/* Declarations from bzrlib._btree_serializer_pyx */


/* Declarations from implementation of bzrlib._btree_serializer_pyx */

struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_vtab;
  PyObject *bytes;
  int key_length;
  int ref_list_length;
  PyObject *keys;
  char *_cur_str;
  char *_end_str;
  char *_start;
  int _header_found;
};

typedef struct {
  PY_LONG_LONG block_offset;
  unsigned int block_length;
  unsigned int record_start;
  unsigned int record_end;
  char sha1[20];
} __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record;

typedef PyObject *(*__pyx_t_6bzrlib_21_btree_serializer_pyx_formatproc)(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);

struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode {
  PyObject_HEAD
  struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_vtab;
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *records;
  PyObject *last_key;
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *last_record;
  int num_records;
  unsigned char common_shift;
  unsigned char offsets[257];
};


struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser {
  PyObject *(*extract_key)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *,char *);
  int (*process_line)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *);
};
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;


struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode {
  StaticTuple *(*_record_to_value_and_refs)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);
  StaticTuple *(*_record_to_item)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *(*_lookup_record)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,char *);
  int (*_count_records)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,char *,char *);
  PyObject *(*_parse_bytes)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,PyObject *);
  char *(*_parse_one_entry)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,char *,char *,__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *);
  int (*_offset_for_sha1)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *,char *);
  PyObject *(*_compute_common)(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *);
};
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;

static PyTypeObject *__pyx_ptype_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = 0;
static PyTypeObject *__pyx_ptype_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = 0;
static int __pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[256];
static char *__pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf;
static __pyx_t_6bzrlib_21_btree_serializer_pyx_formatproc __pyx_v_6bzrlib_21_btree_serializer_pyx__record_formatter;
static void *__pyx_f_6bzrlib_21_btree_serializer_pyx__my_memrchr(void *,int,size_t); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(char *,Py_ssize_t); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size(char *,Py_ssize_t); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__populate_unhexbuf(void); /*proto*/
static int __pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(char *,char *); /*proto*/
static void __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(char *,char *); /*proto*/
static int __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(PyObject *,char *); /*proto*/
static StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(char *); /*proto*/
static unsigned int __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint(char *); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__format_record_py24(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__format_record(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *); /*proto*/

static char __pyx_k1[] = "tried to create a string with an invalid size: %d @0x%x";
static char __pyx_k2[] = "invalid key, wanted segment from ";
static char __pyx_k3[] = "sha1:";
static char __pyx_k4[] = "last < self._start";
static char __pyx_k5[] = "type=leaf";
static char __pyx_k6[] = "Node did not start with \"type=leaf\": %r";
static char __pyx_k7[] = "Failed to find the value area";
static char __pyx_k8[] = " 0 0";
static char __pyx_k9[] = "invalid key, loop_counter != self.ref_list_length";
static char __pyx_k10[] = "unexpected reference data present";
static char __pyx_k11[] = "self.bytes is not a string.";
static char __pyx_k12[] = "parse";
static char __pyx_k13[] = "not a 40-byte hex digest";
static char __pyx_k14[] = "not a 20-byte binary digest";
static char __pyx_k15[] = "sha1_bin must be a str of exactly 20 bytes";
static char __pyx_k16[] = "%s %s %s %s";
static char __pyx_k17[] = "%s %lu %lu %lu";
static char __pyx_k18[] = "%lu %lu %lu %lu";
static char __pyx_k19[] = "key %r is not present";
static char __pyx_k20[] = "We only support parsing plain 8-bit strings.";
static char __pyx_k21[] = "type=leaf\n";
static char __pyx_k22[] = "bytes did not start with 'type=leaf\\n': %r";
static char __pyx_k23[] = "Something went wrong while parsing.";
static char __pyx_k24[] = "line did not start with sha1: %r";
static char __pyx_k25[] = "Line did not contain 40 hex bytes";
static char __pyx_k26[] = "We failed to unhexlify";
static char __pyx_k27[] = "only 1 null, not 2 as expected";
static char __pyx_k28[] = "Failed to parse block offset";
static char __pyx_k29[] = "Failed to parse block length";
static char __pyx_k30[] = "Failed to parse record end";
static char __pyx_k31[] = "We expected a tuple() or StaticTuple() for node not: %s";
static char __pyx_k32[] = "With ref_lists, we expected 4 entries not: %s";
static char __pyx_k33[] = "Without ref_lists, we need at least 3 entries not: %s";
static char __pyx_k34[] = "\0";
static char __pyx_k35[] = "join";
static char __pyx_k36[] = "We expect references to be tuples not: %s";
static char __pyx_k37[] = "We expect reference bits to be strings not: %s";
static char __pyx_k38[] = "Expected a plain str for value not: %s";
static char __pyx_k39[] = "sys";
static char __pyx_k40[] = "0123456789abcdef";
static char __pyx_k41[] = "version_info";

static PyObject *__pyx_n_join;
static PyObject *__pyx_n_parse;
static PyObject *__pyx_n_sys;
static PyObject *__pyx_n_version_info;

static PyObject *__pyx_k1p;
static PyObject *__pyx_k2p;
static PyObject *__pyx_k4p;
static PyObject *__pyx_k6p;
static PyObject *__pyx_k7p;
static PyObject *__pyx_k9p;
static PyObject *__pyx_k10p;
static PyObject *__pyx_k11p;
static PyObject *__pyx_k13p;
static PyObject *__pyx_k14p;
static PyObject *__pyx_k15p;
static PyObject *__pyx_k16p;
static PyObject *__pyx_k19p;
static PyObject *__pyx_k20p;
static PyObject *__pyx_k22p;
static PyObject *__pyx_k23p;
static PyObject *__pyx_k24p;
static PyObject *__pyx_k25p;
static PyObject *__pyx_k26p;
static PyObject *__pyx_k27p;
static PyObject *__pyx_k28p;
static PyObject *__pyx_k29p;
static PyObject *__pyx_k30p;
static PyObject *__pyx_k31p;
static PyObject *__pyx_k32p;
static PyObject *__pyx_k33p;
static PyObject *__pyx_k34p;
static PyObject *__pyx_k36p;
static PyObject *__pyx_k37p;
static PyObject *__pyx_k38p;

static __Pyx_StringTabEntry __pyx_string_tab[] = {
  {&__pyx_n_join, 1, __pyx_k35, sizeof(__pyx_k35)},
  {&__pyx_n_parse, 1, __pyx_k12, sizeof(__pyx_k12)},
  {&__pyx_n_sys, 1, __pyx_k39, sizeof(__pyx_k39)},
  {&__pyx_n_version_info, 1, __pyx_k41, sizeof(__pyx_k41)},
  {&__pyx_k1p, 0, __pyx_k1, sizeof(__pyx_k1)},
  {&__pyx_k2p, 0, __pyx_k2, sizeof(__pyx_k2)},
  {&__pyx_k4p, 0, __pyx_k4, sizeof(__pyx_k4)},
  {&__pyx_k6p, 0, __pyx_k6, sizeof(__pyx_k6)},
  {&__pyx_k7p, 0, __pyx_k7, sizeof(__pyx_k7)},
  {&__pyx_k9p, 0, __pyx_k9, sizeof(__pyx_k9)},
  {&__pyx_k10p, 0, __pyx_k10, sizeof(__pyx_k10)},
  {&__pyx_k11p, 0, __pyx_k11, sizeof(__pyx_k11)},
  {&__pyx_k13p, 0, __pyx_k13, sizeof(__pyx_k13)},
  {&__pyx_k14p, 0, __pyx_k14, sizeof(__pyx_k14)},
  {&__pyx_k15p, 0, __pyx_k15, sizeof(__pyx_k15)},
  {&__pyx_k16p, 0, __pyx_k16, sizeof(__pyx_k16)},
  {&__pyx_k19p, 0, __pyx_k19, sizeof(__pyx_k19)},
  {&__pyx_k20p, 0, __pyx_k20, sizeof(__pyx_k20)},
  {&__pyx_k22p, 0, __pyx_k22, sizeof(__pyx_k22)},
  {&__pyx_k23p, 0, __pyx_k23, sizeof(__pyx_k23)},
  {&__pyx_k24p, 0, __pyx_k24, sizeof(__pyx_k24)},
  {&__pyx_k25p, 0, __pyx_k25, sizeof(__pyx_k25)},
  {&__pyx_k26p, 0, __pyx_k26, sizeof(__pyx_k26)},
  {&__pyx_k27p, 0, __pyx_k27, sizeof(__pyx_k27)},
  {&__pyx_k28p, 0, __pyx_k28, sizeof(__pyx_k28)},
  {&__pyx_k29p, 0, __pyx_k29, sizeof(__pyx_k29)},
  {&__pyx_k30p, 0, __pyx_k30, sizeof(__pyx_k30)},
  {&__pyx_k31p, 0, __pyx_k31, sizeof(__pyx_k31)},
  {&__pyx_k32p, 0, __pyx_k32, sizeof(__pyx_k32)},
  {&__pyx_k33p, 0, __pyx_k33, sizeof(__pyx_k33)},
  {&__pyx_k34p, 0, __pyx_k34, sizeof(__pyx_k34)},
  {&__pyx_k36p, 0, __pyx_k36, sizeof(__pyx_k36)},
  {&__pyx_k37p, 0, __pyx_k37, sizeof(__pyx_k37)},
  {&__pyx_k38p, 0, __pyx_k38, sizeof(__pyx_k38)},
  {0, 0, 0, 0}
};



/* Implementation of bzrlib._btree_serializer_pyx */

static void *__pyx_f_6bzrlib_21_btree_serializer_pyx__my_memrchr(void *__pyx_v_s,int __pyx_v_c,size_t __pyx_v_n) {
  char *__pyx_v_pos;
  char *__pyx_v_start;
  void *__pyx_r;
  int __pyx_1;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":87 */
  __pyx_v_start = ((char *)__pyx_v_s);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":88 */
  __pyx_v_pos = ((__pyx_v_start + __pyx_v_n) - 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":89 */
  while (1) {
    __pyx_1 = (__pyx_v_pos >= __pyx_v_start);
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":90 */
    __pyx_1 = ((__pyx_v_pos[0]) == __pyx_v_c);
    if (__pyx_1) {
      __pyx_r = __pyx_v_pos;
      goto __pyx_L0;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":92 */
    __pyx_v_pos = (__pyx_v_pos - 1);
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":93 */
  __pyx_r = NULL;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(char *__pyx_v_s,Py_ssize_t __pyx_v_size) {
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":98 */
  __pyx_1 = (__pyx_v_size < 0);
  if (__pyx_1) {
    __pyx_2 = PyInt_FromSsize_t(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(((int)__pyx_v_s)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
    __pyx_2 = 0;
    __pyx_3 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k1p, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 101; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 99; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":102 */
  __pyx_2 = PyString_FromStringAndSize(__pyx_v_s,__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 102; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.safe_string_from_size");
  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size(char *__pyx_v_s,Py_ssize_t __pyx_v_size) {
  PyObject *__pyx_v_py_str;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  __pyx_v_result = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":107 */
  __pyx_1 = (__pyx_v_size < 0);
  if (__pyx_1) {
    __pyx_2 = PyInt_FromSsize_t(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
    __pyx_3 = PyInt_FromLong(((int)__pyx_v_s)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
    __pyx_4 = PyTuple_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_4, 0, __pyx_2);
    PyTuple_SET_ITEM(__pyx_4, 1, __pyx_3);
    __pyx_2 = 0;
    __pyx_3 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k1p, __pyx_4); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 110; goto __pyx_L1;}
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 108; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":111 */
  __pyx_v_py_str = PyString_FromStringAndSize(__pyx_v_s,__pyx_v_size);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":112 */
  PyString_InternInPlace((&__pyx_v_py_str));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":113 */
  Py_INCREF(((PyObject *)__pyx_v_py_str));
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = ((PyObject *)__pyx_v_py_str);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":116 */
  Py_DECREF(__pyx_v_py_str);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":117 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.safe_interned_string_from_size");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_bytes = 0;
  PyObject *__pyx_v_key_length = 0;
  PyObject *__pyx_v_ref_list_length = 0;
  int __pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"bytes","key_length","ref_list_length",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_bytes, &__pyx_v_key_length, &__pyx_v_ref_list_length)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_bytes);
  Py_INCREF(__pyx_v_key_length);
  Py_INCREF(__pyx_v_ref_list_length);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":154 */
  Py_INCREF(__pyx_v_bytes);
  Py_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes);
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes = __pyx_v_bytes;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":155 */
  __pyx_1 = PyInt_AsLong(__pyx_v_key_length); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 155; goto __pyx_L1;}
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->key_length = __pyx_1;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":156 */
  __pyx_1 = PyInt_AsLong(__pyx_v_ref_list_length); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 156; goto __pyx_L1;}
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->ref_list_length = __pyx_1;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":157 */
  __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 157; goto __pyx_L1;}
  Py_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys);
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":158 */
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str = NULL;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":159 */
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_end_str = NULL;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":160 */
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_header_found = 0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_bytes);
  Py_DECREF(__pyx_v_key_length);
  Py_DECREF(__pyx_v_ref_list_length);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_extract_key(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_v_self,char *__pyx_v_last) {
  char *__pyx_v_temp_ptr;
  int __pyx_v_loop_counter;
  StaticTuple *__pyx_v_key;
  PyObject *__pyx_v_failure_string;
  PyObject *__pyx_v_key_element;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  int __pyx_3;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_key = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  __pyx_v_failure_string = Py_None; Py_INCREF(Py_None);
  __pyx_v_key_element = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":173 */
  __pyx_1 = ((PyObject *)StaticTuple_New(__pyx_v_self->key_length)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 173; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_key));
  __pyx_v_key = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":174 */
  __pyx_2 = __pyx_v_self->key_length;
  for (__pyx_v_loop_counter = 0; __pyx_v_loop_counter < __pyx_2; ++__pyx_v_loop_counter) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":176 */
    __pyx_v_temp_ptr = ((char *)memchr(__pyx_v_self->_start,'\0',(__pyx_v_last - __pyx_v_self->_start)));

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":177 */
    __pyx_3 = (__pyx_v_temp_ptr == NULL);
    if (__pyx_3) {
      __pyx_3 = ((__pyx_v_loop_counter + 1) == __pyx_v_self->key_length);
      if (__pyx_3) {
        __pyx_v_temp_ptr = __pyx_v_last;
        goto __pyx_L5;
      }
      /*else*/ {

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":183 */
        __pyx_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_self->_start,(__pyx_v_last - __pyx_v_self->_start)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; goto __pyx_L1;}
        __pyx_4 = PyObject_Repr(__pyx_1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 184; goto __pyx_L1;}
        Py_DECREF(__pyx_1); __pyx_1 = 0;
        __pyx_1 = PyNumber_Add(__pyx_k2p, __pyx_4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 183; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        Py_DECREF(__pyx_v_failure_string);
        __pyx_v_failure_string = __pyx_1;
        __pyx_1 = 0;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":186 */
        __pyx_4 = PyTuple_New(1); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
        Py_INCREF(__pyx_v_failure_string);
        PyTuple_SET_ITEM(__pyx_4, 0, __pyx_v_failure_string);
        __pyx_1 = PyObject_CallObject(PyExc_AssertionError, __pyx_4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
        Py_DECREF(__pyx_4); __pyx_4 = 0;
        __Pyx_Raise(__pyx_1, 0, 0);
        Py_DECREF(__pyx_1); __pyx_1 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 186; goto __pyx_L1;}
      }
      __pyx_L5:;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":188 */
    __pyx_3 = (__pyx_v_self->key_length == 1);
    if (__pyx_3) {
      __pyx_3 = ((__pyx_v_temp_ptr - __pyx_v_self->_start) == 45);
      if (__pyx_3) {
        __pyx_3 = (strncmp(__pyx_v_self->_start,__pyx_k3,5) == 0);
      }
    }
    if (__pyx_3) {
      __pyx_4 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_self->_start,(__pyx_v_temp_ptr - __pyx_v_self->_start)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 191; goto __pyx_L1;}
      Py_DECREF(__pyx_v_key_element);
      __pyx_v_key_element = __pyx_4;
      __pyx_4 = 0;
      goto __pyx_L6;
    }
    /*else*/ {
      __pyx_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size(__pyx_v_self->_start,(__pyx_v_temp_ptr - __pyx_v_self->_start)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 194; goto __pyx_L1;}
      Py_DECREF(__pyx_v_key_element);
      __pyx_v_key_element = __pyx_1;
      __pyx_1 = 0;
    }
    __pyx_L6:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":197 */
    __pyx_v_self->_start = (__pyx_v_temp_ptr + 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":198 */
    Py_INCREF(__pyx_v_key_element);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":199 */
    StaticTuple_SET_ITEM(__pyx_v_key,__pyx_v_loop_counter,__pyx_v_key_element);
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":200 */
  __pyx_4 = ((PyObject *)StaticTuple_Intern(__pyx_v_key)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 200; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_key));
  __pyx_v_key = ((StaticTuple *)__pyx_4);
  __pyx_4 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":201 */
  Py_INCREF(((PyObject *)__pyx_v_key));
  __pyx_r = ((PyObject *)__pyx_v_key);
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.extract_key");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_failure_string);
  Py_DECREF(__pyx_v_key_element);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_process_line(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *__pyx_v_self) {
  char *__pyx_v_last;
  char *__pyx_v_temp_ptr;
  char *__pyx_v_ref_ptr;
  char *__pyx_v_next_start;
  int __pyx_v_loop_counter;
  Py_ssize_t __pyx_v_str_len;
  PyObject *__pyx_v_key;
  PyObject *__pyx_v_value;
  PyObject *__pyx_v_ref_lists;
  PyObject *__pyx_v_ref_list;
  PyObject *__pyx_v_node_value;
  int __pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_key = Py_None; Py_INCREF(Py_None);
  __pyx_v_value = Py_None; Py_INCREF(Py_None);
  __pyx_v_ref_lists = Py_None; Py_INCREF(Py_None);
  __pyx_v_ref_list = Py_None; Py_INCREF(Py_None);
  __pyx_v_node_value = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":212 */
  __pyx_v_self->_start = __pyx_v_self->_cur_str;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":214 */
  __pyx_v_last = ((char *)memchr(__pyx_v_self->_start,'\n',(__pyx_v_self->_end_str - __pyx_v_self->_start)));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":215 */
  __pyx_1 = (__pyx_v_last == NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":217 */
    __pyx_v_last = __pyx_v_self->_end_str;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":218 */
    __pyx_v_self->_cur_str = __pyx_v_self->_end_str;
    goto __pyx_L2;
  }
  /*else*/ {
    __pyx_v_self->_cur_str = (__pyx_v_last + 1);
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":224 */
  __pyx_1 = (__pyx_v_last == __pyx_v_self->_start);
  if (__pyx_1) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":227 */
  __pyx_1 = (__pyx_v_last < __pyx_v_self->_start);
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; goto __pyx_L1;}
    Py_INCREF(__pyx_k4p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k4p);
    __pyx_3 = PyObject_CallObject(PyExc_AssertionError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 229; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":230 */
  __pyx_1 = (0 == __pyx_v_self->_header_found);
  if (__pyx_1) {
    __pyx_1 = (strncmp(__pyx_k5,__pyx_v_self->_start,(__pyx_v_last - __pyx_v_self->_start)) == 0);
    if (__pyx_1) {

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":233 */
      __pyx_v_self->_header_found = 1;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":234 */
      __pyx_r = 0;
      goto __pyx_L0;
      goto __pyx_L6;
    }
    /*else*/ {
      __pyx_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_self->_start,(__pyx_v_last - __pyx_v_self->_start)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; goto __pyx_L1;}
      __pyx_3 = PyNumber_Remainder(__pyx_k6p, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 237; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_2, 0, __pyx_3);
      __pyx_3 = 0;
      __pyx_3 = PyObject_CallObject(PyExc_AssertionError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      __Pyx_Raise(__pyx_3, 0, 0);
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 236; goto __pyx_L1;}
    }
    __pyx_L6:;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":239 */
  __pyx_2 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self->__pyx_vtab)->extract_key(__pyx_v_self,__pyx_v_last); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 239; goto __pyx_L1;}
  Py_DECREF(__pyx_v_key);
  __pyx_v_key = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":241 */
  __pyx_v_temp_ptr = ((char *)__pyx_f_6bzrlib_21_btree_serializer_pyx__my_memrchr(__pyx_v_self->_start,'\0',(__pyx_v_last - __pyx_v_self->_start)));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":242 */
  __pyx_1 = (__pyx_v_temp_ptr == NULL);
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
    Py_INCREF(__pyx_k7p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k7p);
    __pyx_2 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 244; goto __pyx_L1;}
    goto __pyx_L7;
  }
  /*else*/ {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":252 */
    __pyx_v_str_len = ((__pyx_v_last - __pyx_v_temp_ptr) - 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":253 */
    __pyx_1 = (__pyx_v_str_len > 4);
    if (__pyx_1) {
      __pyx_1 = (strncmp(__pyx_k8,(__pyx_v_last - 4),4) == 0);
    }
    if (__pyx_1) {
      __pyx_3 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_interned_string_from_size((__pyx_v_temp_ptr + 1),__pyx_v_str_len); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 257; goto __pyx_L1;}
      Py_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_3;
      __pyx_3 = 0;
      goto __pyx_L8;
    }
    /*else*/ {
      __pyx_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size((__pyx_v_temp_ptr + 1),__pyx_v_str_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 259; goto __pyx_L1;}
      Py_DECREF(__pyx_v_value);
      __pyx_v_value = __pyx_2;
      __pyx_2 = 0;
    }
    __pyx_L8:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":261 */
    __pyx_v_last = __pyx_v_temp_ptr;
  }
  __pyx_L7:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":263 */
  __pyx_1 = __pyx_v_self->ref_list_length;
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":264 */
    __pyx_3 = ((PyObject *)StaticTuple_New(__pyx_v_self->ref_list_length)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 264; goto __pyx_L1;}
    Py_DECREF(__pyx_v_ref_lists);
    __pyx_v_ref_lists = __pyx_3;
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":265 */
    __pyx_v_loop_counter = 0;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":266 */
    while (1) {
      __pyx_1 = (__pyx_v_loop_counter < __pyx_v_self->ref_list_length);
      if (!__pyx_1) break;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":267 */
      __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 267; goto __pyx_L1;}
      Py_DECREF(__pyx_v_ref_list);
      __pyx_v_ref_list = __pyx_2;
      __pyx_2 = 0;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":269 */
      __pyx_v_loop_counter = (__pyx_v_loop_counter + 1);

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":270 */
      __pyx_1 = (__pyx_v_last < __pyx_v_self->_start);
      if (__pyx_1) {
        __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
        Py_INCREF(__pyx_k4p);
        PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k4p);
        __pyx_2 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
        __Pyx_Raise(__pyx_2, 0, 0);
        Py_DECREF(__pyx_2); __pyx_2 = 0;
        {__pyx_filename = __pyx_f[0]; __pyx_lineno = 271; goto __pyx_L1;}
        goto __pyx_L12;
      }
      __pyx_L12:;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":273 */
      __pyx_v_temp_ptr = ((char *)memchr(__pyx_v_self->_start,'\t',(__pyx_v_last - __pyx_v_self->_start)));

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":274 */
      __pyx_1 = (__pyx_v_temp_ptr == NULL);
      if (__pyx_1) {
        __pyx_1 = (__pyx_v_loop_counter != __pyx_v_self->ref_list_length);
        if (__pyx_1) {
          __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
          Py_INCREF(__pyx_k9p);
          PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k9p);
          __pyx_2 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
          Py_DECREF(__pyx_3); __pyx_3 = 0;
          __Pyx_Raise(__pyx_2, 0, 0);
          Py_DECREF(__pyx_2); __pyx_2 = 0;
          {__pyx_filename = __pyx_f[0]; __pyx_lineno = 278; goto __pyx_L1;}
          goto __pyx_L14;
        }
        /*else*/ {

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":282 */
          __pyx_v_ref_ptr = __pyx_v_last;

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":283 */
          __pyx_v_next_start = __pyx_v_last;
        }
        __pyx_L14:;
        goto __pyx_L13;
      }
      /*else*/ {

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":286 */
        __pyx_v_ref_ptr = __pyx_v_temp_ptr;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":287 */
        __pyx_v_next_start = (__pyx_v_temp_ptr + 1);
      }
      __pyx_L13:;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":289 */
      while (1) {
        __pyx_1 = (__pyx_v_self->_start < __pyx_v_ref_ptr);
        if (!__pyx_1) break;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":291 */
        __pyx_v_temp_ptr = ((char *)memchr(__pyx_v_self->_start,'\r',(__pyx_v_ref_ptr - __pyx_v_self->_start)));

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":293 */
        __pyx_1 = (__pyx_v_temp_ptr == NULL);
        if (__pyx_1) {
          __pyx_v_temp_ptr = __pyx_v_ref_ptr;
          goto __pyx_L17;
        }
        __pyx_L17:;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":297 */
        __pyx_3 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self->__pyx_vtab)->extract_key(__pyx_v_self,__pyx_v_temp_ptr); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; goto __pyx_L1;}
        __pyx_1 = PyList_Append(__pyx_v_ref_list,__pyx_3); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 297; goto __pyx_L1;}
        Py_DECREF(__pyx_3); __pyx_3 = 0;
      }

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":298 */
      __pyx_2 = PySequence_Tuple(__pyx_v_ref_list); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
      __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      __pyx_2 = ((PyObject *)StaticTuple_Intern(((StaticTuple *)__pyx_3))); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 298; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      Py_DECREF(__pyx_v_ref_list);
      __pyx_v_ref_list = __pyx_2;
      __pyx_2 = 0;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":299 */
      Py_INCREF(__pyx_v_ref_list);

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":300 */
      if (!__Pyx_TypeTest(__pyx_v_ref_lists, __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 300; goto __pyx_L1;}
      StaticTuple_SET_ITEM(((StaticTuple *)__pyx_v_ref_lists),(__pyx_v_loop_counter - 1),__pyx_v_ref_list);

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":302 */
      __pyx_v_self->_start = __pyx_v_next_start;
    }

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":303 */
    __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; goto __pyx_L1;}
    Py_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_value);
    Py_INCREF(__pyx_v_ref_lists);
    PyTuple_SET_ITEM(__pyx_3, 1, __pyx_v_ref_lists);
    __pyx_2 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple), __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 303; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_v_node_value);
    __pyx_v_node_value = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L9;
  }
  /*else*/ {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":305 */
    __pyx_1 = (__pyx_v_last != __pyx_v_self->_start);
    if (__pyx_1) {
      __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; goto __pyx_L1;}
      Py_INCREF(__pyx_k10p);
      PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k10p);
      __pyx_2 = PyObject_CallObject(PyExc_AssertionError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      __Pyx_Raise(__pyx_2, 0, 0);
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 307; goto __pyx_L1;}
      goto __pyx_L18;
    }
    __pyx_L18:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":308 */
    __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple), 0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
    __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
    Py_INCREF(__pyx_v_value);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_value);
    PyTuple_SET_ITEM(__pyx_2, 1, __pyx_3);
    __pyx_3 = 0;
    __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 308; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    Py_DECREF(__pyx_v_node_value);
    __pyx_v_node_value = __pyx_3;
    __pyx_3 = 0;
  }
  __pyx_L9:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":309 */
  __pyx_2 = PyTuple_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
  Py_INCREF(__pyx_v_key);
  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_key);
  Py_INCREF(__pyx_v_node_value);
  PyTuple_SET_ITEM(__pyx_2, 1, __pyx_v_node_value);
  __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
  Py_DECREF(__pyx_2); __pyx_2 = 0;
  __pyx_1 = PyList_Append(__pyx_v_self->keys,__pyx_3); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 309; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":310 */
  __pyx_r = 0;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.process_line");
  __pyx_r = (-1);
  __pyx_L0:;
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_value);
  Py_DECREF(__pyx_v_ref_lists);
  Py_DECREF(__pyx_v_ref_list);
  Py_DECREF(__pyx_v_node_value);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_parse(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_parse(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  Py_ssize_t __pyx_v_byte_count;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  char *__pyx_4;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":314 */
  __pyx_1 = (!PyString_CheckExact(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
    Py_INCREF(__pyx_k11p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k11p);
    __pyx_3 = PyObject_CallObject(PyExc_AssertionError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 315; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":316 */
  __pyx_v_byte_count = PyString_Size(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":317 */
  __pyx_4 = PyString_AsString(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->bytes); if (__pyx_4 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 317; goto __pyx_L1;}
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str = __pyx_4;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":319 */
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_end_str = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str + __pyx_v_byte_count);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":320 */
  while (1) {
    __pyx_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_cur_str < ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->_end_str);
    if (!__pyx_1) break;
    __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->__pyx_vtab)->process_line(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 321; goto __pyx_L1;}
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":322 */
  Py_INCREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys);
  __pyx_r = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)__pyx_v_self)->keys;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.BTreeLeafParser.parse");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_bytes = 0;
  PyObject *__pyx_v_key_length = 0;
  PyObject *__pyx_v_ref_list_length = 0;
  PyObject *__pyx_v_parser;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"bytes","key_length","ref_list_length",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_bytes, &__pyx_v_key_length, &__pyx_v_ref_list_length)) return 0;
  Py_INCREF(__pyx_v_bytes);
  Py_INCREF(__pyx_v_key_length);
  Py_INCREF(__pyx_v_ref_list_length);
  __pyx_v_parser = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":326 */
  __pyx_1 = PyTuple_New(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
  Py_INCREF(__pyx_v_bytes);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_bytes);
  Py_INCREF(__pyx_v_key_length);
  PyTuple_SET_ITEM(__pyx_1, 1, __pyx_v_key_length);
  Py_INCREF(__pyx_v_ref_list_length);
  PyTuple_SET_ITEM(__pyx_1, 2, __pyx_v_ref_list_length);
  __pyx_2 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser), __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 326; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_v_parser);
  __pyx_v_parser = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":327 */
  __pyx_1 = PyObject_GetAttr(__pyx_v_parser, __pyx_n_parse); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; goto __pyx_L1;}
  __pyx_2 = PyObject_CallObject(__pyx_1, 0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 327; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._parse_leaf_lines");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_parser);
  Py_DECREF(__pyx_v_bytes);
  Py_DECREF(__pyx_v_key_length);
  Py_DECREF(__pyx_v_ref_list_length);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__populate_unhexbuf(void) {
  int __pyx_v_i;
  PyObject *__pyx_r;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":351 */
  for (__pyx_v_i = 0; __pyx_v_i < 256; ++__pyx_v_i) {
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[__pyx_v_i]) = (-1);
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":353 */
  for (__pyx_v_i = 0; __pyx_v_i < 10; ++__pyx_v_i) {
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[(__pyx_v_i + '0')]) = __pyx_v_i;
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":355 */
  for (__pyx_v_i = 10; __pyx_v_i < 16; ++__pyx_v_i) {
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((__pyx_v_i - 10) + 'a')]) = __pyx_v_i;
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":357 */
  for (__pyx_v_i = 10; __pyx_v_i < 16; ++__pyx_v_i) {
    (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((__pyx_v_i - 10) + 'A')]) = __pyx_v_i;
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(char *__pyx_v_as_hex,char *__pyx_v_as_bin) {
  int __pyx_v_top;
  int __pyx_v_bot;
  int __pyx_v_i;
  int __pyx_v_j;
  int __pyx_r;
  int __pyx_1;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":374 */
  __pyx_v_j = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":375 */
  for (__pyx_v_i = 0; __pyx_v_i < 20; ++__pyx_v_i) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":376 */
    __pyx_v_top = (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((unsigned char)(__pyx_v_as_hex[__pyx_v_j]))]);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":377 */
    __pyx_v_j = (__pyx_v_j + 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":378 */
    __pyx_v_bot = (__pyx_v_6bzrlib_21_btree_serializer_pyx__unhexbuf[((unsigned char)(__pyx_v_as_hex[__pyx_v_j]))]);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":379 */
    __pyx_v_j = (__pyx_v_j + 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":380 */
    __pyx_1 = (__pyx_v_top == (-1));
    if (!__pyx_1) {
      __pyx_1 = (__pyx_v_bot == (-1));
    }
    if (__pyx_1) {
      __pyx_r = 0;
      goto __pyx_L0;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":382 */
    (__pyx_v_as_bin[__pyx_v_i]) = ((unsigned char)((__pyx_v_top << 4) + __pyx_v_bot));
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":383 */
  __pyx_r = 1;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_unhexlify(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_unhexlify[] = "For the test infrastructure, just thunks to _unhexlify_sha1";
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_unhexlify(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_as_hex = 0;
  PyObject *__pyx_v_as_bin;
  PyObject *__pyx_r;
  int __pyx_1;
  Py_ssize_t __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"as_hex",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_as_hex)) return 0;
  Py_INCREF(__pyx_v_as_hex);
  __pyx_v_as_bin = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":388 */
  __pyx_2 = PyObject_Length(__pyx_v_as_hex); if (__pyx_2 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 388; goto __pyx_L1;}
  __pyx_1 = (__pyx_2 != 40);
  if (!__pyx_1) {
    __pyx_1 = (!PyString_CheckExact(__pyx_v_as_hex));
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; goto __pyx_L1;}
    Py_INCREF(__pyx_k13p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k13p);
    __pyx_4 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 389; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":390 */
  __pyx_3 = PyString_FromStringAndSize(NULL,20); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 390; goto __pyx_L1;}
  Py_DECREF(__pyx_v_as_bin);
  __pyx_v_as_bin = __pyx_3;
  __pyx_3 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":391 */
  __pyx_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(PyString_AS_STRING(__pyx_v_as_hex),PyString_AS_STRING(__pyx_v_as_bin));
  if (__pyx_1) {
    Py_INCREF(__pyx_v_as_bin);
    __pyx_r = __pyx_v_as_bin;
    goto __pyx_L0;
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":393 */
  Py_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_unhexlify");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_as_bin);
  Py_DECREF(__pyx_v_as_hex);
  return __pyx_r;
}

static void __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(char *__pyx_v_as_bin,char *__pyx_v_as_hex) {
  int __pyx_v_i;
  int __pyx_v_j;
  char __pyx_v_c;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":400 */
  __pyx_v_j = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":401 */
  for (__pyx_v_i = 0; __pyx_v_i < 20; ++__pyx_v_i) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":402 */
    __pyx_v_c = (__pyx_v_as_bin[__pyx_v_i]);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":403 */
    (__pyx_v_as_hex[__pyx_v_j]) = (__pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf[((__pyx_v_c >> 4) & 0xf)]);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":404 */
    __pyx_v_j = (__pyx_v_j + 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":405 */
    (__pyx_v_as_hex[__pyx_v_j]) = (__pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf[(__pyx_v_c & 0xf)]);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":406 */
    __pyx_v_j = (__pyx_v_j + 1);
  }

}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_hexlify(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_hexlify[] = "For test infrastructure, thunk to _hexlify_sha1";
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_hexlify(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_as_bin = 0;
  PyObject *__pyx_v_as_hex;
  PyObject *__pyx_r;
  int __pyx_1;
  Py_ssize_t __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  static char *__pyx_argnames[] = {"as_bin",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_as_bin)) return 0;
  Py_INCREF(__pyx_v_as_bin);
  __pyx_v_as_hex = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":411 */
  __pyx_2 = PyObject_Length(__pyx_v_as_bin); if (__pyx_2 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 411; goto __pyx_L1;}
  __pyx_1 = (__pyx_2 != 20);
  if (!__pyx_1) {
    __pyx_1 = (!PyString_CheckExact(__pyx_v_as_bin));
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; goto __pyx_L1;}
    Py_INCREF(__pyx_k14p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k14p);
    __pyx_4 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 412; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":413 */
  __pyx_3 = PyString_FromStringAndSize(NULL,40); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 413; goto __pyx_L1;}
  Py_DECREF(__pyx_v_as_hex);
  __pyx_v_as_hex = __pyx_3;
  __pyx_3 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":414 */
  __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(PyString_AS_STRING(__pyx_v_as_bin),PyString_AS_STRING(__pyx_v_as_hex));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":415 */
  Py_INCREF(__pyx_v_as_hex);
  __pyx_r = __pyx_v_as_hex;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_hexlify");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_as_hex);
  Py_DECREF(__pyx_v_as_bin);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(PyObject *__pyx_v_key,char *__pyx_v_sha1) {
  char *__pyx_v_c_val;
  PyObject *__pyx_v_p_val;
  int __pyx_r;
  int __pyx_1;
  Py_INCREF(__pyx_v_key);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":428 */
  __pyx_1 = StaticTuple_CheckExact(__pyx_v_key);
  if (__pyx_1) {
    if (!__Pyx_TypeTest(__pyx_v_key, __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 428; goto __pyx_L1;}
    __pyx_1 = (StaticTuple_GET_SIZE(((StaticTuple *)__pyx_v_key)) == 1);
  }
  if (__pyx_1) {
    if (!__Pyx_TypeTest(__pyx_v_key, __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 429; goto __pyx_L1;}
    __pyx_v_p_val = ((PyObject *)StaticTuple_GET_ITEM(((StaticTuple *)__pyx_v_key),0));
    goto __pyx_L2;
  }
  __pyx_1 = PyTuple_CheckExact(__pyx_v_key);
  if (__pyx_1) {
    __pyx_1 = (PyTuple_GET_SIZE(__pyx_v_key) == 1);
  }
  if (__pyx_1) {
    __pyx_v_p_val = PyTuple_GET_ITEM(__pyx_v_key,0);
    goto __pyx_L2;
  }
  /*else*/ {
    __pyx_r = 0;
    goto __pyx_L0;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":435 */
  __pyx_1 = PyString_CheckExact(__pyx_v_p_val);
  if (__pyx_1) {
    __pyx_1 = (PyString_GET_SIZE(__pyx_v_p_val) == 45);
  }
  if (__pyx_1) {
    __pyx_v_c_val = PyString_AS_STRING(__pyx_v_p_val);
    goto __pyx_L3;
  }
  /*else*/ {
    __pyx_r = 0;
    goto __pyx_L0;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":439 */
  __pyx_1 = (strncmp(__pyx_v_c_val,__pyx_k3,5) != 0);
  if (__pyx_1) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":441 */
  __pyx_1 = (!__pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1((__pyx_v_c_val + 5),__pyx_v_sha1));
  if (__pyx_1) {
    __pyx_r = 0;
    goto __pyx_L0;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":443 */
  __pyx_r = 1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_WriteUnraisable("bzrlib._btree_serializer_pyx._key_to_sha1");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_key_to_sha1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_key_to_sha1[] = "Map a key to a simple sha1 string.\n\n    This is a testing thunk to the C function.\n    ";
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_key_to_sha1(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_key = 0;
  PyObject *__pyx_v_as_bin_sha;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {"key",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_key)) return 0;
  Py_INCREF(__pyx_v_key);
  __pyx_v_as_bin_sha = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":451 */
  __pyx_1 = PyString_FromStringAndSize(NULL,20); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 451; goto __pyx_L1;}
  Py_DECREF(__pyx_v_as_bin_sha);
  __pyx_v_as_bin_sha = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":452 */
  __pyx_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(__pyx_v_key,PyString_AS_STRING(__pyx_v_as_bin_sha));
  if (__pyx_2) {
    Py_INCREF(__pyx_v_as_bin_sha);
    __pyx_r = __pyx_v_as_bin_sha;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":454 */
  Py_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_key_to_sha1");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_as_bin_sha);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(char *__pyx_v_sha1) {
  StaticTuple *__pyx_v_key;
  PyObject *__pyx_v_hexxed;
  char *__pyx_v_c_buf;
  StaticTuple *__pyx_r;
  PyObject *__pyx_1 = 0;
  __pyx_v_key = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  __pyx_v_hexxed = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":462 */
  __pyx_1 = PyString_FromStringAndSize(NULL,45); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 462; goto __pyx_L1;}
  Py_DECREF(__pyx_v_hexxed);
  __pyx_v_hexxed = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":463 */
  __pyx_v_c_buf = PyString_AS_STRING(__pyx_v_hexxed);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":464 */
  memcpy(__pyx_v_c_buf,__pyx_k3,5);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":465 */
  __pyx_f_6bzrlib_21_btree_serializer_pyx__hexlify_sha1(__pyx_v_sha1,(__pyx_v_c_buf + 5));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":466 */
  __pyx_1 = ((PyObject *)StaticTuple_New(1)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 466; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_key));
  __pyx_v_key = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":467 */
  Py_INCREF(__pyx_v_hexxed);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":468 */
  StaticTuple_SET_ITEM(__pyx_v_key,0,__pyx_v_hexxed);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":478 */
  __pyx_1 = ((PyObject *)StaticTuple_Intern(__pyx_v_key)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 478; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_key));
  __pyx_v_key = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":479 */
  Py_INCREF(((PyObject *)__pyx_v_key));
  __pyx_r = __pyx_v_key;
  goto __pyx_L0;

  __pyx_r = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._sha1_to_key");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_hexxed);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_sha1_to_key(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_sha1_to_key[] = "Test thunk to check the sha1 mapping.";
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__py_sha1_to_key(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sha1_bin = 0;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {"sha1_bin",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_sha1_bin)) return 0;
  Py_INCREF(__pyx_v_sha1_bin);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":484 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_sha1_bin));
  if (!__pyx_1) {
    __pyx_1 = (PyString_GET_SIZE(__pyx_v_sha1_bin) != 20);
  }
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; goto __pyx_L1;}
    Py_INCREF(__pyx_k15p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k15p);
    __pyx_3 = PyObject_CallObject(PyExc_ValueError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 485; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":486 */
  __pyx_2 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(PyString_AS_STRING(__pyx_v_sha1_bin))); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 486; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._py_sha1_to_key");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_sha1_bin);
  return __pyx_r;
}

static unsigned int __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint(char *__pyx_v_sha1) {
  unsigned int __pyx_v_val;
  unsigned int __pyx_r;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":495 */
  __pyx_v_val = (((((((unsigned int)(__pyx_v_sha1[0])) & 0xff) << 24) | ((((unsigned int)(__pyx_v_sha1[1])) & 0xff) << 16)) | ((((unsigned int)(__pyx_v_sha1[2])) & 0xff) << 8)) | ((((unsigned int)(__pyx_v_sha1[3])) & 0xff) << 0));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":496 */
  __pyx_r = __pyx_v_val;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__format_record_py24(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  __pyx_1 = PyLong_FromLongLong(__pyx_v_record->block_offset); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; goto __pyx_L1;}
  __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_record->block_length); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; goto __pyx_L1;}
  __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_record->record_start); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; goto __pyx_L1;}
  __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_record->record_end); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 506; goto __pyx_L1;}
  __pyx_5 = PyTuple_New(4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_1);
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_2);
  PyTuple_SET_ITEM(__pyx_5, 2, __pyx_3);
  PyTuple_SET_ITEM(__pyx_5, 3, __pyx_4);
  __pyx_1 = 0;
  __pyx_2 = 0;
  __pyx_3 = 0;
  __pyx_4 = 0;
  __pyx_1 = PyNumber_Remainder(__pyx_k16p, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 505; goto __pyx_L1;}
  Py_DECREF(__pyx_5); __pyx_5 = 0;
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._format_record_py24");
  __pyx_r = 0;
  __pyx_L0:;
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__format_record(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
  PyObject *__pyx_v_block_offset_str;
  PyObject *__pyx_v_value;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  __pyx_v_block_offset_str = Py_None; Py_INCREF(Py_None);
  __pyx_v_value = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":512 */
  __pyx_1 = (__pyx_v_record->block_offset >= 0xFFFFFFFF);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":515 */
    __pyx_2 = PyLong_FromLongLong(__pyx_v_record->block_offset); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(((PyObject *)(&PyString_Type)), __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 515; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    Py_DECREF(__pyx_v_block_offset_str);
    __pyx_v_block_offset_str = __pyx_2;
    __pyx_2 = 0;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":516 */
    __pyx_3 = PyString_FromFormat(__pyx_k17,PyString_AS_STRING(__pyx_v_block_offset_str),__pyx_v_record->block_length,__pyx_v_record->record_start,__pyx_v_record->record_end); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 516; goto __pyx_L1;}
    Py_DECREF(__pyx_v_value);
    __pyx_v_value = __pyx_3;
    __pyx_3 = 0;
    goto __pyx_L2;
  }
  /*else*/ {
    __pyx_2 = PyString_FromFormat(__pyx_k18,((unsigned long)__pyx_v_record->block_offset),__pyx_v_record->block_length,__pyx_v_record->record_start,__pyx_v_record->record_end); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 521; goto __pyx_L1;}
    Py_DECREF(__pyx_v_value);
    __pyx_v_value = __pyx_2;
    __pyx_2 = 0;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":525 */
  Py_INCREF(__pyx_v_value);
  __pyx_r = __pyx_v_value;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._format_record");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_block_offset_str);
  Py_DECREF(__pyx_v_value);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___sizeof__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___sizeof__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = PyInt_FromLong((((((((((sizeof(PyObject)) + (sizeof(void *))) + (sizeof(int))) + (sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))) + (sizeof(PyObject *))) + (sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *))) + (sizeof(char))) + ((sizeof(unsigned char)) * 257)) + ((sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record)) * ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records))); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 566; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  __pyx_1 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__sizeof__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static void __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___dealloc__(PyObject *__pyx_v_self); /*proto*/
static void __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___dealloc__(PyObject *__pyx_v_self) {
  int __pyx_1;
  Py_INCREF(__pyx_v_self);
  __pyx_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records != NULL);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":570 */
    PyMem_Free(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":571 */
    ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records = NULL;
    goto __pyx_L2;
  }
  __pyx_L2:;

  Py_DECREF(__pyx_v_self);
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_bytes = 0;
  int __pyx_r;
  PyObject *__pyx_1 = 0;
  static char *__pyx_argnames[] = {"bytes",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_bytes)) return -1;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_bytes);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":574 */
  __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_parse_bytes(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self),__pyx_v_bytes); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 574; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":575 */
  Py_INCREF(Py_None);
  Py_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key = Py_None;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":576 */
  ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record = NULL;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__init__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_bytes);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7min_key___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7min_key___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":580 */
  __pyx_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records > 0);
  if (__pyx_1) {
    __pyx_2 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[0]).sha1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 581; goto __pyx_L1;}
    __pyx_r = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":582 */
  Py_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.min_key.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7max_key___get__(PyObject *__pyx_v_self); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7max_key___get__(PyObject *__pyx_v_self) {
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":586 */
  __pyx_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records > 0);
  if (__pyx_1) {
    __pyx_2 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records - 1)]).sha1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 587; goto __pyx_L1;}
    __pyx_r = __pyx_2;
    __pyx_2 = 0;
    goto __pyx_L0;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":588 */
  Py_INCREF(Py_None);
  __pyx_r = Py_None;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.max_key.__get__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_value_and_refs(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
  StaticTuple *__pyx_v_value_and_refs;
  StaticTuple *__pyx_v_empty;
  PyObject *__pyx_v_value;
  StaticTuple *__pyx_r;
  PyObject *__pyx_1 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_value_and_refs = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  __pyx_v_empty = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  __pyx_v_value = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":595 */
  __pyx_1 = ((PyObject *)StaticTuple_New(2)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 595; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_value_and_refs));
  __pyx_v_value_and_refs = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":596 */
  __pyx_1 = __pyx_v_6bzrlib_21_btree_serializer_pyx__record_formatter(__pyx_v_record); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 596; goto __pyx_L1;}
  Py_DECREF(__pyx_v_value);
  __pyx_v_value = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":597 */
  Py_INCREF(__pyx_v_value);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":598 */
  StaticTuple_SET_ITEM(__pyx_v_value_and_refs,0,__pyx_v_value);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":600 */
  __pyx_1 = ((PyObject *)StaticTuple_New(0)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 600; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_empty));
  __pyx_v_empty = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":601 */
  Py_INCREF(((PyObject *)__pyx_v_empty));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":602 */
  StaticTuple_SET_ITEM(__pyx_v_value_and_refs,1,((PyObject *)__pyx_v_empty));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":603 */
  Py_INCREF(((PyObject *)__pyx_v_value_and_refs));
  __pyx_r = __pyx_v_value_and_refs;
  goto __pyx_L0;

  __pyx_r = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._record_to_value_and_refs");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_value_and_refs);
  Py_DECREF(__pyx_v_empty);
  Py_DECREF(__pyx_v_value);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static StaticTuple *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_item(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record) {
  StaticTuple *__pyx_v_item;
  StaticTuple *__pyx_v_key;
  StaticTuple *__pyx_v_value_and_refs;
  StaticTuple *__pyx_r;
  PyObject *__pyx_1 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_item = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  __pyx_v_key = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  __pyx_v_value_and_refs = ((StaticTuple *)Py_None); Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":612 */
  __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key(__pyx_v_record->sha1)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 612; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_key));
  __pyx_v_key = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":613 */
  __pyx_1 = ((PyObject *)StaticTuple_New(2)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 613; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_item));
  __pyx_v_item = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":614 */
  Py_INCREF(((PyObject *)__pyx_v_key));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":615 */
  StaticTuple_SET_ITEM(__pyx_v_item,0,((PyObject *)__pyx_v_key));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":616 */
  __pyx_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_record_to_value_and_refs(__pyx_v_self,__pyx_v_record)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 616; goto __pyx_L1;}
  Py_DECREF(((PyObject *)__pyx_v_value_and_refs));
  __pyx_v_value_and_refs = ((StaticTuple *)__pyx_1);
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":617 */
  Py_INCREF(((PyObject *)__pyx_v_value_and_refs));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":618 */
  StaticTuple_SET_ITEM(__pyx_v_item,1,((PyObject *)__pyx_v_value_and_refs));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":619 */
  Py_INCREF(((PyObject *)__pyx_v_item));
  __pyx_r = __pyx_v_item;
  goto __pyx_L0;

  __pyx_r = ((StaticTuple *)Py_None); Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._record_to_item");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_item);
  Py_DECREF(__pyx_v_key);
  Py_DECREF(__pyx_v_value_and_refs);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__lookup_record(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,char *__pyx_v_sha1) {
  int __pyx_v_lo;
  int __pyx_v_hi;
  int __pyx_v_mid;
  int __pyx_v_the_cmp;
  int __pyx_v_offset;
  PyObject *__pyx_v_local_n_cmp;
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_local_n_cmp = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":635 */
  __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_offset_for_sha1(__pyx_v_self,__pyx_v_sha1); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 635; goto __pyx_L1;}
  __pyx_v_offset = __pyx_1;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":636 */
  __pyx_v_lo = (__pyx_v_self->offsets[__pyx_v_offset]);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":637 */
  __pyx_v_hi = (__pyx_v_self->offsets[(__pyx_v_offset + 1)]);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":638 */
  __pyx_1 = (__pyx_v_hi == 255);
  if (__pyx_1) {
    __pyx_v_hi = __pyx_v_self->num_records;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":644 */
  __pyx_2 = PyInt_FromLong(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 644; goto __pyx_L1;}
  Py_DECREF(__pyx_v_local_n_cmp);
  __pyx_v_local_n_cmp = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":645 */
  while (1) {
    __pyx_1 = (__pyx_v_lo < __pyx_v_hi);
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":646 */
    __pyx_v_mid = ((__pyx_v_lo + __pyx_v_hi) / 2);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":647 */
    __pyx_v_the_cmp = memcmp((__pyx_v_self->records[__pyx_v_mid]).sha1,__pyx_v_sha1,20);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":648 */
    __pyx_1 = (__pyx_v_the_cmp == 0);
    if (__pyx_1) {
      __pyx_r = (&(__pyx_v_self->records[__pyx_v_mid]));
      goto __pyx_L0;
      goto __pyx_L5;
    }
    __pyx_1 = (__pyx_v_the_cmp < 0);
    if (__pyx_1) {
      __pyx_v_lo = (__pyx_v_mid + 1);
      goto __pyx_L5;
    }
    /*else*/ {
      __pyx_v_hi = __pyx_v_mid;
    }
    __pyx_L5:;
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":654 */
  __pyx_r = NULL;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._lookup_record");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_local_n_cmp);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___contains__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  char __pyx_v_sha1[20];
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record;
  int __pyx_r;
  int __pyx_1;
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_2;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":659 */
  __pyx_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(__pyx_v_key,__pyx_v_sha1);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":661 */
    __pyx_2 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_lookup_record(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self),__pyx_v_sha1); if (__pyx_2 == NULL && PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 661; goto __pyx_L1;}
    __pyx_v_record = __pyx_2;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":662 */
    __pyx_1 = (__pyx_v_record != NULL);
    if (__pyx_1) {

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":663 */
      Py_INCREF(__pyx_v_key);
      Py_DECREF(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key);
      ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key = __pyx_v_key;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":664 */
      ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record = __pyx_v_record;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":665 */
      __pyx_1 = PyInt_AsLong(Py_True); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 665; goto __pyx_L1;}
      __pyx_r = __pyx_1;
      goto __pyx_L0;
      goto __pyx_L3;
    }
    __pyx_L3:;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":666 */
  __pyx_1 = PyInt_AsLong(Py_False); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 666; goto __pyx_L1;}
  __pyx_r = __pyx_1;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__contains__");
  __pyx_r = -1;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___getitem__(PyObject *__pyx_v_self, PyObject *__pyx_v_key) {
  char __pyx_v_sha1[20];
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_record;
  PyObject *__pyx_r;
  int __pyx_1;
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_key);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":671 */
  __pyx_v_record = NULL;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":672 */
  __pyx_1 = (((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record != NULL);
  if (__pyx_1) {
    __pyx_1 = __pyx_v_key == ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_key;
  }
  if (__pyx_1) {
    __pyx_v_record = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->last_record;
    goto __pyx_L2;
  }
  __pyx_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__key_to_sha1(__pyx_v_key,__pyx_v_sha1);
  if (__pyx_1) {
    __pyx_2 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_lookup_record(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self),__pyx_v_sha1); if (__pyx_2 == NULL && PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 675; goto __pyx_L1;}
    __pyx_v_record = __pyx_2;
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":676 */
  __pyx_1 = (__pyx_v_record == NULL);
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; goto __pyx_L1;}
    Py_INCREF(__pyx_v_key);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_key);
    __pyx_4 = PyNumber_Remainder(__pyx_k19p, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_4);
    __pyx_4 = 0;
    __pyx_4 = PyObject_CallObject(PyExc_KeyError, __pyx_3); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_4, 0, 0);
    Py_DECREF(__pyx_4); __pyx_4 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 677; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":678 */
  __pyx_3 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_record_to_value_and_refs(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self),__pyx_v_record)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 678; goto __pyx_L1;}
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.__getitem__");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_key);
  return __pyx_r;
}

static Py_ssize_t __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___len__(PyObject *__pyx_v_self); /*proto*/
static Py_ssize_t __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___len__(PyObject *__pyx_v_self) {
  Py_ssize_t __pyx_r;
  Py_INCREF(__pyx_v_self);
  __pyx_r = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_all_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_all_keys(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_i;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  int __pyx_3;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_result = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":685 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 685; goto __pyx_L1;}
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":686 */
  __pyx_2 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {
    __pyx_1 = ((PyObject *)__pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_key((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[__pyx_v_i]).sha1)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; goto __pyx_L1;}
    __pyx_3 = PyList_Append(__pyx_v_result,__pyx_1); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 687; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":688 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.all_keys");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_all_items(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_all_items(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_i;
  PyObject *__pyx_v_result;
  PyObject *__pyx_v_item;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  int __pyx_3;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_result = Py_None; Py_INCREF(Py_None);
  __pyx_v_item = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":692 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 692; goto __pyx_L1;}
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":693 */
  __pyx_2 = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->num_records;
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_2; ++__pyx_v_i) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":694 */
    __pyx_1 = ((PyObject *)((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_record_to_item(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self),(&(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->records[__pyx_v_i])))); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 694; goto __pyx_L1;}
    Py_DECREF(__pyx_v_item);
    __pyx_v_item = __pyx_1;
    __pyx_1 = 0;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":695 */
    __pyx_3 = PyList_Append(__pyx_v_result,__pyx_v_item); if (__pyx_3 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 695; goto __pyx_L1;}
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":696 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode.all_items");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_item);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__count_records(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,char *__pyx_v_c_content,char *__pyx_v_c_end) {
  char *__pyx_v_c_cur;
  int __pyx_v_num_records;
  int __pyx_r;
  int __pyx_1;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":703 */
  __pyx_v_c_cur = __pyx_v_c_content;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":704 */
  __pyx_v_num_records = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":705 */
  while (1) {
    __pyx_1 = (__pyx_v_c_cur != NULL);
    if (__pyx_1) {
      __pyx_1 = (__pyx_v_c_cur < __pyx_v_c_end);
    }
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":706 */
    __pyx_v_c_cur = ((char *)memchr(__pyx_v_c_cur,'\n',(__pyx_v_c_end - __pyx_v_c_cur)));

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":707 */
    __pyx_1 = (__pyx_v_c_cur == NULL);
    if (__pyx_1) {
      goto __pyx_L3;
      goto __pyx_L4;
    }
    __pyx_L4:;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":709 */
    __pyx_v_c_cur = (__pyx_v_c_cur + 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":710 */
    __pyx_v_num_records = (__pyx_v_num_records + 1);
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":711 */
  __pyx_r = __pyx_v_num_records;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_bytes(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,PyObject *__pyx_v_bytes) {
  char *__pyx_v_c_bytes;
  char *__pyx_v_c_cur;
  char *__pyx_v_c_end;
  Py_ssize_t __pyx_v_n_bytes;
  int __pyx_v_num_records;
  int __pyx_v_entry;
  __pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_cur_record;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  char *__pyx_4;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_bytes);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":723 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_bytes));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; goto __pyx_L1;}
    Py_INCREF(__pyx_k20p);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_k20p);
    __pyx_3 = PyObject_CallObject(PyExc_TypeError, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __Pyx_Raise(__pyx_3, 0, 0);
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 724; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":726 */
  __pyx_v_n_bytes = PyString_GET_SIZE(__pyx_v_bytes);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":727 */
  __pyx_v_c_bytes = PyString_AS_STRING(__pyx_v_bytes);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":728 */
  __pyx_v_c_end = (__pyx_v_c_bytes + __pyx_v_n_bytes);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":729 */
  __pyx_1 = strncmp(__pyx_v_c_bytes,__pyx_k21,10);
  if (__pyx_1) {
    __pyx_2 = PySequence_GetSlice(__pyx_v_bytes, 0, 10); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k22p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 731; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 730; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 730; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 730; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":732 */
  __pyx_v_c_cur = (__pyx_v_c_bytes + 10);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":733 */
  __pyx_v_num_records = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_count_records(__pyx_v_self,__pyx_v_c_cur,__pyx_v_c_end);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":735 */
  __pyx_v_self->records = ((__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *)PyMem_Malloc((__pyx_v_num_records * ((sizeof(unsigned short)) + (sizeof(__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record))))));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":737 */
  __pyx_v_self->num_records = __pyx_v_num_records;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":738 */
  __pyx_v_cur_record = __pyx_v_self->records;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":739 */
  __pyx_v_entry = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":740 */
  while (1) {
    __pyx_1 = (__pyx_v_c_cur != NULL);
    if (__pyx_1) {
      __pyx_1 = (__pyx_v_c_cur < __pyx_v_c_end);
      if (__pyx_1) {
        __pyx_1 = (__pyx_v_entry < __pyx_v_num_records);
      }
    }
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":741 */
    __pyx_4 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_parse_one_entry(__pyx_v_self,__pyx_v_c_cur,__pyx_v_c_end,__pyx_v_cur_record); if (__pyx_4 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 741; goto __pyx_L1;}
    __pyx_v_c_cur = __pyx_4;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":742 */
    __pyx_v_cur_record = (__pyx_v_cur_record + 1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":743 */
    __pyx_v_entry = (__pyx_v_entry + 1);
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":744 */
  __pyx_1 = (__pyx_v_entry != __pyx_v_self->num_records);
  if (!__pyx_1) {
    __pyx_1 = (__pyx_v_c_cur != __pyx_v_c_end);
    if (!__pyx_1) {
      __pyx_1 = (__pyx_v_cur_record != (__pyx_v_self->records + __pyx_v_self->num_records));
    }
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; goto __pyx_L1;}
    Py_INCREF(__pyx_k23p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k23p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 747; goto __pyx_L1;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":749 */
  __pyx_3 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_compute_common(__pyx_v_self); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 749; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._parse_bytes");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_bytes);
  return __pyx_r;
}

static char *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_one_entry(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,char *__pyx_v_c_cur,char *__pyx_v_c_end,__pyx_t_6bzrlib_21_btree_serializer_pyx_gc_chk_sha1_record *__pyx_v_cur_record) {
  char *__pyx_v_c_next;
  char *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":758 */
  __pyx_1 = strncmp(__pyx_v_c_cur,__pyx_k3,5);
  if (__pyx_1) {
    __pyx_2 = __pyx_f_6bzrlib_21_btree_serializer_pyx_safe_string_from_size(__pyx_v_c_cur,10); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; goto __pyx_L1;}
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k24p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 760; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 759; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":761 */
  __pyx_v_c_cur = (__pyx_v_c_cur + 5);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":762 */
  __pyx_v_c_next = ((char *)memchr(__pyx_v_c_cur,'\0',(__pyx_v_c_end - __pyx_v_c_cur)));

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":763 */
  __pyx_1 = (__pyx_v_c_next == NULL);
  if (!__pyx_1) {
    __pyx_1 = ((__pyx_v_c_next - __pyx_v_c_cur) != 40);
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; goto __pyx_L1;}
    Py_INCREF(__pyx_k25p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k25p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 764; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":765 */
  __pyx_1 = (!__pyx_f_6bzrlib_21_btree_serializer_pyx__unhexlify_sha1(__pyx_v_c_cur,__pyx_v_cur_record->sha1));
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; goto __pyx_L1;}
    Py_INCREF(__pyx_k26p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k26p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 766; goto __pyx_L1;}
    goto __pyx_L4;
  }
  __pyx_L4:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":767 */
  __pyx_v_c_cur = (__pyx_v_c_next + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":768 */
  __pyx_1 = ((__pyx_v_c_cur[0]) != '\0');
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; goto __pyx_L1;}
    Py_INCREF(__pyx_k27p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k27p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 769; goto __pyx_L1;}
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":770 */
  __pyx_v_c_cur = (__pyx_v_c_cur + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":771 */
  __pyx_v_cur_record->block_offset = strtoll(__pyx_v_c_cur,(&__pyx_v_c_next),10);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":772 */
  __pyx_1 = (__pyx_v_c_cur == __pyx_v_c_next);
  if (!__pyx_1) {
    __pyx_1 = ((__pyx_v_c_next[0]) != ' ');
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; goto __pyx_L1;}
    Py_INCREF(__pyx_k28p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k28p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 773; goto __pyx_L1;}
    goto __pyx_L6;
  }
  __pyx_L6:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":774 */
  __pyx_v_c_cur = (__pyx_v_c_next + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":775 */
  __pyx_v_cur_record->block_length = strtoul(__pyx_v_c_cur,(&__pyx_v_c_next),10);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":776 */
  __pyx_1 = (__pyx_v_c_cur == __pyx_v_c_next);
  if (!__pyx_1) {
    __pyx_1 = ((__pyx_v_c_next[0]) != ' ');
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; goto __pyx_L1;}
    Py_INCREF(__pyx_k29p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k29p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 777; goto __pyx_L1;}
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":778 */
  __pyx_v_c_cur = (__pyx_v_c_next + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":779 */
  __pyx_v_cur_record->record_start = strtoul(__pyx_v_c_cur,(&__pyx_v_c_next),10);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":780 */
  __pyx_1 = (__pyx_v_c_cur == __pyx_v_c_next);
  if (!__pyx_1) {
    __pyx_1 = ((__pyx_v_c_next[0]) != ' ');
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; goto __pyx_L1;}
    Py_INCREF(__pyx_k29p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k29p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 781; goto __pyx_L1;}
    goto __pyx_L8;
  }
  __pyx_L8:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":782 */
  __pyx_v_c_cur = (__pyx_v_c_next + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":783 */
  __pyx_v_cur_record->record_end = strtoul(__pyx_v_c_cur,(&__pyx_v_c_next),10);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":784 */
  __pyx_1 = (__pyx_v_c_cur == __pyx_v_c_next);
  if (!__pyx_1) {
    __pyx_1 = ((__pyx_v_c_next[0]) != '\n');
  }
  if (__pyx_1) {
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; goto __pyx_L1;}
    Py_INCREF(__pyx_k30p);
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_k30p);
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 785; goto __pyx_L1;}
    goto __pyx_L9;
  }
  __pyx_L9:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":786 */
  __pyx_v_c_cur = (__pyx_v_c_next + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":787 */
  __pyx_r = __pyx_v_c_cur;
  goto __pyx_L0;

  __pyx_r = 0;
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._parse_one_entry");
  __pyx_r = NULL;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static int __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__offset_for_sha1(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self,char *__pyx_v_sha1) {
  int __pyx_v_this_offset;
  unsigned int __pyx_v_as_uint;
  int __pyx_r;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":793 */
  __pyx_v_as_uint = __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint(__pyx_v_sha1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":794 */
  __pyx_v_this_offset = ((__pyx_v_as_uint >> __pyx_v_self->common_shift) & 0xFF);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":795 */
  __pyx_r = __pyx_v_this_offset;
  goto __pyx_L0;

  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__get_offset_for_sha1(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__get_offset_for_sha1(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_sha1 = 0;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  static char *__pyx_argnames[] = {"sha1",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "O", __pyx_argnames, &__pyx_v_sha1)) return 0;
  Py_INCREF(__pyx_v_self);
  Py_INCREF(__pyx_v_sha1);
  __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->__pyx_vtab)->_offset_for_sha1(((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self),PyString_AS_STRING(__pyx_v_sha1)); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; goto __pyx_L1;}
  __pyx_2 = PyInt_FromLong(__pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 798; goto __pyx_L1;}
  __pyx_r = __pyx_2;
  __pyx_2 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._get_offset_for_sha1");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  Py_DECREF(__pyx_v_sha1);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__compute_common(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *__pyx_v_self) {
  unsigned int __pyx_v_first;
  unsigned int __pyx_v_this;
  unsigned int __pyx_v_common_mask;
  unsigned char __pyx_v_common_shift;
  int __pyx_v_i;
  int __pyx_v_offset;
  int __pyx_v_this_offset;
  int __pyx_v_max_offset;
  PyObject *__pyx_r;
  int __pyx_1;
  Py_INCREF(__pyx_v_self);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":814 */
  __pyx_1 = (__pyx_v_self->num_records < 2);
  if (__pyx_1) {
    __pyx_v_self->common_shift = 24;
    goto __pyx_L2;
  }
  /*else*/ {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":819 */
    __pyx_v_common_mask = 0xFFFFFFFF;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":820 */
    __pyx_v_first = __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint((__pyx_v_self->records[0]).sha1);

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":821 */
    __pyx_1 = __pyx_v_self->num_records;
    for (__pyx_v_i = 0+1; __pyx_v_i < __pyx_1; ++__pyx_v_i) {

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":822 */
      __pyx_v_this = __pyx_f_6bzrlib_21_btree_serializer_pyx__sha1_to_uint((__pyx_v_self->records[__pyx_v_i]).sha1);

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":823 */
      __pyx_v_common_mask = ((~(__pyx_v_first ^ __pyx_v_this)) & __pyx_v_common_mask);
    }

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":824 */
    __pyx_v_common_shift = 24;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":825 */
    while (1) {
      __pyx_1 = (__pyx_v_common_mask & 0x80000000);
      if (__pyx_1) {
        __pyx_1 = (__pyx_v_common_shift > 0);
      }
      if (!__pyx_1) break;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":826 */
      __pyx_v_common_mask = (__pyx_v_common_mask << 1);

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":827 */
      __pyx_v_common_shift = (__pyx_v_common_shift - 1);
    }

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":828 */
    __pyx_v_self->common_shift = __pyx_v_common_shift;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":829 */
  __pyx_v_offset = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":830 */
  __pyx_v_max_offset = __pyx_v_self->num_records;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":835 */
  __pyx_1 = (__pyx_v_max_offset > 255);
  if (__pyx_1) {
    __pyx_v_max_offset = 255;
    goto __pyx_L7;
  }
  __pyx_L7:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":837 */
  for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_max_offset; ++__pyx_v_i) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":838 */
    __pyx_1 = ((struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self->__pyx_vtab)->_offset_for_sha1(__pyx_v_self,(__pyx_v_self->records[__pyx_v_i]).sha1); if (__pyx_1 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 838; goto __pyx_L1;}
    __pyx_v_this_offset = __pyx_1;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":839 */
    while (1) {
      __pyx_1 = (__pyx_v_offset <= __pyx_v_this_offset);
      if (!__pyx_1) break;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":840 */
      (__pyx_v_self->offsets[__pyx_v_offset]) = __pyx_v_i;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":841 */
      __pyx_v_offset = (__pyx_v_offset + 1);
    }
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":842 */
  while (1) {
    __pyx_1 = (__pyx_v_offset < 257);
    if (!__pyx_1) break;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":843 */
    (__pyx_v_self->offsets[__pyx_v_offset]) = __pyx_v_max_offset;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":844 */
    __pyx_v_offset = (__pyx_v_offset + 1);
  }

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._compute_common");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__get_offsets(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__get_offsets(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  int __pyx_v_i;
  PyObject *__pyx_v_result;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  static char *__pyx_argnames[] = {0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "", __pyx_argnames)) return 0;
  Py_INCREF(__pyx_v_self);
  __pyx_v_result = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":848 */
  __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 848; goto __pyx_L1;}
  Py_DECREF(__pyx_v_result);
  __pyx_v_result = __pyx_1;
  __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":849 */
  for (__pyx_v_i = 0; __pyx_v_i < 257; ++__pyx_v_i) {
    __pyx_1 = PyInt_FromLong((((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)__pyx_v_self)->offsets[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; goto __pyx_L1;}
    __pyx_2 = PyList_Append(__pyx_v_result,__pyx_1); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 850; goto __pyx_L1;}
    Py_DECREF(__pyx_1); __pyx_1 = 0;
  }

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":851 */
  Py_INCREF(__pyx_v_result);
  __pyx_r = __pyx_v_result;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode._get_offsets");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_result);
  Py_DECREF(__pyx_v_self);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__parse_into_chk(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx__parse_into_chk[] = "Parse into a format optimized for chk records.";
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__parse_into_chk(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_bytes = 0;
  PyObject *__pyx_v_key_length = 0;
  PyObject *__pyx_v_ref_list_length = 0;
  PyObject *__pyx_r;
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  static char *__pyx_argnames[] = {"bytes","key_length","ref_list_length",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOO", __pyx_argnames, &__pyx_v_bytes, &__pyx_v_key_length, &__pyx_v_ref_list_length)) return 0;
  Py_INCREF(__pyx_v_bytes);
  Py_INCREF(__pyx_v_key_length);
  Py_INCREF(__pyx_v_ref_list_length);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":856 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_v_key_length, __pyx_1, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; goto __pyx_L1;}
  __pyx_2 = __pyx_2 == 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (!__pyx_2) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 856; goto __pyx_L1;}
  }
  #endif

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":857 */
  #ifndef PYREX_WITHOUT_ASSERTIONS
  __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; goto __pyx_L1;}
  if (PyObject_Cmp(__pyx_v_ref_list_length, __pyx_1, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; goto __pyx_L1;}
  __pyx_2 = __pyx_2 == 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  if (!__pyx_2) {
    PyErr_SetNone(PyExc_AssertionError);
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 857; goto __pyx_L1;}
  }
  #endif

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":858 */
  __pyx_1 = PyTuple_New(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 858; goto __pyx_L1;}
  Py_INCREF(__pyx_v_bytes);
  PyTuple_SET_ITEM(__pyx_1, 0, __pyx_v_bytes);
  __pyx_3 = PyObject_CallObject(((PyObject *)__pyx_ptype_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode), __pyx_1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 858; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._parse_into_chk");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_bytes);
  Py_DECREF(__pyx_v_key_length);
  Py_DECREF(__pyx_v_ref_list_length);
  return __pyx_r;
}

static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__flatten_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/
static char __pyx_doc_6bzrlib_21_btree_serializer_pyx__flatten_node[] = "Convert a node into the serialized form.\n\n    :param node: A tuple representing a node:\n        (index, key_tuple, value, references)\n    :param reference_lists: Does this index have reference lists?\n    :return: (string_key, flattened)\n        string_key  The serialized key for referencing this node\n        flattened   A string with the serialized form for the contents\n    ";
static PyObject *__pyx_f_6bzrlib_21_btree_serializer_pyx__flatten_node(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) {
  PyObject *__pyx_v_node = 0;
  PyObject *__pyx_v_reference_lists = 0;
  int __pyx_v_have_reference_lists;
  Py_ssize_t __pyx_v_flat_len;
  Py_ssize_t __pyx_v_key_len;
  Py_ssize_t __pyx_v_node_len;
  char *__pyx_v_value;
  Py_ssize_t __pyx_v_value_len;
  char *__pyx_v_out;
  Py_ssize_t __pyx_v_refs_len;
  Py_ssize_t __pyx_v_next_len;
  int __pyx_v_first_ref_list;
  int __pyx_v_first_reference;
  int __pyx_v_i;
  Py_ssize_t __pyx_v_ref_bit_len;
  PyObject *__pyx_v_string_key;
  PyObject *__pyx_v_ref_lists;
  PyObject *__pyx_v_ref_list;
  PyObject *__pyx_v_reference;
  PyObject *__pyx_v_ref_bit;
  PyObject *__pyx_v_val;
  PyObject *__pyx_v_line;
  PyObject *__pyx_r;
  int __pyx_1;
  PyObject *__pyx_2 = 0;
  PyObject *__pyx_3 = 0;
  Py_ssize_t __pyx_4;
  PyObject *__pyx_5 = 0;
  PyObject *__pyx_6 = 0;
  PyObject *__pyx_7 = 0;
  char *__pyx_8;
  static char *__pyx_argnames[] = {"node","reference_lists",0};
  if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OO", __pyx_argnames, &__pyx_v_node, &__pyx_v_reference_lists)) return 0;
  Py_INCREF(__pyx_v_node);
  Py_INCREF(__pyx_v_reference_lists);
  __pyx_v_string_key = Py_None; Py_INCREF(Py_None);
  __pyx_v_ref_lists = Py_None; Py_INCREF(Py_None);
  __pyx_v_ref_list = Py_None; Py_INCREF(Py_None);
  __pyx_v_reference = Py_None; Py_INCREF(Py_None);
  __pyx_v_ref_bit = Py_None; Py_INCREF(Py_None);
  __pyx_v_val = Py_None; Py_INCREF(Py_None);
  __pyx_v_line = Py_None; Py_INCREF(Py_None);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":885 */
  __pyx_1 = (!PyTuple_CheckExact(__pyx_v_node));
  if (__pyx_1) {
    __pyx_1 = (!StaticTuple_CheckExact(__pyx_v_node));
  }
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; goto __pyx_L1;}
    Py_INCREF(__pyx_v_node);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_node);
    __pyx_3 = PyObject_CallObject(((PyObject *)(&PyType_Type)), __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_2 = PyNumber_Remainder(__pyx_k31p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 887; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_TypeError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 886; goto __pyx_L1;}
    goto __pyx_L2;
  }
  __pyx_L2:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":888 */
  __pyx_4 = PyObject_Length(__pyx_v_node); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 888; goto __pyx_L1;}
  __pyx_v_node_len = __pyx_4;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":889 */
  __pyx_1 = PyInt_AsLong(__pyx_v_reference_lists); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 889; goto __pyx_L1;}
  __pyx_v_have_reference_lists = __pyx_1;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":890 */
  __pyx_1 = __pyx_v_have_reference_lists;
  if (__pyx_1) {
    __pyx_1 = (__pyx_v_node_len != 4);
    if (__pyx_1) {
      __pyx_4 = PyObject_Length(__pyx_v_node); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; goto __pyx_L1;}
      __pyx_3 = PyInt_FromSsize_t(__pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; goto __pyx_L1;}
      __pyx_2 = PyNumber_Remainder(__pyx_k32p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 893; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; goto __pyx_L1;}
      PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
      __pyx_2 = 0;
      __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; goto __pyx_L1;}
      Py_DECREF(__pyx_3); __pyx_3 = 0;
      __Pyx_Raise(__pyx_2, 0, 0);
      Py_DECREF(__pyx_2); __pyx_2 = 0;
      {__pyx_filename = __pyx_f[0]; __pyx_lineno = 892; goto __pyx_L1;}
      goto __pyx_L4;
    }
    __pyx_L4:;
    goto __pyx_L3;
  }
  __pyx_1 = (__pyx_v_node_len < 3);
  if (__pyx_1) {
    __pyx_4 = PyObject_Length(__pyx_v_node); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; goto __pyx_L1;}
    __pyx_3 = PyInt_FromSsize_t(__pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; goto __pyx_L1;}
    __pyx_2 = PyNumber_Remainder(__pyx_k33p, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 896; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __pyx_3 = PyTuple_New(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_3, 0, __pyx_2);
    __pyx_2 = 0;
    __pyx_2 = PyObject_CallObject(PyExc_ValueError, __pyx_3); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; goto __pyx_L1;}
    Py_DECREF(__pyx_3); __pyx_3 = 0;
    __Pyx_Raise(__pyx_2, 0, 0);
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 895; goto __pyx_L1;}
    goto __pyx_L3;
  }
  __pyx_L3:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":907 */
  __pyx_3 = PyObject_GetAttr(__pyx_k34p, __pyx_n_join); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; goto __pyx_L1;}
  __pyx_2 = __Pyx_GetItemInt(__pyx_v_node, 1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; goto __pyx_L1;}
  __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2);
  __pyx_2 = 0;
  __pyx_2 = PyObject_CallObject(__pyx_3, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 907; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  Py_DECREF(__pyx_5); __pyx_5 = 0;
  Py_DECREF(__pyx_v_string_key);
  __pyx_v_string_key = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":921 */
  __pyx_v_refs_len = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":922 */
  __pyx_1 = __pyx_v_have_reference_lists;
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":924 */
    __pyx_3 = __Pyx_GetItemInt(__pyx_v_node, 3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 924; goto __pyx_L1;}
    Py_DECREF(__pyx_v_ref_lists);
    __pyx_v_ref_lists = __pyx_3;
    __pyx_3 = 0;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":925 */
    __pyx_4 = PyObject_Length(__pyx_v_ref_lists); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 925; goto __pyx_L1;}
    __pyx_v_next_len = __pyx_4;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":926 */
    __pyx_1 = (__pyx_v_next_len > 0);
    if (__pyx_1) {

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":930 */
      __pyx_v_refs_len = (__pyx_v_refs_len + (__pyx_v_next_len - 1));

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":931 */
      __pyx_5 = PyObject_GetIter(__pyx_v_ref_lists); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; goto __pyx_L1;}
      for (;;) {
        __pyx_2 = PyIter_Next(__pyx_5);
        if (!__pyx_2) {
          if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 931; goto __pyx_L1;}
          break;
        }
        Py_DECREF(__pyx_v_ref_list);
        __pyx_v_ref_list = __pyx_2;
        __pyx_2 = 0;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":932 */
        __pyx_4 = PyObject_Length(__pyx_v_ref_list); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 932; goto __pyx_L1;}
        __pyx_v_next_len = __pyx_4;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":933 */
        __pyx_1 = (__pyx_v_next_len > 0);
        if (__pyx_1) {

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":936 */
          __pyx_v_refs_len = (__pyx_v_refs_len + (__pyx_v_next_len - 1));

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":937 */
          __pyx_3 = PyObject_GetIter(__pyx_v_ref_list); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; goto __pyx_L1;}
          for (;;) {
            __pyx_2 = PyIter_Next(__pyx_3);
            if (!__pyx_2) {
              if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 937; goto __pyx_L1;}
              break;
            }
            Py_DECREF(__pyx_v_reference);
            __pyx_v_reference = __pyx_2;
            __pyx_2 = 0;

            /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":938 */
            __pyx_1 = (!PyTuple_CheckExact(__pyx_v_reference));
            if (__pyx_1) {
              __pyx_1 = (!StaticTuple_CheckExact(__pyx_v_reference));
            }
            if (__pyx_1) {
              __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; goto __pyx_L1;}
              Py_INCREF(__pyx_v_reference);
              PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_reference);
              __pyx_6 = PyObject_CallObject(((PyObject *)(&PyType_Type)), __pyx_2); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; goto __pyx_L1;}
              Py_DECREF(__pyx_2); __pyx_2 = 0;
              __pyx_2 = PyNumber_Remainder(__pyx_k36p, __pyx_6); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 942; goto __pyx_L1;}
              Py_DECREF(__pyx_6); __pyx_6 = 0;
              __pyx_6 = PyTuple_New(1); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 940; goto __pyx_L1;}
              PyTuple_SET_ITEM(__pyx_6, 0, __pyx_2);
              __pyx_2 = 0;
              __pyx_2 = PyObject_CallObject(PyExc_TypeError, __pyx_6); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 940; goto __pyx_L1;}
              Py_DECREF(__pyx_6); __pyx_6 = 0;
              __Pyx_Raise(__pyx_2, 0, 0);
              Py_DECREF(__pyx_2); __pyx_2 = 0;
              {__pyx_filename = __pyx_f[0]; __pyx_lineno = 940; goto __pyx_L1;}
              goto __pyx_L12;
            }
            __pyx_L12:;

            /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":943 */
            __pyx_4 = PyObject_Length(__pyx_v_reference); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 943; goto __pyx_L1;}
            __pyx_v_next_len = __pyx_4;

            /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":944 */
            __pyx_1 = (__pyx_v_next_len > 0);
            if (__pyx_1) {

              /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":947 */
              __pyx_v_refs_len = (__pyx_v_refs_len + (__pyx_v_next_len - 1));

              /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":948 */
              __pyx_6 = PyObject_GetIter(__pyx_v_reference); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; goto __pyx_L1;}
              for (;;) {
                __pyx_2 = PyIter_Next(__pyx_6);
                if (!__pyx_2) {
                  if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 948; goto __pyx_L1;}
                  break;
                }
                Py_DECREF(__pyx_v_ref_bit);
                __pyx_v_ref_bit = __pyx_2;
                __pyx_2 = 0;

                /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":949 */
                __pyx_1 = (!PyString_CheckExact(__pyx_v_ref_bit));
                if (__pyx_1) {
                  __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; goto __pyx_L1;}
                  Py_INCREF(__pyx_v_ref_bit);
                  PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_ref_bit);
                  __pyx_7 = PyObject_CallObject(((PyObject *)(&PyType_Type)), __pyx_2); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; goto __pyx_L1;}
                  Py_DECREF(__pyx_2); __pyx_2 = 0;
                  __pyx_2 = PyNumber_Remainder(__pyx_k37p, __pyx_7); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 952; goto __pyx_L1;}
                  Py_DECREF(__pyx_7); __pyx_7 = 0;
                  __pyx_7 = PyTuple_New(1); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; goto __pyx_L1;}
                  PyTuple_SET_ITEM(__pyx_7, 0, __pyx_2);
                  __pyx_2 = 0;
                  __pyx_2 = PyObject_CallObject(PyExc_TypeError, __pyx_7); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; goto __pyx_L1;}
                  Py_DECREF(__pyx_7); __pyx_7 = 0;
                  __Pyx_Raise(__pyx_2, 0, 0);
                  Py_DECREF(__pyx_2); __pyx_2 = 0;
                  {__pyx_filename = __pyx_f[0]; __pyx_lineno = 950; goto __pyx_L1;}
                  goto __pyx_L16;
                }
                __pyx_L16:;

                /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":953 */
                __pyx_v_refs_len = (__pyx_v_refs_len + PyString_GET_SIZE(__pyx_v_ref_bit));
              }
              Py_DECREF(__pyx_6); __pyx_6 = 0;
              goto __pyx_L13;
            }
            __pyx_L13:;
          }
          Py_DECREF(__pyx_3); __pyx_3 = 0;
          goto __pyx_L9;
        }
        __pyx_L9:;
      }
      Py_DECREF(__pyx_5); __pyx_5 = 0;
      goto __pyx_L6;
    }
    __pyx_L6:;
    goto __pyx_L5;
  }
  __pyx_L5:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":956 */
  __pyx_v_key_len = PyString_Size(__pyx_v_string_key);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":957 */
  __pyx_7 = __Pyx_GetItemInt(__pyx_v_node, 2); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 957; goto __pyx_L1;}
  Py_DECREF(__pyx_v_val);
  __pyx_v_val = __pyx_7;
  __pyx_7 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":958 */
  __pyx_1 = (!PyString_CheckExact(__pyx_v_val));
  if (__pyx_1) {
    __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; goto __pyx_L1;}
    Py_INCREF(__pyx_v_val);
    PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_val);
    __pyx_6 = PyObject_CallObject(((PyObject *)(&PyType_Type)), __pyx_2); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; goto __pyx_L1;}
    Py_DECREF(__pyx_2); __pyx_2 = 0;
    __pyx_3 = PyNumber_Remainder(__pyx_k38p, __pyx_6); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 960; goto __pyx_L1;}
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; goto __pyx_L1;}
    PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
    __pyx_3 = 0;
    __pyx_7 = PyObject_CallObject(PyExc_TypeError, __pyx_5); if (!__pyx_7) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; goto __pyx_L1;}
    Py_DECREF(__pyx_5); __pyx_5 = 0;
    __Pyx_Raise(__pyx_7, 0, 0);
    Py_DECREF(__pyx_7); __pyx_7 = 0;
    {__pyx_filename = __pyx_f[0]; __pyx_lineno = 959; goto __pyx_L1;}
    goto __pyx_L17;
  }
  __pyx_L17:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":961 */
  __pyx_v_value = PyString_AS_STRING(__pyx_v_val);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":962 */
  __pyx_v_value_len = PyString_GET_SIZE(__pyx_v_val);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":963 */
  __pyx_v_flat_len = (((((__pyx_v_key_len + 1) + __pyx_v_refs_len) + 1) + __pyx_v_value_len) + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":964 */
  __pyx_2 = PyString_FromStringAndSize(NULL,__pyx_v_flat_len); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 964; goto __pyx_L1;}
  Py_DECREF(__pyx_v_line);
  __pyx_v_line = __pyx_2;
  __pyx_2 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":966 */
  __pyx_8 = PyString_AsString(__pyx_v_line); if (__pyx_8 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 966; goto __pyx_L1;}
  __pyx_v_out = __pyx_8;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":967 */
  __pyx_8 = PyString_AsString(__pyx_v_string_key); if (__pyx_8 == NULL) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 967; goto __pyx_L1;}
  memcpy(__pyx_v_out,__pyx_8,__pyx_v_key_len);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":968 */
  __pyx_v_out = (__pyx_v_out + __pyx_v_key_len);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":969 */
  (__pyx_v_out[0]) = '\0';

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":970 */
  __pyx_v_out = (__pyx_v_out + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":971 */
  __pyx_1 = (__pyx_v_refs_len > 0);
  if (__pyx_1) {

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":972 */
    __pyx_v_first_ref_list = 1;

    /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":973 */
    __pyx_6 = PyObject_GetIter(__pyx_v_ref_lists); if (!__pyx_6) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; goto __pyx_L1;}
    for (;;) {
      __pyx_3 = PyIter_Next(__pyx_6);
      if (!__pyx_3) {
        if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 973; goto __pyx_L1;}
        break;
      }
      Py_DECREF(__pyx_v_ref_list);
      __pyx_v_ref_list = __pyx_3;
      __pyx_3 = 0;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":974 */
      __pyx_1 = (__pyx_v_first_ref_list == 0);
      if (__pyx_1) {

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":975 */
        (__pyx_v_out[0]) = '\t';

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":976 */
        __pyx_v_out = (__pyx_v_out + 1);
        goto __pyx_L21;
      }
      __pyx_L21:;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":977 */
      __pyx_v_first_ref_list = 0;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":978 */
      __pyx_v_first_reference = 1;

      /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":979 */
      __pyx_5 = PyObject_GetIter(__pyx_v_ref_list); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; goto __pyx_L1;}
      for (;;) {
        __pyx_7 = PyIter_Next(__pyx_5);
        if (!__pyx_7) {
          if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 979; goto __pyx_L1;}
          break;
        }
        Py_DECREF(__pyx_v_reference);
        __pyx_v_reference = __pyx_7;
        __pyx_7 = 0;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":980 */
        __pyx_1 = (__pyx_v_first_reference == 0);
        if (__pyx_1) {

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":981 */
          (__pyx_v_out[0]) = '\r';

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":982 */
          __pyx_v_out = (__pyx_v_out + 1);
          goto __pyx_L24;
        }
        __pyx_L24:;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":983 */
        __pyx_v_first_reference = 0;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":984 */
        __pyx_4 = PyObject_Length(__pyx_v_reference); if (__pyx_4 == -1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 984; goto __pyx_L1;}
        __pyx_v_next_len = __pyx_4;

        /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":985 */
        for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_next_len; ++__pyx_v_i) {

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":986 */
          __pyx_1 = (__pyx_v_i != 0);
          if (__pyx_1) {

            /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":987 */
            (__pyx_v_out[0]) = '\x000';

            /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":988 */
            __pyx_v_out = (__pyx_v_out + 1);
            goto __pyx_L27;
          }
          __pyx_L27:;

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":989 */
          __pyx_2 = __Pyx_GetItemInt(__pyx_v_reference, __pyx_v_i); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 989; goto __pyx_L1;}
          Py_DECREF(__pyx_v_ref_bit);
          __pyx_v_ref_bit = __pyx_2;
          __pyx_2 = 0;

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":990 */
          __pyx_v_ref_bit_len = PyString_GET_SIZE(__pyx_v_ref_bit);

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":991 */
          memcpy(__pyx_v_out,PyString_AS_STRING(__pyx_v_ref_bit),__pyx_v_ref_bit_len);

          /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":992 */
          __pyx_v_out = (__pyx_v_out + __pyx_v_ref_bit_len);
        }
      }
      Py_DECREF(__pyx_5); __pyx_5 = 0;
    }
    Py_DECREF(__pyx_6); __pyx_6 = 0;
    goto __pyx_L18;
  }
  __pyx_L18:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":993 */
  (__pyx_v_out[0]) = '\0';

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":994 */
  __pyx_v_out = (__pyx_v_out + 1);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":995 */
  memcpy(__pyx_v_out,__pyx_v_value,__pyx_v_value_len);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":996 */
  __pyx_v_out = (__pyx_v_out + __pyx_v_value_len);

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":997 */
  (__pyx_v_out[0]) = '\n';

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":998 */
  __pyx_3 = PyTuple_New(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 998; goto __pyx_L1;}
  Py_INCREF(__pyx_v_string_key);
  PyTuple_SET_ITEM(__pyx_3, 0, __pyx_v_string_key);
  Py_INCREF(__pyx_v_line);
  PyTuple_SET_ITEM(__pyx_3, 1, __pyx_v_line);
  __pyx_r = __pyx_3;
  __pyx_3 = 0;
  goto __pyx_L0;

  __pyx_r = Py_None; Py_INCREF(Py_None);
  goto __pyx_L0;
  __pyx_L1:;
  Py_XDECREF(__pyx_2);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_5);
  Py_XDECREF(__pyx_6);
  Py_XDECREF(__pyx_7);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx._flatten_node");
  __pyx_r = 0;
  __pyx_L0:;
  Py_DECREF(__pyx_v_string_key);
  Py_DECREF(__pyx_v_ref_lists);
  Py_DECREF(__pyx_v_ref_list);
  Py_DECREF(__pyx_v_reference);
  Py_DECREF(__pyx_v_ref_bit);
  Py_DECREF(__pyx_v_val);
  Py_DECREF(__pyx_v_line);
  Py_DECREF(__pyx_v_node);
  Py_DECREF(__pyx_v_reference_lists);
  return __pyx_r;
}
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser __pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;

static PyObject *__pyx_tp_new_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o);
  *(struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser **)&p->__pyx_vtab = __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
  p->bytes = Py_None; Py_INCREF(Py_None);
  p->keys = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyObject *o) {
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o;
  Py_XDECREF(p->bytes);
  Py_XDECREF(p->keys);
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o;
  if (p->bytes) {
    e = (*v)(p->bytes, a); if (e) return e;
  }
  if (p->keys) {
    e = (*v)(p->keys, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser(PyObject *o) {
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser *)o;
  PyObject *t;
  t = p->bytes; 
  p->bytes = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  t = p->keys; 
  p->keys = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}

static struct PyMethodDef __pyx_methods_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser[] = {
  {"parse", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_parse, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_BTreeLeafParser = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_BTreeLeafParser = {
  0, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  0, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  0, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_BTreeLeafParser = {
  0, /*mp_length*/
  0, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_BTreeLeafParser = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "bzrlib._btree_serializer_pyx.BTreeLeafParser", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_BTreeLeafParser, /*tp_as_number*/
  &__pyx_tp_as_sequence_BTreeLeafParser, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_BTreeLeafParser, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_BTreeLeafParser, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "Parse the leaf nodes of a BTree index.\n\n    :ivar bytes: The PyString object containing the uncompressed text for the\n        node.\n    :ivar key_length: An integer describing how many pieces the keys have for\n        this index.\n    :ivar ref_list_length: An integer describing how many references this index\n        contains.\n    :ivar keys: A PyList of keys found in this node.\n\n    :ivar _cur_str: A pointer to the start of the next line to parse\n    :ivar _end_str: A pointer to the end of bytes\n    :ivar _start: Pointer to the location within the current line while\n        parsing.\n    :ivar _header_found: True when we have parsed the header for this node\n    ", /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_methods*/
  0, /*tp_members*/
  0, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};
static struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode __pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;

static PyObject *__pyx_tp_new_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyTypeObject *t, PyObject *a, PyObject *k) {
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p;
  PyObject *o = (*t->tp_alloc)(t, 0);
  if (!o) return 0;
  p = ((struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o);
  *(struct __pyx_vtabstruct_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode **)&p->__pyx_vtab = __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
  p->last_key = Py_None; Py_INCREF(Py_None);
  return o;
}

static void __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o;
  {
    PyObject *etype, *eval, *etb;
    PyErr_Fetch(&etype, &eval, &etb);
    ++o->ob_refcnt;
    __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___dealloc__(o);
    if (PyErr_Occurred()) PyErr_WriteUnraisable(o);
    --o->ob_refcnt;
    PyErr_Restore(etype, eval, etb);
  }
  Py_XDECREF(p->last_key);
  (*o->ob_type->tp_free)(o);
}

static int __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o, visitproc v, void *a) {
  int e;
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o;
  if (p->last_key) {
    e = (*v)(p->last_key, a); if (e) return e;
  }
  return 0;
}

static int __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o) {
  struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *p = (struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode *)o;
  PyObject *t;
  t = p->last_key; 
  p->last_key = Py_None; Py_INCREF(Py_None);
  Py_XDECREF(t);
  return 0;
}
static PyObject *__pyx_sq_item_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode(PyObject *o, Py_ssize_t i) {
  PyObject *r;
  PyObject *x = PyInt_FromSsize_t(i); if(!x) return 0;
  r = o->ob_type->tp_as_mapping->mp_subscript(o, x);
  Py_DECREF(x);
  return r;
}

static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_min_key(PyObject *o, void *x) {
  return __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7min_key___get__(o);
}

static PyObject *__pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_max_key(PyObject *o, void *x) {
  return __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_7max_key___get__(o);
}

static struct PyMethodDef __pyx_methods_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode[] = {
  {"__sizeof__", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___sizeof__, METH_VARARGS|METH_KEYWORDS, 0},
  {"all_keys", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_all_keys, METH_VARARGS|METH_KEYWORDS, 0},
  {"all_items", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_all_items, METH_VARARGS|METH_KEYWORDS, 0},
  {"_get_offset_for_sha1", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__get_offset_for_sha1, METH_VARARGS|METH_KEYWORDS, 0},
  {"_get_offsets", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__get_offsets, METH_VARARGS|METH_KEYWORDS, 0},
  {0, 0, 0, 0}
};

static struct PyMemberDef __pyx_members_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode[] = {
  {"last_key", T_OBJECT, offsetof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, last_key), 0, 0},
  {"num_records", T_INT, offsetof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, num_records), 0, 0},
  {"common_shift", T_UBYTE, offsetof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, common_shift), 0, 0},
  {0, 0, 0, 0, 0}
};

static struct PyGetSetDef __pyx_getsets_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode[] = {
  {"min_key", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_min_key, 0, 0, 0},
  {"max_key", __pyx_getprop_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode_max_key, 0, 0, 0},
  {0, 0, 0, 0, 0}
};

static PyNumberMethods __pyx_tp_as_number_GCCHKSHA1LeafNode = {
  0, /*nb_add*/
  0, /*nb_subtract*/
  0, /*nb_multiply*/
  0, /*nb_divide*/
  0, /*nb_remainder*/
  0, /*nb_divmod*/
  0, /*nb_power*/
  0, /*nb_negative*/
  0, /*nb_positive*/
  0, /*nb_absolute*/
  0, /*nb_nonzero*/
  0, /*nb_invert*/
  0, /*nb_lshift*/
  0, /*nb_rshift*/
  0, /*nb_and*/
  0, /*nb_xor*/
  0, /*nb_or*/
  0, /*nb_coerce*/
  0, /*nb_int*/
  0, /*nb_long*/
  0, /*nb_float*/
  0, /*nb_oct*/
  0, /*nb_hex*/
  0, /*nb_inplace_add*/
  0, /*nb_inplace_subtract*/
  0, /*nb_inplace_multiply*/
  0, /*nb_inplace_divide*/
  0, /*nb_inplace_remainder*/
  0, /*nb_inplace_power*/
  0, /*nb_inplace_lshift*/
  0, /*nb_inplace_rshift*/
  0, /*nb_inplace_and*/
  0, /*nb_inplace_xor*/
  0, /*nb_inplace_or*/
  0, /*nb_floor_divide*/
  0, /*nb_true_divide*/
  0, /*nb_inplace_floor_divide*/
  0, /*nb_inplace_true_divide*/
  #if Py_TPFLAGS_DEFAULT & Py_TPFLAGS_HAVE_INDEX
  0, /*nb_index*/
  #endif
};

static PySequenceMethods __pyx_tp_as_sequence_GCCHKSHA1LeafNode = {
  __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___len__, /*sq_length*/
  0, /*sq_concat*/
  0, /*sq_repeat*/
  __pyx_sq_item_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*sq_item*/
  0, /*sq_slice*/
  0, /*sq_ass_item*/
  0, /*sq_ass_slice*/
  __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___contains__, /*sq_contains*/
  0, /*sq_inplace_concat*/
  0, /*sq_inplace_repeat*/
};

static PyMappingMethods __pyx_tp_as_mapping_GCCHKSHA1LeafNode = {
  __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___len__, /*mp_length*/
  __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___getitem__, /*mp_subscript*/
  0, /*mp_ass_subscript*/
};

static PyBufferProcs __pyx_tp_as_buffer_GCCHKSHA1LeafNode = {
  0, /*bf_getreadbuffer*/
  0, /*bf_getwritebuffer*/
  0, /*bf_getsegcount*/
  0, /*bf_getcharbuffer*/
};

PyTypeObject __pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = {
  PyObject_HEAD_INIT(0)
  0, /*ob_size*/
  "bzrlib._btree_serializer_pyx.GCCHKSHA1LeafNode", /*tp_name*/
  sizeof(struct __pyx_obj_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode), /*tp_basicsize*/
  0, /*tp_itemsize*/
  __pyx_tp_dealloc_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_dealloc*/
  0, /*tp_print*/
  0, /*tp_getattr*/
  0, /*tp_setattr*/
  0, /*tp_compare*/
  0, /*tp_repr*/
  &__pyx_tp_as_number_GCCHKSHA1LeafNode, /*tp_as_number*/
  &__pyx_tp_as_sequence_GCCHKSHA1LeafNode, /*tp_as_sequence*/
  &__pyx_tp_as_mapping_GCCHKSHA1LeafNode, /*tp_as_mapping*/
  0, /*tp_hash*/
  0, /*tp_call*/
  0, /*tp_str*/
  0, /*tp_getattro*/
  0, /*tp_setattro*/
  &__pyx_tp_as_buffer_GCCHKSHA1LeafNode, /*tp_as_buffer*/
  Py_TPFLAGS_DEFAULT|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/
  "Track all the entries for a given leaf node.", /*tp_doc*/
  __pyx_tp_traverse_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_traverse*/
  __pyx_tp_clear_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_clear*/
  0, /*tp_richcompare*/
  0, /*tp_weaklistoffset*/
  0, /*tp_iter*/
  0, /*tp_iternext*/
  __pyx_methods_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_methods*/
  __pyx_members_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_members*/
  __pyx_getsets_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_getset*/
  0, /*tp_base*/
  0, /*tp_dict*/
  0, /*tp_descr_get*/
  0, /*tp_descr_set*/
  0, /*tp_dictoffset*/
  __pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode___init__, /*tp_init*/
  0, /*tp_alloc*/
  __pyx_tp_new_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode, /*tp_new*/
  0, /*tp_free*/
  0, /*tp_is_gc*/
  0, /*tp_bases*/
  0, /*tp_mro*/
  0, /*tp_cache*/
  0, /*tp_subclasses*/
  0, /*tp_weaklist*/
};

static struct PyMethodDef __pyx_methods[] = {
  {"_parse_leaf_lines", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__parse_leaf_lines, METH_VARARGS|METH_KEYWORDS, 0},
  {"_py_unhexlify", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__py_unhexlify, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_unhexlify},
  {"_py_hexlify", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__py_hexlify, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_hexlify},
  {"_py_key_to_sha1", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__py_key_to_sha1, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_key_to_sha1},
  {"_py_sha1_to_key", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__py_sha1_to_key, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_21_btree_serializer_pyx__py_sha1_to_key},
  {"_parse_into_chk", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__parse_into_chk, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_21_btree_serializer_pyx__parse_into_chk},
  {"_flatten_node", (PyCFunction)__pyx_f_6bzrlib_21_btree_serializer_pyx__flatten_node, METH_VARARGS|METH_KEYWORDS, __pyx_doc_6bzrlib_21_btree_serializer_pyx__flatten_node},
  {0, 0, 0, 0}
};

static void __pyx_init_filenames(void); /*proto*/

PyMODINIT_FUNC init_btree_serializer_pyx(void); /*proto*/
PyMODINIT_FUNC init_btree_serializer_pyx(void) {
  PyObject *__pyx_1 = 0;
  int __pyx_2;
  PyObject *__pyx_3 = 0;
  PyObject *__pyx_4 = 0;
  PyObject *__pyx_5 = 0;
  __pyx_init_filenames();
  __pyx_m = Py_InitModule4("_btree_serializer_pyx", __pyx_methods, __pyx_mdoc, 0, PYTHON_API_VERSION);
  if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;};
  Py_INCREF(__pyx_m);
  __pyx_b = PyImport_AddModule("__builtin__");
  if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;};
  if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;};
  if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;};
  __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = &__pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.extract_key = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_extract_key;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.process_line = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_15BTreeLeafParser_process_line;
  __pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser.tp_dict, __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "BTreeLeafParser", (PyObject *)&__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 123; goto __pyx_L1;}
  __pyx_ptype_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser = &__pyx_type_6bzrlib_21_btree_serializer_pyx_BTreeLeafParser;
  __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = &__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._record_to_value_and_refs = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_value_and_refs;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._record_to_item = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__record_to_item;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._lookup_record = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__lookup_record;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._count_records = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__count_records;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._parse_bytes = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_bytes;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._parse_one_entry = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__parse_one_entry;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._offset_for_sha1 = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__offset_for_sha1;
  *(void(**)(void))&__pyx_vtable_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode._compute_common = (void(*)(void))__pyx_f_6bzrlib_21_btree_serializer_pyx_17GCCHKSHA1LeafNode__compute_common;
  __pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode.tp_free = _PyObject_GC_Del;
  if (PyType_Ready(&__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; goto __pyx_L1;}
  if (__Pyx_SetVtable(__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode.tp_dict, __pyx_vtabptr_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; goto __pyx_L1;}
  if (PyObject_SetAttrString(__pyx_m, "GCCHKSHA1LeafNode", (PyObject *)&__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 534; goto __pyx_L1;}
  __pyx_ptype_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode = &__pyx_type_6bzrlib_21_btree_serializer_pyx_GCCHKSHA1LeafNode;
  __pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple = __Pyx_ImportType("bzrlib._static_tuple_c", "StaticTuple", sizeof(StaticTuple)); if (!__pyx_ptype_6bzrlib_15_static_tuple_c_StaticTuple) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 26; goto __pyx_L1;}

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":77 */
  __pyx_1 = __Pyx_Import(__pyx_n_sys, 0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; goto __pyx_L1;}
  if (PyObject_SetAttr(__pyx_m, __pyx_n_sys, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 77; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":120 */
  __pyx_2 = import_static_tuple_c(); if (__pyx_2 == (-1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 120; goto __pyx_L1;}

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":347 */
  __pyx_v_6bzrlib_21_btree_serializer_pyx__hexbuf = __pyx_k40;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":359 */
  __pyx_1 = __pyx_f_6bzrlib_21_btree_serializer_pyx__populate_unhexbuf(); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 359; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":529 */
  __pyx_v_6bzrlib_21_btree_serializer_pyx__record_formatter = __pyx_f_6bzrlib_21_btree_serializer_pyx__format_record;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":530 */
  __pyx_1 = __Pyx_GetName(__pyx_m, __pyx_n_sys); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  __pyx_3 = PyObject_GetAttr(__pyx_1, __pyx_n_version_info); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  __pyx_1 = PySequence_GetSlice(__pyx_3, 0, 2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  Py_DECREF(__pyx_3); __pyx_3 = 0;
  __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  __pyx_4 = PyInt_FromLong(4); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3);
  PyTuple_SET_ITEM(__pyx_5, 1, __pyx_4);
  __pyx_3 = 0;
  __pyx_4 = 0;
  if (PyObject_Cmp(__pyx_1, __pyx_5, &__pyx_2) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 530; goto __pyx_L1;}
  __pyx_2 = __pyx_2 == 0;
  Py_DECREF(__pyx_1); __pyx_1 = 0;
  Py_DECREF(__pyx_5); __pyx_5 = 0;
  if (__pyx_2) {
    __pyx_v_6bzrlib_21_btree_serializer_pyx__record_formatter = __pyx_f_6bzrlib_21_btree_serializer_pyx__format_record_py24;
    goto __pyx_L28;
  }
  __pyx_L28:;

  /* "/home/vila/src/bzr/integration/2.3b5-dev/bzrlib/_btree_serializer_pyx.pyx":861 */
  return;
  __pyx_L1:;
  Py_XDECREF(__pyx_1);
  Py_XDECREF(__pyx_3);
  Py_XDECREF(__pyx_4);
  Py_XDECREF(__pyx_5);
  __Pyx_AddTraceback("bzrlib._btree_serializer_pyx");
}

static char *__pyx_filenames[] = {
  "_btree_serializer_pyx.pyx",
  "_static_tuple_c.pxd",
};

/* Runtime support code */

static void __pyx_init_filenames(void) {
  __pyx_f = __pyx_filenames;
}

static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) {
    Py_XINCREF(type);
    Py_XINCREF(value);
    Py_XINCREF(tb);
    /* First, check the traceback argument, replacing None with NULL. */
    if (tb == Py_None) {
        Py_DECREF(tb);
        tb = 0;
    }
    else if (tb != NULL && !PyTraceBack_Check(tb)) {
        PyErr_SetString(PyExc_TypeError,
            "raise: arg 3 must be a traceback or None");
        goto raise_error;
    }
    /* Next, replace a missing value with None */
    if (value == NULL) {
        value = Py_None;
        Py_INCREF(value);
    }
    #if PY_VERSION_HEX < 0x02050000
    if (!PyClass_Check(type))
    #else
    if (!PyType_Check(type))
    #endif
    {
        /* Raising an instance.  The value should be a dummy. */
        if (value != Py_None) {
            PyErr_SetString(PyExc_TypeError,
                "instance exception may not have a separate value");
            goto raise_error;
        }
        /* Normalize to raise <class>, <instance> */
        Py_DECREF(value);
        value = type;
        #if PY_VERSION_HEX < 0x02050000
            if (PyInstance_Check(type)) {
                type = (PyObject*) ((PyInstanceObject*)type)->in_class;
                Py_INCREF(type);
            }
            else {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception must be an old-style class or instance");
                goto raise_error;
            }
        #else
            type = (PyObject*) type->ob_type;
            Py_INCREF(type);
            if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) {
                PyErr_SetString(PyExc_TypeError,
                    "raise: exception class must be a subclass of BaseException");
                goto raise_error;
            }
        #endif
    }
    PyErr_Restore(type, value, tb);
    return;
raise_error:
    Py_XDECREF(value);
    Py_XDECREF(type);
    Py_XDECREF(tb);
    return;
}

static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) {
    if (!type) {
        PyErr_Format(PyExc_SystemError, "Missing type object");
        return 0;
    }
    if (obj == Py_None || PyObject_TypeCheck(obj, type))
        return 1;
    PyErr_Format(PyExc_TypeError, "Cannot convert %s to %s",
        obj->ob_type->tp_name, type->tp_name);
    return 0;
}

static void __Pyx_WriteUnraisable(char *name) {
    PyObject *old_exc, *old_val, *old_tb;
    PyObject *ctx;
    PyErr_Fetch(&old_exc, &old_val, &old_tb);
    ctx = PyString_FromString(name);
    PyErr_Restore(old_exc, old_val, old_tb);
    if (!ctx)
        ctx = Py_None;
    PyErr_WriteUnraisable(ctx);
}

static PyObject *__Pyx_GetItemInt(PyObject *o, Py_ssize_t i) {
    PyTypeObject *t = o->ob_type;
    PyObject *r;
    if (t->tp_as_sequence && t->tp_as_sequence->sq_item)
        r = PySequence_GetItem(o, i);
    else {
        PyObject *j = PyInt_FromLong(i);
        if (!j)
            return 0;
        r = PyObject_GetItem(o, j);
        Py_DECREF(j);
    }
    return r;
}

static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) {
    while (t->p) {
        *t->p = PyString_FromStringAndSize(t->s, t->n - 1);
        if (!*t->p)
            return -1;
        if (t->i)
            PyString_InternInPlace(t->p);
        ++t;
    }
    return 0;
}

static int __Pyx_SetVtable(PyObject *dict, void *vtable) {
    PyObject *pycobj = 0;
    int result;
    
    pycobj = PyCObject_FromVoidPtr(vtable, 0);
    if (!pycobj)
        goto bad;
    if (PyDict_SetItemString(dict, "__pyx_vtable__", pycobj) < 0)
        goto bad;
    result = 0;
    goto done;

bad:
    result = -1;
done:
    Py_XDECREF(pycobj);
    return result;
}

#ifndef __PYX_HAVE_RT_ImportType
#define __PYX_HAVE_RT_ImportType
static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, 
    long size) 
{
    PyObject *py_module = 0;
    PyObject *result = 0;
    
    py_module = __Pyx_ImportModule(module_name);
    if (!py_module)
        goto bad;
    result = PyObject_GetAttrString(py_module, class_name);
    if (!result)
        goto bad;
    if (!PyType_Check(result)) {
        PyErr_Format(PyExc_TypeError, 
            "%s.%s is not a type object",
            module_name, class_name);
        goto bad;
    }
    if (((PyTypeObject *)result)->tp_basicsize != size) {
        PyErr_Format(PyExc_ValueError, 
            "%s.%s does not appear to be the correct type object",
            module_name, class_name);
        goto bad;
    }
    return (PyTypeObject *)result;
bad:
    Py_XDECREF(result);
    return 0;
}
#endif

#ifndef __PYX_HAVE_RT_ImportModule
#define __PYX_HAVE_RT_ImportModule
static PyObject *__Pyx_ImportModule(char *name) {
    PyObject *py_name = 0;
    
    py_name = PyString_FromString(name);
    if (!py_name)
        goto bad;
    return PyImport_Import(py_name);
bad:
    Py_XDECREF(py_name);
    return 0;
}
#endif

static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list) {
    PyObject *__import__ = 0;
    PyObject *empty_list = 0;
    PyObject *module = 0;
    PyObject *global_dict = 0;
    PyObject *empty_dict = 0;
    PyObject *list;
    __import__ = PyObject_GetAttrString(__pyx_b, "__import__");
    if (!__import__)
        goto bad;
    if (from_list)
        list = from_list;
    else {
        empty_list = PyList_New(0);
        if (!empty_list)
            goto bad;
        list = empty_list;
    }
    global_dict = PyModule_GetDict(__pyx_m);
    if (!global_dict)
        goto bad;
    empty_dict = PyDict_New();
    if (!empty_dict)
        goto bad;
    module = PyObject_CallFunction(__import__, "OOOO",
        name, global_dict, empty_dict, list);
bad:
    Py_XDECREF(empty_list);
    Py_XDECREF(__import__);
    Py_XDECREF(empty_dict);
    return module;
}

static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) {
    PyObject *result;
    result = PyObject_GetAttr(dict, name);
    if (!result)
        PyErr_SetObject(PyExc_NameError, name);
    return result;
}

#include "compile.h"
#include "frameobject.h"
#include "traceback.h"

static void __Pyx_AddTraceback(char *funcname) {
    PyObject *py_srcfile = 0;
    PyObject *py_funcname = 0;
    PyObject *py_globals = 0;
    PyObject *empty_tuple = 0;
    PyObject *empty_string = 0;
    PyCodeObject *py_code = 0;
    PyFrameObject *py_frame = 0;
    
    py_srcfile = PyString_FromString(__pyx_filename);
    if (!py_srcfile) goto bad;
    py_funcname = PyString_FromString(funcname);
    if (!py_funcname) goto bad;
    py_globals = PyModule_GetDict(__pyx_m);
    if (!py_globals) goto bad;
    empty_tuple = PyTuple_New(0);
    if (!empty_tuple) goto bad;
    empty_string = PyString_FromString("");
    if (!empty_string) goto bad;
    py_code = PyCode_New(
        0,            /*int argcount,*/
        0,            /*int nlocals,*/
        0,            /*int stacksize,*/
        0,            /*int flags,*/
        empty_string, /*PyObject *code,*/
        empty_tuple,  /*PyObject *consts,*/
        empty_tuple,  /*PyObject *names,*/
        empty_tuple,  /*PyObject *varnames,*/
        empty_tuple,  /*PyObject *freevars,*/
        empty_tuple,  /*PyObject *cellvars,*/
        py_srcfile,   /*PyObject *filename,*/
        py_funcname,  /*PyObject *name,*/
        __pyx_lineno,   /*int firstlineno,*/
        empty_string  /*PyObject *lnotab*/
    );
    if (!py_code) goto bad;
    py_frame = PyFrame_New(
        PyThreadState_Get(), /*PyThreadState *tstate,*/
        py_code,             /*PyCodeObject *code,*/
        py_globals,          /*PyObject *globals,*/
        0                    /*PyObject *locals*/
    );
    if (!py_frame) goto bad;
    py_frame->f_lineno = __pyx_lineno;
    PyTraceBack_Here(py_frame);
bad:
    Py_XDECREF(py_srcfile);
    Py_XDECREF(py_funcname);
    Py_XDECREF(empty_tuple);
    Py_XDECREF(empty_string);
    Py_XDECREF(py_code);
    Py_XDECREF(py_frame);
}
