3535import os
3636import re
3737import sys
38+ import warnings
3839
3940from . import environment
4041
@@ -505,8 +506,8 @@ def __init__(self, ofile, maxresultrows=None):
505506
506507 self ._inspector = OrderedDict ()
507508 self ._chunk_count = 0
508- self ._record_count = 0
509- self ._total_record_count = 0
509+ self ._pending_record_count = 0
510+ self ._committed_record_count = 0
510511
511512 @property
512513 def is_flushed (self ):
@@ -524,6 +525,30 @@ def ofile(self):
524525 def ofile (self , value ):
525526 self ._ofile = set_binary_mode (value )
526527
528+ @property
529+ def pending_record_count (self ):
530+ return self ._pending_record_count
531+
532+ @property
533+ def _record_count (self ):
534+ warnings .warn (
535+ "_record_count will be deprecated soon. Use pending_record_count instead." ,
536+ PendingDeprecationWarning
537+ )
538+ return self .pending_record_count
539+
540+ @property
541+ def committed_record_count (self ):
542+ return self ._committed_record_count
543+
544+ @property
545+ def _total_record_count (self ):
546+ warnings .warn (
547+ "_total_record_count will be deprecated soon. Use committed_record_count instead." ,
548+ PendingDeprecationWarning
549+ )
550+ return self .committed_record_count
551+
527552 def write (self , data ):
528553 bytes_type = bytes if sys .version_info >= (3 , 0 ) else str
529554 if not isinstance (data , bytes_type ):
@@ -555,7 +580,7 @@ def _clear(self):
555580 self ._buffer .seek (0 )
556581 self ._buffer .truncate ()
557582 self ._inspector .clear ()
558- self ._record_count = 0
583+ self ._pending_record_count = 0
559584
560585 def _ensure_validity (self ):
561586 if self ._finished is True :
@@ -650,9 +675,9 @@ def _write_record(self, record):
650675 values += (repr (value ), None )
651676
652677 self ._writerow (values )
653- self ._record_count += 1
678+ self ._pending_record_count += 1
654679
655- if self ._record_count >= self ._maxresultrows :
680+ if self .pending_record_count >= self ._maxresultrows :
656681 self .flush (partial = True )
657682
658683 try :
@@ -689,7 +714,7 @@ def flush(self, finished=None, partial=None):
689714
690715 RecordWriter .flush (self , finished , partial ) # validates arguments and the state of this instance
691716
692- if self ._record_count > 0 or (self ._chunk_count == 0 and 'messages' in self ._inspector ):
717+ if self .pending_record_count > 0 or (self ._chunk_count == 0 and 'messages' in self ._inspector ):
693718
694719 messages = self ._inspector .get ('messages' )
695720
@@ -727,9 +752,9 @@ def flush(self, finished=None, partial=None):
727752 print (level , text , file = stderr )
728753
729754 self .write (self ._buffer .getvalue ())
730- self ._clear ()
731755 self ._chunk_count += 1
732- self ._total_record_count += self ._record_count
756+ self ._committed_record_count += self .pending_record_count
757+ self ._clear ()
733758
734759 self ._finished = finished is True
735760
@@ -758,25 +783,22 @@ def flush(self, finished=None, partial=None):
758783
759784 def write_chunk (self , finished = None ):
760785 inspector = self ._inspector
761- self ._total_record_count += self ._record_count
786+ self ._committed_record_count += self .pending_record_count
762787 self ._chunk_count += 1
763788
764789 # TODO: DVPL-6448: splunklib.searchcommands | Add support for partial: true when it is implemented in
765790 # ChunkedExternProcessor (See SPL-103525)
766791 #
767792 # We will need to replace the following block of code with this block:
768793 #
769- # metadata = [
770- # ('inspector', self._inspector if len(self._inspector) else None),
771- # ('finished', finished),
772- # ('partial', partial)]
794+ # metadata = [item for item in (('inspector', inspector), ('finished', finished), ('partial', partial))]
795+ #
796+ # if partial is True:
797+ # finished = False
773798
774799 if len (inspector ) == 0 :
775800 inspector = None
776801
777- #if partial is True:
778- # finished = False
779-
780802 metadata = [item for item in (('inspector' , inspector ), ('finished' , finished ))]
781803 self ._write_chunk (metadata , self ._buffer .getvalue ())
782804 self ._clear ()
@@ -794,7 +816,7 @@ def write_metric(self, name, value):
794816 self ._inspector ['metric.' + name ] = value
795817
796818 def _clear (self ):
797- RecordWriter ._clear (self )
819+ super () ._clear ()
798820 self ._fieldnames = None
799821
800822 def _write_chunk (self , metadata , body ):
0 commit comments