Skip to content

Commit

Permalink
0.8.7
Browse files Browse the repository at this point in the history
  • Loading branch information
akarneliuk committed Aug 10, 2022
1 parent e550fb4 commit 673b991
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Dev Log

Release **0.8.7**:

- Fixed bug, when returned ``json_val`` or ``json_ietf_val`` is not processed correctly if the value is empty string.
- Fixed bug, when returned ``json_val`` or ``json_ietf_val`` is not processed correctly if the value is empty string. Fix for `Issue 58 <https://github.com/akarneliuk/pygnmi/issues/58>`_.

Release **0.8.6**:

Expand Down
23 changes: 19 additions & 4 deletions pygnmi/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import time
import threading
import os
from typing import Any
import cryptography
import grpc
from pygnmi.spec.v080.gnmi_pb2_grpc import gNMIStub
Expand Down Expand Up @@ -438,12 +439,10 @@ def get(self, prefix: str = "", path: list = None,
# Message Update, Key val
if update_msg.HasField('val'):
if update_msg.val.HasField('json_ietf_val'):
processed_val = json.loads(update_msg.val.json_ietf_val) if update_msg.val.json_ietf_val else None
update_container.update({'val': processed_val})
update_container.update({'val': process_potentially_json_value(update_msg.val.json_ietf_val)})

elif update_msg.val.HasField('json_val'):
processed_val = json.loads(update_msg.val.json_val) if update_msg.val.json_val else None
update_container.update({'val': processed_val})
update_container.update({'val': process_potentially_json_value(update_msg.val.json_val)})

elif update_msg.val.HasField('string_val'):
update_container.update({'val': update_msg.val.string_val})
Expand Down Expand Up @@ -1244,8 +1243,24 @@ def telemetryParser(in_message=None, debug: bool = False):


def debug_gnmi_msg(is_printable, what_to_print, message_name) -> None:
"""This helper function prints debug output"""
if is_printable:
print(message_name)
print("-" * os.get_terminal_size().columns)
print(what_to_print)
print("-" * os.get_terminal_size().columns, end="\n\n\n")


def process_potentially_json_value(input_val) -> Any:
"""This helper method converts value from bytestream"""
unprocessed_value = input_val.decode(encoding="utf-8")

if unprocessed_value:
try:
processed_val = json.loads(unprocessed_value)
except json.decoder.JSONDecodeError:
processed_val = unprocessed_value
else:
processed_val = None

return processed_val

0 comments on commit 673b991

Please sign in to comment.