Giter VIP home page Giter VIP logo

imgix-python's People

Contributors

adamenger avatar ashutoshkrris avatar atlawrie avatar cablehead avatar ericdeansanchez avatar fossabot avatar frederickfogerty avatar hashknot avatar jnak avatar kellysutton avatar luqven avatar noblelady avatar oscarbralo avatar paulstraw avatar rik avatar sherwinski avatar tommikaikkonen avatar zacman85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imgix-python's Issues

Py2 and 3 compatibility

At Rover we are upgrading our codebase to python3.6 while maintaining compatibility with python2.7.

We are running into a problem where imgix isn't compatible with both python 2.7 and 3.6 at the same time.

The reason is that the behavior of string literals in the imgix-python library is not consistent between python versions.

For example, take URLBuilder.create_url(path, opts). If path is explicitly unicode in python 2, this will result in the following error:

  File "/usr/local/lib/python2.7/dist-packages/imgix/urlhelper.py", line 188, in __str__
    "", ])
  File "/usr/local/lib/python2.7/dist-packages/future/backports/urllib/parse.py", line 387, in urlunparse
    _coerce_args(*components))
  File "/usr/local/lib/python2.7/dist-packages/future/backports/urllib/parse.py", line 115, in _coerce_args
    raise TypeError("Cannot mix str and non-str arguments")
TypeError: Cannot mix str and non-str arguments

This will fail in the same way if path is explicitly a byte string in python 3. The only way that it can be expected to work at all between the two versions is if the path variable is a string literal with no explicit type and from __future__ import unicode_literals is not present.

In order to ease our transition of hundreds of thousands of lines of code to python3 we need to include all future imports in all our files which means that path will be explicitly unicode in both python2 and python3.

The issue can be fixed by making string literals be either explicitly unicode or bytestring regardless of what version of python was being run. This can be done by adding from __future__ import unicode_literals to all the files in this library.

One way to automatically do this would be to use futurize

Trouble signing with `%20` character in url for

When signing a url with a + encoded as %20 for a web proxy secure source, the signing fails.

Try encoding:
http://www.brookings.edu/~/media/research/images/l/lk%20lo/london_bigben_flags001/london_bigben_flags001_16x9.jpg

>>> import imgix
>>> image_url_builder = imgix.UrlBuilder(IMGIX_URL, sign_key=IMGIX_SIGN_KEY, use_https=True)
>>> image_url = 'http://www.brookings.edu/~/media/research/images/l/lk%20lo/london_bigben_flags001/london_bigben_flags001_16x9.jpg'
>>> options = {'w': 260, 'fit': 'crop', 'crop': 'entropy'}
>>> image_url_builder.create_url(image_url, options)
'https://factr-url.imgix.net/http%3A%2F%2Fwww.brookings.edu%2F%7E%2Fmedia%2Fresearch%2Fimages%2Fl%2Flk%2520lo%2Flondon_bigben_flags001%2Flondon_bigben_flags001_16x9.jpg?crop=entropy&fit=crop&ixlib=python-1.1.0&w=260&s=473639e97d47f1b991e46ba670042358'

The signed url throws a 401.

Consider storing a float percentage

The value is named SRCSET_INCREMENT_PERCENTAGE, consider making it one.

SRCSET_INCREMENT_PERCENTAGE = 8

It's only other use is 13 lines down here,

prev *= 1 + (SRCSET_INCREMENT_PERCENTAGE / 100.0) * 2

where the conversion to a percentage actually occurs.

Reasons to Consider:

  • truth, the value is named to be a percentage, so it should be a percentage
  • demonstrate consistent semantics for ourselves and users

Think through potential rename

import imgix

b = imgix.url.Builder("demos.imgix.net")
b.create("/bridge.png", w=100, h=100)

Is Helper needed? It's not currently exposed in the docs.

Type Safety for URL options

There are many settings that can be used with Imgix. These have a range of types, but most are integers, floats, or strings that define an enumeration.

It would be great to get a more type-safe API using Python enums and/or mypy types. This would also give some basis to further safety in APIs provided using this library (such as a GraphQL API backed by this).

feat: optionally disable path encoding

Description

Related PR: imgix/js-core#314

Add disablePathEncoding functionality to the URL building logic in create_url and create_srcset. This way, users can decide to opt-out of path encoding.

Probably a good way of handling this would be to add a new constructor option, disablePathEncoding, that can be referenced in any of the instance methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.