Skip to content

Commit f989fcf

Browse files
committed
Addressing review (to be squashed).
1 parent b424d7f commit f989fcf

File tree

1 file changed

+30
-10
lines changed

1 file changed

+30
-10
lines changed

gcloud/bigtable/happybase/table.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,10 +580,7 @@ def _next_char(str_val, index):
580580
:returns: The next character after the character at ``index``
581581
in ``str_val``.
582582
"""
583-
if six.PY3: # pragma: NO COVER
584-
ord_val = str_val[index]
585-
else:
586-
ord_val = ord(str_val[index])
583+
ord_val = six.indexbytes(str_val, index)
587584
return _to_bytes(chr(ord_val + 1), encoding='latin-1')
588585

589586

@@ -611,12 +608,8 @@ def _string_successor(str_val):
611608

612609
index = len(str_val) - 1
613610
while index >= 0:
614-
if six.PY3: # pragma: NO COVER
615-
if str_val[index] != 0xff:
616-
break
617-
else:
618-
if str_val[index] != b'\xff':
619-
break
611+
if six.indexbytes(str_val, index) != 0xff:
612+
break
620613
index -= 1
621614

622615
if index == -1:
@@ -651,6 +644,17 @@ def _convert_to_time_range(timestamp=None):
651644
def _cells_to_pairs(cells, include_timestamp=False):
652645
"""Converts list of cells to HappyBase format.
653646
647+
For example::
648+
649+
>>> import datetime
650+
>>> from gcloud.bigtable.row_data import Cell
651+
>>> cell1 = Cell(b'val1', datetime.datetime.utcnow())
652+
>>> cell2 = Cell(b'val2', datetime.datetime.utcnow())
653+
>>> _cells_to_pairs([cell1, cell2])
654+
[b'val1', b'val2']
655+
>>> _cells_to_pairs([cell1, cell2], include_timestamp=True)
656+
[(b'val1', 1456361486255), (b'val2', 1456361491927)]
657+
654658
:type cells: list
655659
:param cells: List of :class:`.Cell` returned from a read request.
656660
@@ -681,6 +685,22 @@ def _partial_row_to_dict(partial_row_data, include_timestamp=False):
681685
is due to the fact that this method is used by callers which use
682686
a ``CellsColumnLimitFilter(1)`` filter.
683687
688+
For example::
689+
690+
>>> import datetime
691+
>>> from gcloud.bigtable.row_data import Cell, PartialRowData
692+
>>> cell1 = Cell(b'val1', datetime.datetime.utcnow())
693+
>>> cell2 = Cell(b'val2', datetime.datetime.utcnow())
694+
>>> row_data = PartialRowData(b'row-key')
695+
>>> _partial_row_to_dict(row_data)
696+
{}
697+
>>> row_data._cells[u'fam1'] = {b'col1': [cell1], b'col2': [cell2]}
698+
>>> _partial_row_to_dict(row_data)
699+
{b'fam1:col2': b'val2', b'fam1:col1': b'val1'}
700+
>>> _partial_row_to_dict(row_data, include_timestamp=True)
701+
{b'fam1:col2': (b'val2', 1456361724480),
702+
b'fam1:col1': (b'val1', 1456361721135)}
703+
684704
:type partial_row_data: :class:`.row_data.PartialRowData`
685705
:param partial_row_data: Row data consumed from a stream.
686706

0 commit comments

Comments
 (0)