From 589a81bb12751302626580f052eb656bb26afc52 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 13 Jun 2019 16:17:14 -0400 Subject: [PATCH 1/4] improve username pattern --- libraryauth/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraryauth/views.py b/libraryauth/views.py index e96f0e75..a3de1344 100644 --- a/libraryauth/views.py +++ b/libraryauth/views.py @@ -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 From e3a5a50f34ea08b9335647d8edcb0764abedd661 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 13 Jun 2019 16:18:54 -0400 Subject: [PATCH 2/4] catch S3 exception --- core/models/bibmodels.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/core/models/bibmodels.py b/core/models/bibmodels.py index 2e22cc35..bc3bc0ba 100644 --- a/core/models/bibmodels.py +++ b/core/models/bibmodels.py @@ -9,8 +9,9 @@ from decimal import Decimal import unicodedata from urlparse import urlparse -from sorl.thumbnail import get_thumbnail +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 @@ -1225,8 +1226,12 @@ class Ebook(models.Model): else: ebf = self.ebook_files.filter(asking=False).order_by('-created')[0] if not self.filesize: - self.filesize = ebf.file.size - self.save() + 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): From 4969994a878771a0dd3a55b813e182fe383d4a45 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 13 Jun 2019 16:20:05 -0400 Subject: [PATCH 3/4] urllib2 didn't handle chunked method --- core/models/bibmodels.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/models/bibmodels.py b/core/models/bibmodels.py index bc3bc0ba..08feb98c 100644 --- a/core/models/bibmodels.py +++ b/core/models/bibmodels.py @@ -1,14 +1,14 @@ import logging import math import re -import urllib -import urllib2 import uuid from decimal import Decimal import unicodedata from urlparse import urlparse +import requests + from botocore.exceptions import ClientError from PIL import ImageFile from sorl.thumbnail import get_thumbnail @@ -1198,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() @@ -1214,12 +1214,11 @@ 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)) From 9b55eddb5bed2b4872ae35c7000325d47f251cd5 Mon Sep 17 00:00:00 2001 From: eric Date: Thu, 13 Jun 2019 16:20:16 -0400 Subject: [PATCH 4/4] update boto --- requirements_versioned.pip | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements_versioned.pip b/requirements_versioned.pip index 74589032..16ef4278 100644 --- a/requirements_versioned.pip +++ b/requirements_versioned.pip @@ -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