import urllib
import urlparse

from . import app_settings

def strip_token(url):
    bits = urlparse.urlparse(url)
    original_query = urlparse.parse_qsl(bits.query)

    query = {}
    for k, v in original_query:
        if k != app_settings.KEY:
            query[k] = v

    query = urllib.urlencode(query)

    return urlparse.urlunparse(
        (bits[0], bits[1], bits[2], bits[3], query, bits[5]),
    )

import urllib
import urlparse

from django.conf import settings
from django.contrib import auth

from . import app_settings

def strip_token(url):
    bits = urlparse.urlparse(url)
    original_query = urlparse.parse_qsl(bits.query)

    query = {}
    for k, v in original_query:
        if k != app_settings.KEY:
            query[k] = v

    query = urllib.urlencode(query)

    return urlparse.urlunparse(
        (bits[0], bits[1], bits[2], bits[3], query, bits[5]),
    )

def login(request, user):
    user.backend = settings.AUTHENTICATION_BACKENDS[0]
    auth.login(request, user)

Make login a utility so it can be re-used elsewhere.
Make login a utility so it can be re-used elsewhere.

Signed-off-by: Chris Lamb <711c73f64afdce07b7e38039a96d2224209e9a6c@playfire.com>

  import urllib
  import urlparse
+ 
+ from django.conf import settings
+ from django.contrib import auth
  
  from . import app_settings
  
  def strip_token(url):
      bits = urlparse.urlparse(url)
      original_query = urlparse.parse_qsl(bits.query)
  
      query = {}
      for k, v in original_query:
          if k != app_settings.KEY:
              query[k] = v
  
      query = urllib.urlencode(query)
  
      return urlparse.urlunparse(
          (bits[0], bits[1], bits[2], bits[3], query, bits[5]),
      )
  
+ def login(request, user):
+     user.backend = settings.AUTHENTICATION_BACKENDS[0]
+     auth.login(request, user)
+ 
Make login a utility so it can be re-used elsewhere.
## Code Before:
import urllib
import urlparse

from . import app_settings

def strip_token(url):
    bits = urlparse.urlparse(url)
    original_query = urlparse.parse_qsl(bits.query)

    query = {}
    for k, v in original_query:
        if k != app_settings.KEY:
            query[k] = v

    query = urllib.urlencode(query)

    return urlparse.urlunparse(
        (bits[0], bits[1], bits[2], bits[3], query, bits[5]),
    )

## Instruction:
Make login a utility so it can be re-used elsewhere.
## Code After:
import urllib
import urlparse

from django.conf import settings
from django.contrib import auth

from . import app_settings

def strip_token(url):
    bits = urlparse.urlparse(url)
    original_query = urlparse.parse_qsl(bits.query)

    query = {}
    for k, v in original_query:
        if k != app_settings.KEY:
            query[k] = v

    query = urllib.urlencode(query)

    return urlparse.urlunparse(
        (bits[0], bits[1], bits[2], bits[3], query, bits[5]),
    )

def login(request, user):
    user.backend = settings.AUTHENTICATION_BACKENDS[0]
    auth.login(request, user)
