Changeset 200 for trunk/python2


Ignore:
Timestamp:
06/03/10 01:08:20 (15 years ago)
Author:
tim
Message:

redesigned python key iterator and test script
updated documentation

Location:
trunk/python2/regfi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/python2/regfi/pyregfi.h

    r199 r200  
    4949CLASS(KeyIterator, Object)
    5050     PRIVATE REGFI_ITERATOR *iter;
    51      PRIVATE bool first_called;
     51     PRIVATE bool root_traversed;
    5252
    5353     KeyIterator METHOD(KeyIterator, Con, struct RegistryFile_t *file, char **path,
     
    5656     struct ValueIterator_t *METHOD(KeyIterator, list_values);
    5757
    58      KeyIterator METHOD(KeyIterator, __iter__);
    59      REGFI_NK_REC *METHOD(KeyIterator, iternext);
     58     void METHOD(KeyIterator, __iter__);
     59     BORROWED REGFI_NK_REC *METHOD(KeyIterator, iternext);
    6060
    6161     int METHOD(KeyIterator, down);
     
    7171
    7272     void METHOD(ValueIterator, __iter__);
    73      RawData METHOD(ValueIterator, iternext);
     73     REGFI_VK_REC *METHOD(ValueIterator, iternext);
    7474END_CLASS
    7575
  • trunk/python2/regfi/regfi.c

    r199 r200  
    3030
    3131  if(!self->reg) {
    32     /*RaiseError(ERuntimeError, "REGFI Error: %s", regfi_log_get_str());*/
     32    RaiseError(ERuntimeError, "REGFI Error: %s", regfi_log_get_str());
    3333    /*char* e = regfi_log_get_str();*/
    3434    /*fprintf(stderr, "%p\n", e);*/
     
    6161}
    6262
    63 static KeyIterator KeyIterator_Con(KeyIterator self, RegistryFile file, char **path,
    64                              REGFI_ENCODING encoding) {
     63static KeyIterator KeyIterator_Con(KeyIterator self,
     64                                   RegistryFile file,
     65                                   char **path,
     66                                   REGFI_ENCODING encoding)
     67{
    6568  self->iter = regfi_iterator_new(file->reg, encoding);
    6669
     
    8083  }
    8184
    82   fprintf(stderr, "Con called\n");
    83   self->first_called = false;
     85  self->root_traversed = false;
    8486
    8587  return self;
     
    8890}
    8991
    90 static KeyIterator KeyIterator__iter__(KeyIterator self) {
    91   return self;
    92 }
    93 
    94 
    95 static const REGFI_NK_REC* KeyIterator_next(KeyIterator self) {
    96 
    97   fprintf(stderr, "next called\n");
    98 
    99   if(!self->first_called)
     92static void KeyIterator__iter__(KeyIterator self)
     93{
     94  return;
     95}
     96
     97
     98static const REGFI_NK_REC *KeyIterator_next(KeyIterator self)
     99{
     100  if(!self->root_traversed)
     101    self->root_traversed = true;
     102  else if(!regfi_iterator_down(self->iter))
    100103  {
    101     regfi_iterator_first_subkey(self->iter);
    102     self->first_called = true;
    103   }
    104   else
    105     regfi_iterator_next_subkey(self->iter);
    106    
    107   return regfi_iterator_cur_subkey(self->iter);
     104    do
     105    {
     106      if(!regfi_iterator_up(self->iter))
     107        return NULL;
     108    } while(!regfi_iterator_next_subkey(self->iter));
     109
     110    /* XXX: This is an error condition. 
     111     *      Probably should throw an exception or something. */
     112    if(!regfi_iterator_down(self->iter))
     113      return NULL;
     114  }
     115
     116  regfi_iterator_first_subkey(self->iter);
     117  return regfi_iterator_cur_key(self->iter);
    108118}
    109119
    110120
    111121static int KeyIterator_down(KeyIterator self) {
    112   fprintf(stderr, "down cur_subkey: %d\n", self->iter->cur_subkey);
    113122  int result = regfi_iterator_down(self->iter);
    114   fprintf(stderr, "down result: %d\n", result);
    115123  regfi_iterator_first_subkey(self->iter);
    116124  regfi_iterator_first_value(self->iter);
     
    153161}
    154162
    155 static ValueIterator ValueIterator__iter__(ValueIterator self) {
    156   return self;
    157 }
    158 
    159 static RawData ValueIterator_iternext(ValueIterator self) {
     163static void ValueIterator__iter__(ValueIterator self) {
     164  return;
     165}
     166
     167static REGFI_VK_REC* ValueIterator_iternext(ValueIterator self) {
    160168  RawData result;
    161169  const REGFI_DATA* data;
     
    172180  rec = regfi_iterator_cur_value(self->iter);
    173181
     182  return rec;
     183
    174184  if(!rec) return NULL;
    175185
     
    177187   *      Instead, make data fetching a method and parse it then.
    178188   */
     189  /*
    179190  data = (REGFI_DATA *)regfi_iterator_fetch_data(self->iter, rec);
    180191  if(!data) {
     
    198209    break;
    199210  }
     211  */
    200212
    201213  return result;
Note: See TracChangeset for help on using the changeset viewer.