Skip to content

Commit

Permalink
Update USER_AGENT. Remove max_length restriction from CloudianryField…
Browse files Browse the repository at this point in the history
…. Rename and reformat CHANGES.txt.

  * Version 1.1.2
  * Update `USER_AGENT` format and allow the setting of `USER_PLATFORM`
  * Remove `max_length` restriction from `CloudinaryField`
  * Reformat CHANGES.txt and rename it to CHANGELOG.md
  * Change PyPI package classifier to "Development Status :: 5 - Production/Stable"
  • Loading branch information
tocker committed Jun 22, 2015
1 parent a4292ab commit 73abd59
Show file tree
Hide file tree
Showing 9 changed files with 386 additions and 42 deletions.
340 changes: 340 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

32 changes: 0 additions & 32 deletions CHANGES.txt

This file was deleted.

4 changes: 2 additions & 2 deletions cloudinary.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 1.1
Name: cloudinary
Version: 1.1.0
Version: 1.1.2
Summary: Python interface to Cloudinary
Home-page: http://cloudinary.com
Author: Cloudinary
Expand All @@ -11,6 +11,6 @@ Keywords: cloudinary image upload transformation cdn
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Development Status :: 4 - Beta
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Topic :: Internet :: WWW/HTTP
31 changes: 29 additions & 2 deletions cloudinary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,45 @@
import sys
import re


CF_SHARED_CDN = "d3jpl91pxevbkh.cloudfront.net"
OLD_AKAMAI_SHARED_CDN = "cloudinary-a.akamaihd.net"
AKAMAI_SHARED_CDN = "res.cloudinary.com"
SHARED_CDN = AKAMAI_SHARED_CDN
CL_BLANK = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"

VERSION = "1.1.1"
USER_AGENT = "cld-python-" + VERSION
VERSION = "1.1.2"
USER_AGENT = "CloudinaryPython/" + VERSION
""" :const: USER_AGENT """

USER_PLATFORM = ""
"""
Additional information to be passed with the USER_AGENT, e.g. "CloudinaryMagento/1.0.1". This value is set in platform-specific
implementations that use cloudinary_php.
The format of the value should be <ProductName>/Version[ (comment)].
@see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
**Do not set this value in application code!**
"""

from cloudinary import utils
from cloudinary.compat import urlparse, parse_qs


def get_user_agent():
"""Provides the `USER_AGENT` string that is passed to the Cloudinary servers.
Prepends `USER_PLATFORM` if it is defined.
:returns: the user agent
:rtype: str
"""

if USER_PLATFORM == "":
return USER_AGENT
else:
return USER_PLATFORM + " " + USER_AGENT

def import_django_settings():
try:
import django.conf
Expand Down
2 changes: 1 addition & 1 deletion cloudinary/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def call_api(method, uri, params, **options):
encoded_value = base64.encodebytes(byte_value) if PY3 else base64.encodestring(byte_value)
base64string = to_string(encoded_value).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
request.add_header("User-Agent", cloudinary.USER_AGENT)
request.add_header("User-Agent", cloudinary.get_user_agent())
request.get_method = lambda: method.upper()

kw = {}
Expand Down
2 changes: 1 addition & 1 deletion cloudinary/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CloudinaryField(with_metaclass(models.SubfieldBase, models.Field)):
description = "A resource stored in Cloudinary"

def __init__(self, *args, **kwargs):
options = {'max_length': 100}
options = {}
self.default_form_class = kwargs.pop("default_form_class", forms.CloudinaryFileField)
options.update(kwargs)
self.type = options.pop("type", "upload")
Expand Down
2 changes: 1 addition & 1 deletion cloudinary/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def call_api(action, params, http_headers={}, return_error=False, unsigned=False
datagen = "".join(datagen)

request = urllib2.Request(api_url + "?" + urlencode(param_list), datagen, headers)
request.add_header("User-Agent", cloudinary.USER_AGENT)
request.add_header("User-Agent", cloudinary.get_user_agent())
for k, v in http_headers.items():
request.add_header(k, v)

Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

version = '1.1.1'
version = '1.1.2'

setup(name='cloudinary',
version=version,
Expand All @@ -15,7 +15,7 @@
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Development Status :: 4 - Beta",
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Topic :: Internet :: WWW/HTTP",
],
Expand Down
11 changes: 10 additions & 1 deletion tests/utils_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import copy
import cloudinary.utils
import unittest
import re
Expand Down Expand Up @@ -432,5 +431,15 @@ def test_offset(self):
for transformation, offset in test_cases.items():
self.__test_cloudinary_url(public_id="video_id", options={'resource_type': 'video', 'offset': offset}, expected_url=VIDEO_UPLOAD_PATH + transformation + "/video_id")

def test_user_agent(self):
agent = cloudinary.get_user_agent()
platform = 'MyPlatform/1.2.3 (Test code)'
self.assertRegexpMatches(agent, 'CloudinaryPython/\d\.\d+\.\d+')
temp = cloudinary.USER_PLATFORM
cloudinary.USER_PLATFORM = platform
result = cloudinary.get_user_agent()
cloudinary.USER_PLATFORM = temp # restore value before assertion
self.assertEqual(result, platform + ' ' + agent)

if __name__ == '__main__':
unittest.main()

0 comments on commit 73abd59

Please sign in to comment.