Skip to content

Conversation

@oleksandrivantsiv
Copy link
Contributor

Decode data from redis DB into UTF-8 in python3.

Decode data from redis DB into UTF-8 in python3.
import time
from .dbconnector import SonicV2Connector

PY3K = sys.version_info >= (3, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

K [](start = 3, length = 1)

What does K mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

py3k is py3000, py3.0 same meaning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears "Python 3000" (or "py3k") was the initial name for what was eventually changed to "Python 3.0" to keep in line with the old versioning scheme before its actual release. I wasn't aware of the early name, and others might not be, either. We can always change it to "PY3X" or similar in the future.

Whatever we choose, we should probably use the same convention in all of our scripts whenever we need to make them compatible with both Python 2 and Python 3.

for key in raw_data:
for raw_key in raw_data:
key = raw_key
if PY3K:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PY3K [](start = 15, length = 4)

Why we need to check python3? Is it possible not to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Library supposes to work with Python 2 and 3. Current implementation doesn't handle encoding correctly in Python 3. Python 2 has different API to works with encoding than Python 3. So it is not possible to not check.

@lguohan lguohan merged commit a0418a1 into sonic-net:master Dec 14, 2017
praveen-li pushed a commit to praveen-li/sonic-py-swsssdk that referenced this pull request May 4, 2021
* msft_github/master:
  [configdb]: Addopt get_table method to work with python3. (sonic-net#26)
  [configdb]: add mod_entry, rename set_config to mod_config (sonic-net#25)
  [configdb] fix bug of leaving unwanted columns in a hash (sonic-net#23)
  Revert "Add support to remove the key of table entry (sonic-net#15)" (sonic-net#24)
  Add support to remove the key of table entry (sonic-net#15)
  [configdb] support redis connecting methods other than TCP (sonic-net#22)
  [interface]: Extend the max data wait time to 60s (sonic-net#21)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants