Skip to content

Commit d514667

Browse files
azure-eu and include_metadata support added
1 parent 0333c0b commit d514667

File tree

16 files changed

+116
-69
lines changed

16 files changed

+116
-69
lines changed

CHANGELOG.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# CHANGELOG
22

3+
## _v1.8.0_
4+
5+
### **Date: 8-MAY-2023**
6+
7+
- AZURE_EU, region support added
8+
- include_metadata support added to asset, entry and query
9+
- General code improvement clean up
10+
311
---
412

513
## _v1.7.0_
@@ -67,13 +75,13 @@ Date: 08-Dec-2020
6775
- Timeout support included
6876

6977
- Entry
70-
- added support for include_fallback.
78+
- added support for include_fallback.
7179
- Asset
72-
- added support for include_fallback.
80+
- added support for include_fallback.
7381
- AssetQueryable
74-
- added support for include_fallback.
82+
- added support for include_fallback.
7583
- Query
76-
- added support for include_fallback.
84+
- added support for include_fallback.
7785

7886
---
7987

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2012 - 2021 Contentstack. All rights reserved.
3+
Copyright (c) 2012 - 2023 Contentstack. All rights reserved.
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ Read through to understand how to use the Sync API with Contentstack Python SDK.
137137
The MIT License (MIT)
138138
^^^^^^^^^^^^^^^^^^^^^
139139

140-
Copyright © 2012-2020 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
140+
Copyright © 2012-2023 Contentstack. All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
141141

142142
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
143143

changelog.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,20 @@
22
**CHANGELOG**
33
================
44

5-
*v1.7.0*
5+
*v1.8.0*
6+
============
7+
8+
**Date: 02-MAY-2023**
69

10+
- AZURE_EU, region support added
11+
- include_metadata support added to asset, entry and query
12+
- General code improvement clean up
13+
14+
15+
*v1.7.0*
716
============
817

9-
**Date: 8-APR-2022**
18+
**Date: 08-APR-2022**
1019

1120
Region support added.
1221
- AZURE_NA support added

contentstack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .utility import Utils
1717

1818
__title__ = 'contentstack-python'
19-
__author__ = 'Contentstack'
19+
__author__ = 'contentstack'
2020
__status__ = 'debug'
2121
__version__ = '1.8.0'
2222
__endpoint__ = 'cdn.contentstack.io'

contentstack/error_composer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import requests
2+
3+
def make_api_request(url):
4+
try:
5+
response = requests.get(url)
6+
response.raise_for_status()
7+
except requests.exceptions.HTTPError as http_error:
8+
print(f"HTTP error occurred: {http_error}")
9+
raise
10+
except requests.exceptions.Timeout as timeout_error:
11+
print(f"Timeout error occurred: {timeout_error}")
12+
raise
13+
except requests.exceptions.ConnectionError as connection_error:
14+
print(f"Connection error occurred: {connection_error}")
15+
raise
16+
except requests.exceptions.RequestException as request_exception:
17+
print(f"An error occurred: {request_exception}")
18+
raise
19+
else:
20+
print("API request successful")
21+
return response.json()
22+
finally:
23+
print("API request complete")
24+
25+
# Example usage
26+
try:
27+
api_data = make_api_request("https://jsonplaceholder.typicode.com/posts")
28+
print(api_data)
29+
except Exception as e:
30+
print("Caught exception:", e)

contentstack/https_connection.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@
77

88
import logging
99
import platform
10-
import json
11-
from json import JSONDecodeError
1210
import requests
1311
from requests.adapters import HTTPAdapter
14-
from requests.exceptions import HTTPError, Timeout
1512
import contentstack
1613

1714
log = logging.getLogger(__name__)
@@ -42,6 +39,16 @@ def user_agents():
4239
return {'User-Agent': str(header), "X-User-Agent": package}
4340

4441

42+
def get_api_data(response):
43+
try:
44+
response.raise_for_status()
45+
except requests.exceptions.HTTPError as error:
46+
print(f"Error: {error}")
47+
return None
48+
else:
49+
return response.json()
50+
51+
4552
class HTTPSConnection: # R0903: Too few public methods
4653
"""Make Https Request to fetch the result as per requested url"""
4754

@@ -66,25 +73,26 @@ def get(self, url):
6673
session = requests.Session()
6774
adapter = HTTPAdapter(max_retries=self.retry_strategy)
6875
session.mount('https://', adapter)
69-
response = session.get(
70-
url, verify=True, headers=self.headers, timeout=self.timeout)
76+
response = session.get(url, verify=True, headers=self.headers, timeout=self.timeout)
77+
response.encoding = "utf-8"
78+
# response.raise_for_status()
7179
session.close()
72-
if response.encoding is None:
73-
response.encoding = 'utf-8'
74-
elif response is not None:
75-
return response.json()
76-
else:
77-
return {"error": "error details not found", "error_code": 422,
78-
"error_message": "unknown error"}
79-
except Timeout as timeout_err:
80-
raise TimeoutError(
81-
json.dumps({"httpStatus": 408,
82-
"message": f'Timeout error ${timeout_err.strerror}'})) from timeout_err
83-
except ConnectionError as connect_err:
84-
raise ConnectionError(json.dumps({"httpStatus": 503,
85-
"message": f'Service error ${connect_err.strerror}'})) from connect_err
86-
except JSONDecodeError as connection_err:
87-
raise TypeError(json.dumps({"httpStatus": 503,
88-
"message": 'Decoding JSON has failed.'})) from connection_err
89-
except HTTPError as http_err:
90-
raise HTTPError('Http error occurred') from http_err
80+
except requests.exceptions.HTTPError as http_error:
81+
print(f"HTTP error occurred: {http_error}")
82+
except requests.exceptions.Timeout as timeout_error:
83+
print(f"Timeout error occurred: {timeout_error}")
84+
except requests.exceptions.ConnectionError as connection_error:
85+
print(f"Connection error occurred: {connection_error}")
86+
except requests.exceptions.RequestException as request_exception:
87+
print(f"An error occurred: {request_exception}")
88+
else:
89+
print("API request successful")
90+
return response.json()
91+
finally:
92+
print("API request complete")
93+
94+
# if response.status_code == 200 and response.encoding is None:
95+
# response.encoding = 'utf-8'
96+
# return response.json()
97+
# else:
98+
# return get_api_data(response)

contentstack/query.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import enum
66
import json
77
import logging
8+
import warnings
89
from urllib import parse
910

1011
import empty
@@ -121,10 +122,6 @@ def tags(self, *tags):
121122
self.query_params["tags"] = ",".join(tags)
122123
return self
123124

124-
@deprecation.deprecated(
125-
deprecated_in="1.7.0",
126-
current_version='1.8.0',
127-
details="Use regex function instead")
128125
def search(self, value: str):
129126
"""
130127
This method provides only the entries matching
@@ -147,6 +144,7 @@ def search(self, value: str):
147144
>>> result = query.find()
148145
-------------------------------------
149146
"""
147+
warnings.warn('deprecated in 1.7.0, Use regex function instead')
150148
if value is not None:
151149
self.query_params["typeahead"] = value
152150
return self
@@ -328,10 +326,11 @@ def __execute_network_call(self):
328326
self.__validate_live_preview()
329327
encoded_string = parse.urlencode(self.query_params, doseq=True)
330328
url = f'{self.base_url}?{encoded_string}'
331-
if self.http_instance.live_preview['content_type_uid'] == self.content_type_uid:
332-
_rq = self.http_instance.get(url)['entries']
333-
_preview = self.http_instance.live_preview['resp']
334-
return self._merge_preview(_rq, _preview)
329+
if self.http_instance.live_preview['enable']:
330+
if self.http_instance.live_preview['content_type_uid'] == self.content_type_uid:
331+
_rq = self.http_instance.get(url)['entries']
332+
_preview = self.http_instance.live_preview['resp']
333+
return self._merge_preview(_rq, _preview)
335334
return self.http_instance.get(url)
336335

337336
def _merge_preview(self, qresp, _preview):

contentstack/stack.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,9 @@ def __sync_request(self):
319319
"""
320320
base_url = f'{self.http_instance.endpoint}/stacks/sync'
321321
self.sync_param['environment'] = self.http_instance.headers['environment']
322-
encoded_query = parse.urlencode(self.sync_param)
323-
url = f'{base_url}?{encoded_query}'
324-
result = self.http_instance.get(url)
325-
return result
322+
query = parse.urlencode(self.sync_param)
323+
url = f'{base_url}?{query}'
324+
return self.http_instance.get(url)
326325

327326
def image_transform(self, image_url, **kwargs):
328327
"""
@@ -362,12 +361,15 @@ def live_preview_query(self, **kwargs):
362361

363362
def _execute_management_api(self):
364363
_headers, _endpoint = self._enable_live_preview()
365-
_ct_uid = self.live_preview.get("content_type_uid")
364+
content_type_uid = self.live_preview.get("content_type_uid")
366365
_entry_uid = self.live_preview.get("entry_uid")
367-
_url = f'{_endpoint}/content_types/{_ct_uid}/entries/{_entry_uid}'
366+
_url = f'{_endpoint}/content_types/{content_type_uid}/entries/{_entry_uid}'
368367
import requests
369368
r = requests.get(url=_url, verify=True, headers=_headers)
370-
self.live_preview['resp'] = r.json()['entry']
369+
if r.ok:
370+
self.live_preview['resp'] = r.json()['entry']
371+
else:
372+
print(r.status_code)
371373
return self
372374

373375
def _enable_live_preview(self):

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)