Skip to content

Commit

Permalink
Merge pull request #74 from uploadcare/v-1.2.12
Browse files Browse the repository at this point in the history
V 1.2.12
  • Loading branch information
dmitry-mukhin committed Dec 30, 2014
2 parents f51e45f + f0082ad commit 3aa483f
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 24 deletions.
13 changes: 12 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ History
-------


1.2.12
~~~~~~

- add synchronous upload from URL method to `File`
- UploadcareExceptions are `__repr__`ed properly
- update widget to 1.5.3 (see `widget changelog`_)


1.2.11
~~~~~~

Expand Down Expand Up @@ -148,7 +156,7 @@ param is unicode and ``requests.request()`` got ``files`` argument, e.g.:

- ``ImageField`` was added. It provides uploading only image files. Moreover,
you can activate manual crop, e.g. ``ImageField(manual_crop='2:3')``.
- More apropriate exceptions were added.
- More appropriate exceptions were added.
- Tests were separated from library and were restructured.
- Widget was updated up to *0.6.7*.
- Issue of ``FileField``'s ``blank``, ``null`` attributes was fixed.
Expand Down Expand Up @@ -233,3 +241,6 @@ param is unicode and ``requests.request()`` got ``files`` argument, e.g.:
- url()
- filename()
- Changed pyuploadcare.UploadCareException.__init__


.. _widget changelog: https://github.com/uploadcare/uploadcare-widget/blob/master/HISTORY.markdown
2 changes: 1 addition & 1 deletion pyuploadcare/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

from __future__ import unicode_literals

__version__ = '1.2.11'
__version__ = '1.2.12'

from .api_resources import File, FileList, FileGroup
from .exceptions import (
Expand Down
5 changes: 4 additions & 1 deletion pyuploadcare/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _content_type_from_response(response):


def rest_request(verb, path, data=None, timeout=conf.DEFAULT,
retry_throttled=conf.retry_throttled):
retry_throttled=conf.DEFAULT):
"""Makes REST API request and returns response as ``dict``.
It provides auth headers as well and takes settings from ``conf`` module.
Expand Down Expand Up @@ -83,6 +83,9 @@ def rest_request(verb, path, data=None, timeout=conf.DEFAULT,
}
"""
if retry_throttled is conf.DEFAULT:
retry_throttled = conf.retry_throttled

path = path.lstrip('/')
url = urljoin(conf.api_base, path)
url_parts = urlsplit(url)
Expand Down
23 changes: 22 additions & 1 deletion pyuploadcare/api_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import re
import logging
import math
import time

import dateutil.parser
import six

from . import conf
from .api import rest_request, uploading_request
from .exceptions import InvalidRequestError, APIError
from .exceptions import (InvalidRequestError, APIError, UploadError,
TimeoutError)


logger = logging.getLogger("pyuploadcare")
Expand Down Expand Up @@ -273,6 +275,25 @@ def upload_from_url(cls, url):
file_from_url = cls.FileFromUrl(result['token'])
return file_from_url

@classmethod
def upload_from_url_sync(cls, url, timeout=30):
"""Uploads file from given url and returns ``File`` instance.
"""
ffu = cls.upload_from_url(url)

time_started = time.time()
while time.time() - time_started < timeout:
status = ffu.update_info()['status']
if status == 'success':
return ffu.get_file()
if status in ('failed', 'error'):
raise UploadError(
'could not upload file from url: {0}'.format(ffu.info())
)
time.sleep(0.1)
else:
raise TimeoutError('timed out during upload')

class FileFromUrl(object):
"""Contains the logic around an upload from url.
Expand Down
2 changes: 1 addition & 1 deletion pyuploadcare/dj/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
conf.secret = settings.UPLOADCARE['secret']


widget_version = settings.UPLOADCARE.get('widget_version', '1.4.6')
widget_version = settings.UPLOADCARE.get('widget_version', '1.5.3')

hosted_url = 'https://ucarecdn.com/widget/{version}/uploadcare/uploadcare-{version}.min.js'.format(
version=widget_version)
Expand Down
17 changes: 0 additions & 17 deletions pyuploadcare/dj/static/uploadcare/uploadcare-1.4.6.min.js

This file was deleted.

16 changes: 16 additions & 0 deletions pyuploadcare/dj/static/uploadcare/uploadcare-1.5.3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyuploadcare/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class UploadcareException(Exception):
"""Base exception class of library."""
def __init__(self, data='', *args, **kwargs):
self.data = str(data)
super(UploadcareException, self).__init__(*args, **kwargs)
super(UploadcareException, self).__init__(data, *args, **kwargs)


class APIConnectionError(UploadcareException):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

setup(
name='pyuploadcare',
version='1.2.11',
version='1.2.12',
description='Python library for Uploadcare.com',
long_description=(
open('README.rst').read() + '\n\n' + open('HISTORY.rst').read()
Expand Down

0 comments on commit 3aa483f

Please sign in to comment.