Skip to content

Commit 90bbe85

Browse files
mshaileshr@gmail.commshaileshr@gmail.com
authored andcommitted
1.0.0 DOC String corrected
1 parent 7b4815d commit 90bbe85

File tree

6 files changed

+182
-198
lines changed

6 files changed

+182
-198
lines changed

contentstack/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11

2-
# __init__
3-
# contentstack
4-
#
5-
# Created by Shailesh Mishra on 22/06/19.
6-
# Copyright © 2019 Contentstack. All rights reserved.
2+
"""
3+
__init__.py
4+
contentstack
5+
Created by Shailesh Mishra on 22/06/19.
6+
Copyright 2019 Contentstack. All rights reserved.
7+
8+
"""
79

810
import warnings
9-
__author__ = 'Shailesh Mishra'
11+
12+
__author__ = 'Contentstack (Shailesh Mishra)'
1013
__status__ = 'debug'
1114
__version__ = '1.0.0'
1215
__package__ = 'contentstack'
1316
__endpoint__ = 'cdn.contentstack.io'
17+
__email__ = "mshaileshr@gmail.com"
1418

1519
from .entry import Entry
1620
from .asset import Asset
1721
from .config import Config
1822
from .content_type import ContentType
19-
from .errors import Error, ConfigError, FileModeWarning
23+
from .errors import Error, FileModeWarning
2024
from .http_connection import HTTPConnection
2125

2226
# Set a default logger to prevent "No handler found" warnings
2327
# Set default logging handler to avoid "No handler found" warnings.
2428
import logging
2529
from logging import NullHandler
26-
2730
logging.getLogger(__name__).addHandler(NullHandler())
28-
29-
# FileModeWarnings go off per the default.
3031
warnings.simplefilter('default', FileModeWarning, append=True)

contentstack/config.py

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
1-
# Config
2-
# contentstack
3-
#
4-
# Created by Shailesh Mishra on 22/06/19.
5-
# Copyright © 2019 Contentstack. All rights reserved.
1+
"""
2+
Config
3+
contentstack
4+
Created by Shailesh Mishra on 22/06/19.
5+
Copyright 2019 Contentstack. All rights reserved.
6+
7+
"""
68

79
import logging
8-
from enum import Enum
10+
import enum
911

10-
logging.basicConfig(filename='cs.log', format='%(asctime)s - %(message)s', level=logging.INFO)
11-
logging.getLogger("Config")
12+
logging.basicConfig(filename='report.log', format='%(asctime)s - %(message)s', level=logging.INFO)
13+
logging.getLogger(__name__)
1214

1315

14-
class ContentstackRegion(Enum):
16+
class ContentstackRegion(enum.Enum):
1517
US = 'us'
1618
EU = 'eu'
1719

1820

1921
class Config(object):
2022

21-
"""
22-
All API paths are relative to this base URL, for example, /users actually means <scheme>://<host>/<basePath>/users.
23-
"""
24-
2523
def __init__(self):
2624
self.default = dict(protocol="https", region=ContentstackRegion.US, host="cdn.contentstack.io", version="v3")
2725

@@ -30,19 +28,16 @@ def region(self, region=ContentstackRegion.US):
3028
"""
3129
The base URL for Content Delivery API is cdn.contentstack.io.
3230
default region is for ContentstackRegion is US
33-
3431
:param region: ContentstackRegion
3532
:return: self
36-
37-
Example:
38-
>>> config = Config().region(region=ContentstackRegion.US)
39-
33+
==============================
34+
[Example:]
35+
>>> config = Config().region(region=ContentstackRegion.US)
36+
==============================
4037
"""
4138

4239
if region is not None and isinstance(region, ContentstackRegion):
4340
self.default['region'] = region
44-
else:
45-
raise ValueError('Kindly provide a valid argument')
4641
return self
4742

4843
def host(self, host):
@@ -59,10 +54,10 @@ def host(self, host):
5954
:return: self
6055
:rtype: Config
6156
62-
Example:
63-
64-
>>> config = Config().host('api.contentstack.io')
65-
57+
==============================
58+
[Example:]
59+
>>> config = Config().host('api.contentstack.io')
60+
==============================
6661
"""
6762

6863
if host is not None and isinstance(host, str):
@@ -78,33 +73,33 @@ def version(self, version=None):
7873
:type version: str
7974
:return: self
8075
:rtype: Config
76+
==============================
77+
[Example:] The API version (in our case, 'v3') can be found in the URL
8178
82-
Example: The API version (in our case, 'v3') can be found in the URL, e.g.
83-
84-
>>> config = Config()
85-
>>> config.version = 'v3'
86-
79+
>>> config = Config()
80+
>>> config.version = 'v3'
81+
==============================
8782
"""
83+
8884
if version is not None and isinstance(version, str):
8985
self.default['version'] = version
9086

9187
return self
9288

9389
@property
9490
def endpoint(self):
91+
92+
"""
93+
:return: url endpoint to make Http requst
94+
"""
9595
return self.__get_url()
9696

9797
def __get_url(self):
9898
host = self.default["host"]
9999
if self.default['region'] is not ContentstackRegion.US:
100-
101100
if self.default["host"] == 'cdn.contentstack.io':
102-
# update the host to .com
103101
self.default["host"] = 'cdn.contentstack.com'
104102
else:
105-
# Find the regional value
106103
regional_host = str(self.default['region'].value)
107-
# Attach region to the host
108104
host = '{}-{}'.format(regional_host, self.default["host"])
109-
110105
return "{0}://{1}/{2}".format(self.default["protocol"], host, self.default["version"])

contentstack/errors.py

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
# Error
2-
# contentstack
3-
#
4-
# Created by Shailesh Mishra on 22/06/19.
5-
# Copyright © 2019 Contentstack. All rights reserved.
1+
"""
2+
Error
3+
contentstack
4+
Created by Shailesh Mishra on 22/06/19.
5+
Copyright 2019 Contentstack. All rights reserved.
6+
7+
"""
68

79

810
class Error:
11+
912
"""
1013
contentstack.error
1114
~~~~~~~~~~~~~~~~~~
@@ -15,75 +18,78 @@ class Error:
1518
"""
1619

1720
def __init__(self):
18-
"""
19-
20-
"""
21+
# It has some values to set error_msg, error_code etc..
2122
self.__error_dict = {}
2223
self.__error_code = str
2324
self.__msg = str
24-
self.__cause_err = str
25-
26-
def config(self, result: dict):
27-
"""
2825

29-
:param result:
30-
:type result:
31-
:return:
32-
:rtype:
33-
"""
26+
def _config(self, result: dict):
27+
# config error information
3428
if result is not None and len(result) > 0:
3529
self.__error_dict = result
3630
self.__error_code = self.__error_dict['error_code']
3731
self.__msg = self.__error_dict['error_message']
38-
self.__cause_err = self.__error_dict['errors']
3932
return self
4033

4134
@property
4235
def error_code(self):
36+
4337
"""
4438
It returns error code from the stack response
4539
:return: error_code as int
4640
:rtype: int
41+
==============================
42+
[Example:]
4743
48-
Example. code = error.error_code
49-
44+
>>> ode = error.error_code
45+
==============================
5046
"""
5147
return self.__error_code
5248

5349
@property
5450
def error_message(self):
51+
5552
"""
5653
Returns error_message from the stack response
5754
:return: error_message
5855
:rtype: str
56+
==============================
57+
[Example:]
5958
60-
Example. error.error_message
61-
59+
>>> ode = error.error_message
60+
==============================
6261
"""
6362

6463
return self.__msg
6564

6665
@property
6766
def error(self):
67+
6868
"""
6969
This returns error code and error_message in dict formats
7070
:return: error dict
7171
:rtype: dict
72+
==============================
73+
[Example:]
7274
73-
Example. error = error.error
75+
>>> ode = error.error
76+
==============================
7477
"""
7578

76-
return self.__cause_err
79+
return self.__msg
7780

7881
@property
7982
def error_info(self) -> dict:
83+
8084
"""
8185
error information
8286
:return: error information
8387
:rtype: dict
88+
==============================
89+
[Example:]
8490
85-
Example. error.error_info
86-
91+
>>> ode = error.error_info
92+
==============================
8793
"""
8894
return self.__error_dict
8995

@@ -114,28 +120,15 @@ def error_info(self) -> dict:
114120
429: "The number of requests exceeds the allowed limit for the given time period.",
115121
500: "The server is malfunctioning and is not specific on what the problem is.",
116122
502: "A server received an invalid response from another server.",
117-
504: "A server did not receive a timely response from another server that it was accessing while attempting "
118-
"to load the web page or fill another request by the browser. "
123+
504: """ A server did not receive a timely response from another server that it was accessing while attempting
124+
to load the web page or fill another request by the browser. """
119125
}
120126

121-
@staticmethod
122-
def logging_config(level):
123-
print('level ' + level)
124-
125-
126-
class ConfigError(Exception):
127-
pass
128-
129127

130128
class StackException(Exception):
131-
pass
132-
133-
134-
class ContentstackError(Exception):
135-
pass
136-
137-
138-
class NotSupportedException(Exception):
129+
"""
130+
StackException used to handle Stack validation Errors.
131+
"""
139132
pass
140133

141134

0 commit comments

Comments
 (0)