From 2a3fc56a096a59866faaf2e09fd7482e4b171197 Mon Sep 17 00:00:00 2001
From: Robohash
Date: Fri, 4 Nov 2022 14:10:00 -0400
Subject: [PATCH] Fix extension parsing
---
robohash/robohash.py | 7 ++++---
robohash/static/robots.txt | 9 +++++++++
robohash/templates/root.html | 7 +------
robohash/webfront.py | 11 ++++-------
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/robohash/robohash.py b/robohash/robohash.py
index e0e2ae4..d31ade7 100644
--- a/robohash/robohash.py
+++ b/robohash/robohash.py
@@ -16,6 +16,9 @@ class Robohash(object):
Takes in the string to make a Robohash out of.
"""
+ # Default to png
+ self.format = 'png'
+
# Optionally remove an images extension before hashing.
if ignoreext is True:
string = self._remove_exts(string)
@@ -41,7 +44,6 @@ class Robohash(object):
# Get the colors in set1
self.colors = self._listdirs(self.resourcedir + 'sets/set1')
- self.format = 'png'
def _remove_exts(self,string):
"""
@@ -93,7 +95,7 @@ class Robohash(object):
directories = []
for root, dirs, files in natsort.natsorted(os.walk(path, topdown=False)):
for name in dirs:
- if name[:1] is not '.':
+ if name[:1] != '.':
directories.append(os.path.join(root, name))
directories = natsort.natsorted(directories)
@@ -117,7 +119,6 @@ class Robohash(object):
Build our Robot!
Returns the robot image itself.
"""
-
# Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all
# If they don't set one, take the first entry from sets above.
diff --git a/robohash/static/robots.txt b/robohash/static/robots.txt
index c2a49f4..2498203 100644
--- a/robohash/static/robots.txt
+++ b/robohash/static/robots.txt
@@ -1,2 +1,11 @@
+User-agent: SpiritRover
+Allow: Finally-coming-home
+
+User-agent: T-1000
+Allow: Liquid-metal-form
+
+User-agent: WALL-E
+Allow: Rebuilding-with-EVE
+
User-agent: *
Allow: /
diff --git a/robohash/templates/root.html b/robohash/templates/root.html
index 49b3bcf..19e76ac 100644
--- a/robohash/templates/root.html
+++ b/robohash/templates/root.html
@@ -27,7 +27,6 @@ robo@robohash.org
-
@@ -430,7 +429,7 @@ function submitform()
Want a JPG instead? Fine. PNG? Fine. Want it as a bitmap? I think you're nutty. But fine. Just change the
- URL to request in any format you want. Use ?ignoreext=false to make the bots care about extensions.
+ URL to request in any format you want. If you want it to hash the whole thing, including the extension use ?ignoreext=false to ignore the extensions.
@@ -606,10 +605,6 @@ Robohash.org" or something.
diff --git a/robohash/webfront.py b/robohash/webfront.py
index b4196f5..cc26ee7 100755
--- a/robohash/webfront.py
+++ b/robohash/webfront.py
@@ -280,9 +280,7 @@ class ImgHandler(tornado.web.RequestHandler):
# Detect if the user has passed in a flag to ignore extensions.
# Pass this along to to Robohash obj later on.
-
- ignoreext = args.get('ignoreext','false').lower() == 'true'
-
+ ignoreext = args.get('ignoreext','true').lower() == 'true'
# Split the size variable in to sizex and sizey
if "size" in args:
sizex,sizey = args.get('size').split("x")
@@ -317,8 +315,7 @@ class ImgHandler(tornado.web.RequestHandler):
args['avatar'] = False
# Create our Robohashing object
- r = Robohash(string)
-
+ r = Robohash(string=string,ignoreext=ignoreext)
# Allow users to manually specify a robot 'set' that they like.
# Ensure that this is one of the allowed choices, or allow all
@@ -364,11 +361,11 @@ class ImgHandler(tornado.web.RequestHandler):
bgset = args.get('bgset')
# We're going to be returning the image directly, so tell the browser to expect a binary.
- self.set_header("Content-Type", "image/" + format)
+ self.set_header("Content-Type", "image/" + r.format)
self.set_header("Cache-Control", "public,max-age=31536000")
# Build our Robot.
- r.assemble(roboset=roboset,format=format,bgset=bgset,color=color,sizex=sizex,sizey=sizey)
+ r.assemble(roboset=roboset,format=r.format,bgset=bgset,color=color,sizex=sizex,sizey=sizey)
# Print the Robot to the handler, as a file-like obj
if r.format != 'datauri':