Merge pull request #842 from Gluejar/maintenance3

assorted fixes
pull/94/head
eshellman 2019-06-13 16:40:40 -04:00 committed by GitHub
commit 4c92a23dc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 15 deletions

View File

@ -1,16 +1,17 @@
import logging
import math
import re
import urllib
import urllib2
import uuid
from decimal import Decimal
import unicodedata
from urlparse import urlparse
from sorl.thumbnail import get_thumbnail
import requests
from botocore.exceptions import ClientError
from PIL import ImageFile
from sorl.thumbnail import get_thumbnail
from django.conf import settings
from django.contrib.auth.models import User
@ -1197,13 +1198,13 @@ class Ebook(models.Model):
return ebf.file
def get_archive_ebf(self): # returns an ebf
if not self.ebook_files.filter(asking=False):
if not self.ebook_files.filter(asking=False).count():
if not self.provider in good_providers:
return None
try:
r = urllib2.urlopen(self.url)
try:
self.filesize = int(r.info().getheaders("Content-Length")[0])
r = requests.get(self.url)
if r.status_code == 200:
self.filesize = len(r.content)
if self.save:
self.filesize = self.filesize if self.filesize < 2147483647 else 2147483647 # largest safe positive integer
self.save()
@ -1213,20 +1214,23 @@ class Ebook(models.Model):
format=self.format,
source=self.url
)
ebf.file.save(path_for_file(ebf, None), ContentFile(r.read()))
ebf.file.save(path_for_file(ebf, None), ContentFile(r.content))
ebf.file.close()
ebf.save()
return ebf
except IndexError:
# response has no Content-Length header probably a bad link
else:
logging.error('Bad link error: {}'.format(self.url))
except IOError:
logger.error(u'could not open {}'.format(self.url))
else:
ebf = self.ebook_files.filter(asking=False).order_by('-created')[0]
if not self.filesize:
try:
self.filesize = ebf.file.size
self.save()
except ClientError:
# error thrown when the can't access the S3 bucket
pass
return ebf
def set_provider(self):

View File

@ -307,7 +307,7 @@ class CustomRegistrationView(RegistrationView):
return self.pretend_success()
return super(CustomRegistrationView, self).form_valid(form)
SUSPICIOUSUN = re.compile(r'^[A-Z]([a-z]{4,8})[a-z]{3}$', )
SUSPICIOUSUN = re.compile(r'^[A-Z][a-z]{7}[a-z]*$', )
MANYDOTS = re.compile(r'(\.[^\.]+){4}')
def similar(s1, s2):
#trigrams in common

View File

@ -14,8 +14,8 @@ anyjson==0.3.3
appdirs==1.4.0
billiard==3.3.0.23
awscli>=1.15.52
boto==2.48.0
boto3==1.7.33
boto==2.49.0
boto3==1.9.167
celery==3.1.23
certifi==2019.3.9
chardet==3.0.4