Skip to content

Commit

Permalink
replace requests by internal _requests method
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtekson committed Jul 25, 2024
1 parent e1eec9d commit 957bf72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 52 deletions.
65 changes: 14 additions & 51 deletions geo/Geoserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,12 +1555,7 @@ def upload_style(

r = self._requests(method="post", url=url, data=style_xml, headers=headers)
if r.status_code == 201:
r_sld = requests.put(
url + "/" + name,
data=xml,
auth=(self.username, self.password),
headers=header_sld,
)
r_sld = self._requests(method="put", url=url + "/" + name, data=xml, headers=header_sld)

if r_sld.status_code == 200:
return r_sld.status_code
Expand Down Expand Up @@ -1656,12 +1651,8 @@ def create_coveragestyle(
)
if r.status_code == 201:
with open("style.sld", "rb") as f:
r_sld = requests.put(
url + "/" + style_name,
data=f.read(),
auth=(self.username, self.password),
headers=header_sld,
)
r_sld = self._requests(method="put", url=url + "/" + style_name, data=f.read(), headers=header_sld)

os.remove("style.sld")
if r_sld.status_code == 200:
return r_sld.status_code
Expand Down Expand Up @@ -2268,9 +2259,7 @@ def create_datastore(

else:
url = "{}/rest/workspaces/{}/datastores".format(self.service_url, workspace)
r = requests.post(
url, data, auth=(self.username, self.password), headers=headers
)
r = self._requests(method="post", url=url, data=data, headers=headers)

if r.status_code in [200, 201]:
return "Data store created/updated successfully"
Expand Down Expand Up @@ -2337,12 +2326,7 @@ def create_shp_datastore(
)

with open(path, "rb") as f:
r = requests.put(
url,
data=f.read(),
auth=(self.username, self.password),
headers=headers,
)
r = self._requests("put", url, data=f.read(), headers=headers)
if r.status_code in [200, 201, 202]:
return "The shapefile datastore created successfully!"
else:
Expand Down Expand Up @@ -2406,12 +2390,8 @@ def create_gpkg_datastore(
)

with open(path, "rb") as f:
r = requests.put(
url,
data=f.read(),
auth=(self.username, self.password),
headers=headers,
)
r = self._requests("put", url, data=f.read(), headers=headers)

if r.status_code in [200, 201, 202]:
return "The geopackage datastore created successfully!"
else:
Expand Down Expand Up @@ -2493,12 +2473,8 @@ def publish_featurestore(
</featureType>"""
headers = {"content-type": "text/xml"}

r = requests.post(
url,
data=layer_xml,
auth=(self.username, self.password),
headers=headers,
)
r = self._requests("post", url, data=layer_xml, headers=headers)

if r.status_code == 201:
return r.status_code
else:
Expand Down Expand Up @@ -2572,12 +2548,8 @@ def edit_featuretype(
</featureType>"""
headers = {"content-type": "text/xml"}

r = requests.put(
url,
data=layer_xml,
auth=(self.username, self.password),
headers=headers,
)
r = self._requests("put", url, data=layer_xml, headers=headers)

if r.status_code == 200:
return r.status_code
else:
Expand Down Expand Up @@ -2716,12 +2688,7 @@ def publish_featurestore_sqlview(
headers = {"content-type": "text/xml"}

# request
r = requests.post(
url,
data=layer_xml,
auth=(self.username, self.password),
headers=headers,
)
r = self.requests("post", url, data=layer_xml, headers=headers)

if r.status_code == 201:
return r.status_code
Expand Down Expand Up @@ -2981,9 +2948,7 @@ def create_user(
username, password, str(enabled).lower()
)
headers = {"content-type": "text/xml", "accept": "application/json"}
r = requests.post(
url, data, auth=(self.username, self.password), headers=headers
)
r = self._requests("post", url, data=data, headers=headers)

if r.status_code == 201:
return "User created successfully"
Expand Down Expand Up @@ -3036,9 +3001,7 @@ def modify_user(
data = unparse({"user": modifications})
print(url, data)
headers = {"content-type": "text/xml", "accept": "application/json"}
r = requests.post(
url, data, auth=(self.username, self.password), headers=headers
)
r = self._requests.post("post", url, data=data, headers=headers)

if r.status_code == 200:
return "User modified successfully"
Expand Down
2 changes: 1 addition & 1 deletion geo/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

__author__ = "Tek Kshetri"
__email__ = "iamtekson@gmail.com"
__version__ = "2.8.1"
__version__ = "2.8.2"

0 comments on commit 957bf72

Please sign in to comment.