Permalink
Browse files

fixes for an issue discovered by @ibnesayeed this morning

  • Loading branch information...
shawnmjones committed Oct 12, 2018
1 parent 7e720c1 commit 16a31bef49a3199b3d072b33675104b560568d3a
Showing with 17 additions and 12 deletions.
  1. +1 −1 docs/source/conf.py
  2. +12 −10 mementoembed/__init__.py
  3. +1 −1 mementoembed/version.py
  4. +3 −0 sample_appconfig.cfg
View
@@ -26,7 +26,7 @@
# The short X.Y version
version = ''
# The full version, including alpha/beta/rc tags
release = '0.2018.10.11.222821'
release = '0.2018.10.12.164424'
# -- General configuration ---------------------------------------------------
View
@@ -223,17 +223,19 @@ def create_app():
application_logger.info("Default image path set to {}".format(app.config['DEFAULT_IMAGE_PATH']))
application_logger.info("Use data URIs for default image: {}".format(app.config['USE_DATA_URI_FOR_DEFAULT_IMAGE']))
if app.config['USE_DATA_URI_FOR_DEFAULT_IMAGE'].lower() == "yes":
if 'USE_DATA_URI_FOR_DEFAULT_IMAGE' in app.config:

This comment has been minimized.

Show comment
Hide comment
@ibnesayeed

ibnesayeed Oct 12, 2018

Member

@shawnmjones you could have avoided this additional nesting of if blocks by simply changing:

if app.config['USE_DATA_URI_FOR_DEFAULT_IMAGE'].lower() == "yes":

to

if app.config.get('USE_DATA_URI_FOR_DEFAULT_IMAGE', '').lower() == "yes":
@ibnesayeed

ibnesayeed Oct 12, 2018

Member

@shawnmjones you could have avoided this additional nesting of if blocks by simply changing:

if app.config['USE_DATA_URI_FOR_DEFAULT_IMAGE'].lower() == "yes":

to

if app.config.get('USE_DATA_URI_FOR_DEFAULT_IMAGE', '').lower() == "yes":

This comment has been minimized.

Show comment
Hide comment

This comment has been minimized.

Show comment
Hide comment
@shawnmjones

shawnmjones Oct 12, 2018

Collaborator

In a subsequent commit, I updated the code for the config a bit so this sort of thing might not be necessary in the future. I was unaware of this additional parameter for the get function. Thanks!

@shawnmjones

shawnmjones Oct 12, 2018

Collaborator

In a subsequent commit, I updated the code for the config a bit so this sort of thing might not be necessary in the future. I was unaware of this additional parameter for the get function. Thanks!

application_logger.info("Opening default image for conversion to data URI")
with open(app.config['DEFAULT_IMAGE_PATH'], 'rb') as f:
imgdata = f.read()
application_logger.info("Default image has been opened and stored")
application_logger.info("Converting image data to a base64 data URI")
app.config['DEFAULT_IMAGE_PATH'] = "data:png;base64,{}".format( base64.b64encode(imgdata).decode('utf-8') )
application_logger.info("Done with image conversion")
application_logger.debug("Default image path now set to {}".format(app.config['DEFAULT_IMAGE_PATH']))
if app.config['USE_DATA_URI_FOR_DEFAULT_IMAGE'].lower() == "yes":
application_logger.info("Opening default image for conversion to data URI")
with open(app.config['DEFAULT_IMAGE_PATH'], 'rb') as f:
imgdata = f.read()
application_logger.info("Default image has been opened and stored")
application_logger.info("Converting image data to a base64 data URI")
app.config['DEFAULT_IMAGE_PATH'] = "data:png;base64,{}".format( base64.b64encode(imgdata).decode('utf-8') )
application_logger.info("Done with image conversion")
application_logger.debug("Default image path now set to {}".format(app.config['DEFAULT_IMAGE_PATH']))
application_logger.info("All Configuration successfully loaded for MementoEmbed")
View
@@ -1,3 +1,3 @@
__appname__ = "MementoEmbed"
__appversion__ = '0.2018.10.11.222821'
__appversion__ = '0.2018.10.12.164424'
__useragent__ = "{}/{}".format(__appname__, __appversion__)
View
@@ -79,3 +79,6 @@ ALLOW_SOCIALCARD_DATAURIS_FOR_FAVICONS = "No"
# Default image to use if no other image can be found
DEFAULT_IMAGE_PATH = "mementoembed/static/images/96px-Sphere_wireframe.svg.png"
# Use a data URI for the default image
USE_DATA_URI_FOR_DEFAULT_IMAGE = "Yes"

0 comments on commit 16a31be

Please sign in to comment.