Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions generated/nidaqmx/_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def __getattr__(self, function):
"""


def get_encoding_from_locale():
"""
Gets the current locale encoding handling cases where it is unset.
"""
_, encoding = locale.getlocale()
return encoding or 'ascii'


class DaqLibImporter:
"""
Encapsulates NI-DAQmx library importing and handle type parsing logic.
Expand Down Expand Up @@ -157,7 +165,7 @@ def encoding(self):
if self._encoding is None:
self._import_lib()
return self._encoding

def _import_lib(self):
"""
Determines the location of and loads the NI-DAQmx CAI DLL.
Expand Down Expand Up @@ -185,7 +193,7 @@ def _load_lib(libname: str):
try:
if nidaqmx_c_library=="nicaiu":
windll, cdll = _load_lib("nicaiu")
encoding = locale.getlocale()[1]
encoding = get_encoding_from_locale()
elif nidaqmx_c_library=="nicai_utf8":
windll, cdll = _load_lib("nicai_utf8")
encoding = 'utf-8'
Expand All @@ -201,15 +209,15 @@ def _load_lib(libname: str):
# Fallback to nicaiu.dll if nicai_utf8.dll cannot be loaded
try:
windll, cdll = _load_lib("nicaiu")
encoding = locale.getlocale()[1]
encoding = get_encoding_from_locale()
except (OSError, WindowsError) as e:
raise DaqNotFoundError(_DAQ_NOT_FOUND_MESSAGE) from e
elif sys.platform.startswith('linux'):
library_path = find_library('nidaqmx')
if library_path is not None:
cdll = ctypes.cdll.LoadLibrary(library_path)
windll = cdll
encoding = locale.getlocale()[1]
encoding = get_encoding_from_locale()
else:
raise DaqNotFoundError(_DAQ_NOT_FOUND_MESSAGE)
else:
Expand Down
16 changes: 12 additions & 4 deletions src/handwritten/_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ def __getattr__(self, function):
"""


def get_encoding_from_locale():
"""
Gets the current locale encoding handling cases where it is unset.
"""
_, encoding = locale.getlocale()
return encoding or 'ascii'


class DaqLibImporter:
"""
Encapsulates NI-DAQmx library importing and handle type parsing logic.
Expand Down Expand Up @@ -157,7 +165,7 @@ def encoding(self):
if self._encoding is None:
self._import_lib()
return self._encoding

def _import_lib(self):
"""
Determines the location of and loads the NI-DAQmx CAI DLL.
Expand Down Expand Up @@ -185,7 +193,7 @@ def _load_lib(libname: str):
try:
if nidaqmx_c_library=="nicaiu":
windll, cdll = _load_lib("nicaiu")
encoding = locale.getlocale()[1]
encoding = get_encoding_from_locale()
elif nidaqmx_c_library=="nicai_utf8":
windll, cdll = _load_lib("nicai_utf8")
encoding = 'utf-8'
Expand All @@ -201,15 +209,15 @@ def _load_lib(libname: str):
# Fallback to nicaiu.dll if nicai_utf8.dll cannot be loaded
try:
windll, cdll = _load_lib("nicaiu")
encoding = locale.getlocale()[1]
encoding = get_encoding_from_locale()
except (OSError, WindowsError) as e:
raise DaqNotFoundError(_DAQ_NOT_FOUND_MESSAGE) from e
elif sys.platform.startswith('linux'):
library_path = find_library('nidaqmx')
if library_path is not None:
cdll = ctypes.cdll.LoadLibrary(library_path)
windll = cdll
encoding = locale.getlocale()[1]
encoding = get_encoding_from_locale()
else:
raise DaqNotFoundError(_DAQ_NOT_FOUND_MESSAGE)
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/acceptance/test_internationalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pytest

from nidaqmx._lib import lib_importer
from nidaqmx._lib import lib_importer, get_encoding_from_locale
from nidaqmx.error_codes import DAQmxErrors
from nidaqmx.errors import DaqError
from nidaqmx.system import Device
Expand All @@ -20,7 +20,7 @@ def ai_task(task, sim_6363_device):
def _get_encoding(obj: Union[Task, Dict[str, Any]]) -> Optional[str]:
if getattr(obj, "_grpc_options", None) or (isinstance(obj, dict) and "grpc_options" in obj):
# gRPC server limited to MBCS encoding
return locale.getlocale()[1]
return get_encoding_from_locale()
else:
return lib_importer.encoding

Expand Down
Loading