Permalink
Browse files

Auto Pep8

  • Loading branch information...
glader committed Mar 30, 2012
1 parent d2fa750 commit 77512f836d6626cd1ca71828ba2e4c8ffe33c77c
Showing with 51 additions and 61 deletions.
  1. +6 −5 setup.py
  2. +5 −3 yafotki/client/client.py
  3. +4 −6 yafotki/client/http.py
  4. +12 −17 yafotki/client/http_client.py
  5. +16 −15 yafotki/client/yarsa.py
  6. +5 −6 yafotki/fields.py
  7. +3 −9 yafotki/storage.py
View
@@ -10,7 +10,8 @@
for dirpath, dirnames, filenames in os.walk('yafotki'):
for i, dirname in enumerate(dirnames):
- if dirname.startswith('.'): del dirnames[i]
+ if dirname.startswith('.'):
+ del dirnames[i]
if '__init__.py' in filenames:
pkg = dirpath.replace(os.path.sep, '.')
if os.path.altsep:
@@ -26,11 +27,11 @@
description='Yandex.Fotki files backend for django',
author='Serge A Makarov',
author_email='serg.makar@gmail.com',
- license = 'BSD Licence',
- version = '0.2',
+ license='BSD Licence',
+ version='0.2',
url='https://bitbucket.org/redsnow/django-yafotki',
package_dir={'yafotki': 'yafotki'},
packages=packages,
package_data={'yafotki': data_files},
- install_requires = ['feedparser']
-)
+ install_requires=['feedparser']
+)
View
@@ -9,9 +9,12 @@
import http_client
#TODO: Add exceptions for all errors
+
+
class YFClientException(Exception):
pass
+
class YFCreateObjectException(YFClientException):
pass
@@ -30,7 +33,7 @@ class YFClient(object):
photoes_link = None
atom_processor = None
- def __init__(self, username = None, password = None):
+ def __init__(self, username=None, password=None):
self.username = username
self.password = password
self.http_client = http_client.YaAtomHttpClient()
@@ -40,7 +43,6 @@ def __init__(self, username = None, password = None):
if self.username and self.password:
self.login()
-
def login(self):
self.get_rsa()
self.encrypted_login = yarsa.encrypt("<credentials login='%s' password='%s'/>" % (self.username, self.password,), self.rsa_key)
@@ -68,7 +70,7 @@ def get_service_doc(self):
def get_albums(self):
pass
- def add_album(self, title, summary = None):
+ def add_album(self, title, summary=None):
data = '<entry xmlns="http://www.w3.org/2005/Atom" xmlns:f="yandex:fotki"><title>%s</title><summary>%s</summary></entry>' % (title, summary,)
response = self.http_client.post(self.albums_link, data, {
'Content-Type': 'application/atom+xml; charset=utf-8; type=entry'
View
@@ -4,12 +4,12 @@
from urlparse import urlparse
import types
+
def parse_url(url):
url_parts = urlparse(url)
url = Url(url_parts)
return url
-
class Url(object):
@@ -43,16 +43,16 @@ class YandexHttpClientException(Exception):
DEFAULT_CONTENT_TYPE = 'application/atom+xml'
DEFAULT_CHARSET = 'charset=utf-8'
+
class HttpClient(object):
debug = False
headers = {}
- def __init__(self, headers = None, debug = None):
+ def __init__(self, headers=None, debug=None):
self.debug = debug or False
self.headers = headers or {}
-
- def request(self, method, url, data = None, headers = None):
+ def request(self, method, url, data=None, headers=None):
all_headers = self.headers.copy()
if headers:
all_headers.update(headers)
@@ -72,8 +72,6 @@ def request(self, method, url, data = None, headers = None):
connection.request(method, url_object.path, data, all_headers)
return connection.getresponse()
-
def init_connection(self, url):
url = parse_url(url)
return httplib.HTTPConnection(url.host, url.port)
-
@@ -2,41 +2,36 @@
import http
+
class YaAtomHttpClient(object):
http_client = None
auth_token = None
- def __init__(self, http_client = None, auth_token = None):
+ def __init__(self, http_client=None, auth_token=None):
self.http_client = http_client or http.HttpClient()
self.auth_token = auth_token or None
def set_token(self, token):
self.auth_token = token
- def request(self, method = None, uri = None, data = None, headers = None ):
+ def request(self, method=None, uri=None, data=None, headers=None):
request_headers = {}
if headers:
request_headers.update(headers)
if self.auth_token:
request_headers['Authorization'] = 'FimpToken realm="fotki.yandex.ru", token="%s"' % self.auth_token
- return self.http_client.request(method, uri, data,request_headers)
-
-
- def get(self, uri, headers = None):
- return self.request('GET', uri = uri, headers = headers )
-
- def post(self, uri, data = None, headers = None):
- return self.request('POST', uri = uri, data = data,headers = headers )
-
- def put(self, uri, data = None, headers = None):
- return self.request('PUT', uri = uri, data = data,headers = headers )
-
- def delete(self, uri, data = None, headers = None):
- return self.request('DELETE', uri = uri, data = data,headers = headers )
-
+ return self.http_client.request(method, uri, data, request_headers)
+ def get(self, uri, headers=None):
+ return self.request('GET', uri=uri, headers=headers)
+ def post(self, uri, data=None, headers=None):
+ return self.request('POST', uri=uri, data=data, headers=headers)
+ def put(self, uri, data=None, headers=None):
+ return self.request('PUT', uri=uri, data=data, headers=headers)
+ def delete(self, uri, data=None, headers=None):
+ return self.request('DELETE', uri=uri, data=data, headers=headers)
View
@@ -1,27 +1,28 @@
#-*- coding:utf-8 -*-
+
def encrypt(message, public_key):
NSTR, ESTR = public_key.split("#")
DATA_ARR = [ord(x) for x in message]
- N,E,STEP_SIZE = int(NSTR,16),int(ESTR,16), len(NSTR)/2-1
- prev_crypted = [0]*STEP_SIZE
+ N, E, STEP_SIZE = int(NSTR, 16), int(ESTR, 16), len(NSTR) / 2 - 1
+ prev_crypted = [0] * STEP_SIZE
hex_out = ""
- for i in range(0,(len(DATA_ARR)-1)/STEP_SIZE+1):
- tmp = DATA_ARR[i*STEP_SIZE:(i+1)*STEP_SIZE]
- tmp = [tmp[i] ^ prev_crypted[i] for i in range(0,len(tmp))]
+ for i in range(0, (len(DATA_ARR) - 1) / STEP_SIZE + 1):
+ tmp = DATA_ARR[i * STEP_SIZE:(i + 1) * STEP_SIZE]
+ tmp = [tmp[i] ^ prev_crypted[i] for i in range(0, len(tmp))]
tmp.reverse()
plain = 0
- for x in range(0,len(tmp)): plain+= tmp[x]*pow(256, x, N)
- hex_result = "%x" % pow(plain,E,N)
- hex_result = "".join(['0']*( len(NSTR)- len(hex_result))) + hex_result
+ for x in range(0, len(tmp)):
+ plain += tmp[x] * pow(256, x, N)
+ hex_result = "%x" % pow(plain, E, N)
+ hex_result = "".join(['0'] * (len(NSTR) - len(hex_result))) + hex_result
- for x in range(0,min(len(hex_result),len(prev_crypted)*2),2):
- prev_crypted[x/2] = int(hex_result[x:x+2],16)
+ for x in range(0, min(len(hex_result), len(prev_crypted) * 2), 2):
+ prev_crypted[x / 2] = int(hex_result[x:x + 2], 16)
- hex_out += ("0" if len(tmp) < 16 else "") + ("%x" % len(tmp)) + "00" # current size
- ks = len(NSTR)/2
- hex_out += ("0" if ks < 16 else "") + ("%x" % ks) + "00" # key size
+ hex_out += ("0" if len(tmp) < 16 else "") + ("%x" % len(tmp)) + "00" # current size
+ ks = len(NSTR) / 2
+ hex_out += ("0" if ks < 16 else "") + ("%x" % ks) + "00" # key size
hex_out += hex_result
- return hex_out.decode("hex").encode("base64").replace("\n","")
-
+ return hex_out.decode("hex").encode("base64").replace("\n", "")
View
@@ -3,7 +3,7 @@
import re
from bisect import bisect
-from django.db.models.fields.files import FieldFile,FileField
+from django.db.models.fields.files import FieldFile, FileField
from yafotki.storage import YFStorage
@@ -30,19 +30,18 @@ def __getattr__(self, name):
return self.src(size=match.group(1))
return super(YFFieldFile, self).__getattr__(name)
-
- def src(self, size = None):
+ def src(self, size=None):
default_url = self.storage.url(self.name)
if size is not None:
if size != 'orig':
sizes = self.SIZES.keys()
sizes.sort()
try:
- size = self.SIZES[sizes[bisect(sizes, int(size)-1)]]
+ size = self.SIZES[sizes[bisect(sizes, int(size) - 1)]]
except IndexError:
size = self.SIZES[sizes[-1]]
- return default_url.replace('_orig', '_'+size)
+ return default_url.replace('_orig', '_' + size)
return default_url
@@ -61,4 +60,4 @@ def __init__(self, *args, **kwargs):
add_introspection_rules([], ["^yafotki\.fields\.YFField"])
except ImportError:
- pass
+ pass
View
@@ -8,18 +8,17 @@
from yafotki.client.client import YFClient
-#TODO: Make queries to YF(e.g Authorization in YF) only in
+#TODO: Make queries to YF(e.g Authorization in YF) only in
class YFStorage(Storage):
options = None
yf_client = None
- def __init__(self, options = None):
+ def __init__(self, options=None):
self.options = options or settings.YAFOTKI_STORAGE_OPTIONS
self.yf_client = YFClient(self.options['username'], self.options['password'])
-
- def _open(self, name, mode = 'rb'):
+ def _open(self, name, mode='rb'):
pass
def _save(self, name, content):
@@ -33,7 +32,6 @@ def _save(self, name, content):
photo_obj = self.yf_client.add_photo(album_name, image_name, content.file, content_type)
return photo_obj.entries[0].links[3].href
-
def delete(self, name):
pass
@@ -43,7 +41,6 @@ def exists(self, name):
album_name = 'default'
return self.yf_client.is_exist(album_name, file_name)
-
def listdir(self, path):
pass
@@ -52,6 +49,3 @@ def size(self, name):
def url(self, path):
return path
-
-
-

0 comments on commit 77512f8

Please sign in to comment.