Skip to content

Commit cd875ef

Browse files
ZLeventerclaude
andcommitted
Replace double-underscore prefixes with single underscore (fixes #29)
Python's double underscore prefix triggers name mangling, which is inappropriate for regular private functions and methods. Renamed all non-dunder `__` prefixed functions/methods to single underscore `_` across encoder.py, decoder.py, and client.py. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 094397b commit cd875ef

3 files changed

Lines changed: 44 additions & 44 deletions

File tree

linkedin_api/clients/restli/client.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get(
9696

9797
encoded_query_param_string = encode_query_params_for_get_requests(query_params)
9898

99-
return self.__send_and_format_response(
99+
return self._send_and_format_response(
100100
restli_method=RESTLI_METHODS.GET,
101101
resource_path=resource_path,
102102
path_keys=path_keys,
@@ -147,7 +147,7 @@ def batch_get(
147147
query_params_final
148148
)
149149

150-
return self.__send_and_format_response(
150+
return self._send_and_format_response(
151151
restli_method=RESTLI_METHODS.BATCH_GET,
152152
resource_path=resource_path,
153153
path_keys=path_keys,
@@ -194,7 +194,7 @@ def get_all(
194194
"""
195195
encoded_query_param_string = encode_query_params_for_get_requests(query_params)
196196

197-
return self.__send_and_format_response(
197+
return self._send_and_format_response(
198198
restli_method=RESTLI_METHODS.GET_ALL,
199199
resource_path=resource_path,
200200
path_keys=path_keys,
@@ -255,7 +255,7 @@ def finder(
255255
final_query_params
256256
)
257257

258-
return self.__send_and_format_response(
258+
return self._send_and_format_response(
259259
restli_method=RESTLI_METHODS.FINDER,
260260
resource_path=resource_path,
261261
path_keys=path_keys,
@@ -322,7 +322,7 @@ def batch_finder(
322322
final_query_params
323323
)
324324

325-
return self.__send_and_format_response(
325+
return self._send_and_format_response(
326326
restli_method=RESTLI_METHODS.BATCH_FINDER,
327327
resource_path=resource_path,
328328
path_keys=path_keys,
@@ -371,7 +371,7 @@ def create(
371371

372372
encoded_query_param_string = encoder.param_encode(query_params)
373373

374-
return self.__send_and_format_response(
374+
return self._send_and_format_response(
375375
restli_method=RESTLI_METHODS.CREATE,
376376
resource_path=resource_path,
377377
path_keys=path_keys,
@@ -431,7 +431,7 @@ def batch_create(
431431
encoded_query_param_string = encoder.param_encode(query_params)
432432
request_body = {"elements": entities}
433433

434-
return self.__send_and_format_response(
434+
return self._send_and_format_response(
435435
restli_method=RESTLI_METHODS.BATCH_CREATE,
436436
resource_path=resource_path,
437437
path_keys=path_keys,
@@ -488,7 +488,7 @@ def update(
488488

489489
encoded_query_param_string = encoder.param_encode(query_params)
490490

491-
return self.__send_and_format_response(
491+
return self._send_and_format_response(
492492
restli_method=RESTLI_METHODS.UPDATE,
493493
resource_path=resource_path,
494494
path_keys=path_keys,
@@ -550,7 +550,7 @@ def batch_update(
550550
entities_map = dict(zip(encoded_ids, entities))
551551
request_body = {"entities": entities_map}
552552

553-
return self.__send_and_format_response(
553+
return self._send_and_format_response(
554554
restli_method=RESTLI_METHODS.BATCH_UPDATE,
555555
resource_path=resource_path,
556556
path_keys=path_keys,
@@ -604,7 +604,7 @@ def partial_update(
604604

605605
request_body = {"patch": {"$set": patch_set_object}}
606606

607-
return self.__send_and_format_response(
607+
return self._send_and_format_response(
608608
restli_method=RESTLI_METHODS.PARTIAL_UPDATE,
609609
resource_path=resource_path,
610610
path_keys=path_keys,
@@ -671,7 +671,7 @@ def batch_partial_update(
671671
}
672672
request_body = {"entities": entities_map}
673673

674-
return self.__send_and_format_response(
674+
return self._send_and_format_response(
675675
restli_method=RESTLI_METHODS.BATCH_PARTIAL_UPDATE,
676676
resource_path=resource_path,
677677
path_keys=path_keys,
@@ -716,7 +716,7 @@ def delete(
716716

717717
encoded_query_param_string = encoder.param_encode(query_params)
718718

719-
return self.__send_and_format_response(
719+
return self._send_and_format_response(
720720
restli_method=RESTLI_METHODS.DELETE,
721721
resource_path=resource_path,
722722
path_keys=path_keys,
@@ -764,7 +764,7 @@ def batch_delete(
764764
final_query_params.update({"ids": ids})
765765
encoded_query_param_string = encoder.param_encode(final_query_params)
766766

767-
return self.__send_and_format_response(
767+
return self._send_and_format_response(
768768
resource_path=resource_path,
769769
path_keys=path_keys,
770770
encoded_query_param_string=encoded_query_param_string,
@@ -823,7 +823,7 @@ def action(
823823

824824
request_body = action_params if action_params else {}
825825

826-
return self.__send_and_format_response(
826+
return self._send_and_format_response(
827827
restli_method=RESTLI_METHODS.ACTION,
828828
resource_path=resource_path,
829829
path_keys=path_keys,
@@ -834,7 +834,7 @@ def action(
834834
formatter=ActionResponseFormatter,
835835
)
836836

837-
def __send_and_format_response(
837+
def _send_and_format_response(
838838
self,
839839
*,
840840
restli_method: RESTLI_METHODS,

linkedin_api/clients/restli/utils/decoder.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def decode(value: str) -> Union[Dict[str, Any], List[Any], str]:
3030
Returns:
3131
Union[Dict[str,Any], List[Any], str]: The decoded value
3232
"""
33-
return __internal_decode(value, False)
33+
return _internal_decode(value, False)
3434

3535

3636
def reduced_decode(value: str) -> Union[Dict[str, Any], List[Any], str]:
@@ -43,10 +43,10 @@ def reduced_decode(value: str) -> Union[Dict[str, Any], List[Any], str]:
4343
Returns:
4444
Union[Dict[str,Any], List[Any], str]: The decoded value
4545
"""
46-
return __internal_decode(value, True)
46+
return _internal_decode(value, True)
4747

4848

49-
def __validateSuffix(restli_encoded_str: str, suffix: str):
49+
def _validateSuffix(restli_encoded_str: str, suffix: str):
5050
"""
5151
Validates that the input restli_encoded_str has the expected suffix at the end
5252
"""
@@ -56,7 +56,7 @@ def __validateSuffix(restli_encoded_str: str, suffix: str):
5656
)
5757

5858

59-
def __restli_unescape(value: str, reduced: bool):
59+
def _restli_unescape(value: str, reduced: bool):
6060
if not reduced:
6161
value = unquote(value)
6262
elif re.search(reduced_decode_special_chars_pattern, value):
@@ -68,7 +68,7 @@ def __restli_unescape(value: str, reduced: bool):
6868
return value
6969

7070

71-
def __find_last_right_bracket(value: str, pos: int) -> int:
71+
def _find_last_right_bracket(value: str, pos: int) -> int:
7272
"""
7373
Returns the index of the last right, matching bracket, starting from specified index.
7474
For example, consider value = "List(1,(k:v))".
@@ -111,21 +111,21 @@ def __find_last_right_bracket(value: str, pos: int) -> int:
111111
return idx
112112

113113

114-
def __internal_decode(restli_encoded_str: str, reduced: bool):
114+
def _internal_decode(restli_encoded_str: str, reduced: bool):
115115
if (restli_encoded_str is None) or (restli_encoded_str == "''"):
116116
restli_encoded_str = ""
117117

118118
if restli_encoded_str.startswith(LIST_PREFIX):
119-
__validateSuffix(restli_encoded_str, LIST_SUFFIX)
120-
return __decode_list(restli_encoded_str[5:-1], reduced)
119+
_validateSuffix(restli_encoded_str, LIST_SUFFIX)
120+
return _decode_list(restli_encoded_str[5:-1], reduced)
121121
elif restli_encoded_str.startswith(OBJ_PREFIX):
122-
__validateSuffix(restli_encoded_str, OBJ_SUFFIX)
123-
return __decode_object(restli_encoded_str[1:-1], reduced)
122+
_validateSuffix(restli_encoded_str, OBJ_SUFFIX)
123+
return _decode_object(restli_encoded_str[1:-1], reduced)
124124
else:
125-
return __restli_unescape(restli_encoded_str, reduced)
125+
return _restli_unescape(restli_encoded_str, reduced)
126126

127127

128-
def __decode_list(restli_encoded_str: str, reduced: bool) -> List[Any]:
128+
def _decode_list(restli_encoded_str: str, reduced: bool) -> List[Any]:
129129
"""
130130
Decodes a Rest.li-encoded string to a list
131131
@@ -147,9 +147,9 @@ def __decode_list(restli_encoded_str: str, reduced: bool) -> List[Any]:
147147
restli_encoded_str[idx:].startswith(OBJ_PREFIX)
148148
):
149149
# If we encounter a List or Object as one of the current list's entries, append the decoded value
150-
right_bracket_idx = __find_last_right_bracket(restli_encoded_str, idx)
150+
right_bracket_idx = _find_last_right_bracket(restli_encoded_str, idx)
151151
decoded_list.append(
152-
__internal_decode(
152+
_internal_decode(
153153
restli_encoded_str[idx : right_bracket_idx + 1], reduced
154154
)
155155
)
@@ -162,15 +162,15 @@ def __decode_list(restli_encoded_str: str, reduced: bool) -> List[Any]:
162162
if end_idx < 0:
163163
end_idx = len(restli_encoded_str)
164164
decoded_list.append(
165-
__restli_unescape(restli_encoded_str[idx:end_idx], reduced)
165+
_restli_unescape(restli_encoded_str[idx:end_idx], reduced)
166166
)
167167

168168
# Move past the comma
169169
idx = end_idx + 1
170170
return decoded_list
171171

172172

173-
def __decode_object(restli_encoded_str: str, reduced: bool) -> Dict[str, Any]:
173+
def _decode_object(restli_encoded_str: str, reduced: bool) -> Dict[str, Any]:
174174
"""
175175
Decodes a Rest.li-encoded string to an object.
176176
@@ -189,7 +189,7 @@ def __decode_object(restli_encoded_str: str, reduced: bool) -> Dict[str, Any]:
189189
while idx < len(restli_encoded_str):
190190
# Get the key value between the start index and key-val separator (:)
191191
colon_idx = restli_encoded_str.find(OBJ_KEY_VAL_SEP, idx)
192-
key = __restli_unescape(restli_encoded_str[idx:colon_idx], reduced)
192+
key = _restli_unescape(restli_encoded_str[idx:colon_idx], reduced)
193193

194194
# Move to the next character after the colon
195195
idx = colon_idx + 1
@@ -198,8 +198,8 @@ def __decode_object(restli_encoded_str: str, reduced: bool) -> Dict[str, Any]:
198198
restli_encoded_str[idx:].startswith(OBJ_PREFIX)
199199
):
200200
# If we encounter a List or Object as the key's value, decode it
201-
right_bracket_idx = __find_last_right_bracket(restli_encoded_str, idx)
202-
decoded_object[key] = __internal_decode(
201+
right_bracket_idx = _find_last_right_bracket(restli_encoded_str, idx)
202+
decoded_object[key] = _internal_decode(
203203
restli_encoded_str[idx : right_bracket_idx + 1], reduced
204204
)
205205

@@ -211,7 +211,7 @@ def __decode_object(restli_encoded_str: str, reduced: bool) -> Dict[str, Any]:
211211
if end_idx < 0:
212212
end_idx = len(restli_encoded_str)
213213

214-
decoded_object[key] = __restli_unescape(
214+
decoded_object[key] = _restli_unescape(
215215
restli_encoded_str[idx:end_idx], reduced
216216
)
217217
# end_idx is the comma index, so move 1 past it

linkedin_api/clients/restli/utils/encoder.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def param_encode(raw_query_params_map: Optional[Dict[str, Any]]) -> str:
2727
if raw_query_params_map is None:
2828
return ""
2929

30-
query_params_map = __encode_query_param_map(raw_query_params_map)
30+
query_params_map = _encode_query_param_map(raw_query_params_map)
3131
return "&".join(
3232
[f"{key}={query_params_map[key]}" for key in sorted(query_params_map.keys())]
3333
)
@@ -48,32 +48,32 @@ def encode(value: Union[bool, str, int, float, List, Dict]) -> str:
4848
elif isinstance(value, bool):
4949
return "true" if value else "false"
5050
elif isinstance(value, str):
51-
return __encode_string(value)
51+
return _encode_string(value)
5252
elif isinstance(value, list):
53-
return __encode_list(value)
53+
return _encode_list(value)
5454
elif isinstance(value, dict):
55-
return __encode_dict(value)
55+
return _encode_dict(value)
5656
else:
5757
# Everything else (e.g. int, float)
5858
return str(value)
5959

6060

61-
def __encode_query_param_map(raw_query_params_map: Dict[str, Any]) -> Dict:
61+
def _encode_query_param_map(raw_query_params_map: Dict[str, Any]) -> Dict:
6262
# Return a Dict with the input keys and values encoded
63-
return {__encode_string(k): encode(v) for (k, v) in raw_query_params_map.items()}
63+
return {_encode_string(k): encode(v) for (k, v) in raw_query_params_map.items()}
6464

6565

66-
def __encode_string(value: str) -> str:
66+
def _encode_string(value: str) -> str:
6767
# Perform standard URL-encoding on strings
6868
return quote(value, safe="")
6969

7070

71-
def __encode_list(value: List[Any]) -> str:
71+
def _encode_list(value: List[Any]) -> str:
7272
# Encode a list
7373
return f"{LIST_PREFIX}{LIST_ITEM_SEP.join(encode(el) for el in value)}{LIST_SUFFIX}"
7474

7575

76-
def __encode_dict(value: Dict[str, Any]) -> str:
76+
def _encode_dict(value: Dict[str, Any]) -> str:
7777
# Encode a dict by encoding both key and value, both of which can be complex
7878
key_values = OBJ_KEY_VAL_PAIR_SEP.join(
7979
f"{encode(k)}{OBJ_KEY_VAL_SEP}{encode(v)}" for (k, v) in sorted(value.items())

0 commit comments

Comments
 (0)