text
stringlengths
0
828
self.logger.warn(""Received exception while connecting to slick at %s"", url, exc_info=sys.exc_info())
raise SlickCommunicationError(
""Tried 3 times to request data from slick at url %s without a successful status code."", url)"
4186,"def update(self):
""""""Update the specified object from slick. You specify the object as a parameter, using the parent object as
a function. Example:
proj = slick.projects.findByName(""foo"")
... update proj here
slick.projects(proj).update()
""""""
obj = self.data
url = self.getUrl()
# hopefully when we discover what problems exist in slick to require this, we can take the loop out
last_stats_code = None
last_body = None
for retry in range(3):
try:
json_data = obj.to_json()
self.logger.debug(""Making request to slick at url %s, with data: %s"", url, json_data)
r = requests.put(url, data=json_data, headers=json_content)
self.logger.debug(""Request returned status code %d"", r.status_code)
if r.status_code is 200:
return self.model.from_dict(r.json())
else:
last_stats_code = r.status_code
last_body = r.text
self.logger.warn(""Slick status code: %d"", r.status_code)
self.logger.warn(""Body of what slick returned: %s"", r.text)
except BaseException as error:
self.logger.warn(""Received exception while connecting to slick at %s"", url, exc_info=sys.exc_info())
traceback.print_exc()
raise SlickCommunicationError(
""Tried 3 times to request data from slick at url %s without a successful status code. Last status code: %d, body: %s"", url, last_stats_code, last_body)"
4187,"def create(self):
""""""Create the specified object (perform a POST to the api). You specify the object as a parameter, using
the parent object as a function. Example:
proj = Project()
... add project data here
proj = slick.projects(proj).create()
""""""
obj = self.data
self.data = None
url = self.getUrl()
# hopefully when we discover what problems exist in slick to require this, we can take the loop out
for retry in range(3):
try:
json_data = obj.to_json()
self.logger.debug(""Making request to slick at url %s, with data: %s"", url, json_data)
r = requests.post(url, data=json_data, headers=json_content)
self.logger.debug(""Request returned status code %d"", r.status_code)
if r.status_code is 200:
return self.model.from_dict(r.json())
else:
self.logger.debug(""Body of what slick returned: %s"", r.text)
except BaseException as error:
self.logger.warn(""Received exception while connecting to slick at %s"", url, exc_info=sys.exc_info())
raise SlickCommunicationError(
""Tried 3 times to request data from slick at url %s without a successful status code."", url)"
4188,"def remove(self):
""""""Remove or delete the specified object from slick. You specify which one you want by providing the id as
a parameter to the parent object, using it as a function. Example:
slick.projects(""4fd8cd95e4b0ee7ba54b9885"").remove()
""""""
url = self.getUrl()
# hopefully when we discover what problems exist in slick to require this, we can take the loop out
for retry in range(3):
try:
self.logger.debug(""Making DELETE request to slick at url %s"", url)
r = requests.delete(url)
self.logger.debug(""Request returned status code %d"", r.status_code)
if r.status_code is 200:
return None
else:
self.logger.debug(""Body of what slick returned: %s"", r.text)
except BaseException as error:
self.logger.warn(""Received exception while connecting to slick at %s"", url, exc_info=sys.exc_info())
raise SlickCommunicationError(
""Tried 3 times to request data from slick at url %s without a successful status code."", url)"
4189,"def upload_local_file(self, local_file_path, file_obj=None):
""""""Create a Stored File and upload it's data. This is a one part do it all type method. Here is what
it does:
1. ""Discover"" information about the file (mime-type, size)
2. Create the stored file object in slick
3. Upload (chunked) all the data in the local file
4. re-fetch the stored file object from slick, and return it
""""""
if file_obj is None and not os.path.exists(local_file_path):
return
storedfile = StoredFile()
storedfile.mimetype = mimetypes.guess_type(local_file_path)[0]
storedfile.filename = os.path.basename(local_file_path)
if file_obj is None:
storedfile.length = os.stat(local_file_path).st_size
else:
file_obj.seek(0,os.SEEK_END)
storedfile.length = file_obj.tell()
file_obj.seek(0)