# Path: util.py
# def md5_storage_hash(s):
#   m = md5.new()
#   m.update(s)
#   return m.hexdigest()


import math
import re
import urlparse
import requests
import json
import neat_binary
from threading import Thread, Lock
from util import md5_storage_hash
from redis import StrictRedis
from bs4 import BeautifulSoup
from shove import Shove
  except:
    return dmsfield

def get_fast_image(key):
  # This is not terribly fast, but if the archive's image is not fast,
  # this will load much much faster. If the image is cached, it will load
  # at about the same speed.
  # Pros: faster.
  # Cons: not "official" skymorph post-processing. The initial bytes are the same,
  # but the sharpness/contrast improvements are done by the API, not by NASA.
  storage_key = 'fast_%s' % (md5_storage_hash(key))
  store_mutex.acquire()
  if storage_key in store:
    store_mutex.release()
    return store[storage_key]
  store_mutex.release()
  data = [x for x in key.split('|') if x.strip() != '']
  id = data[0]
  x = float(data[12])
  y = float(data[13])
  width = height = IMAGE_SIZE
  x0 = max(0, x - IMAGE_SIZE/2.)
  y0 = max(0, y - IMAGE_SIZE/2.)
  ret = neat_binary.process_from_internet(id, x0, y0, width, height)
  store_mutex.acquire()
  store[storage_key] = ret
  store_mutex.release()
  return ret

def get_image(key):

# Path: util.py
# def md5_storage_hash(s):
#   m = md5.new()
#   m.update(s)
#   return m.hexdigest()


# Path: skymorph/skymorph.py
import math
import re
import urlparse
import requests
import json
import neat_binary
from threading import Thread, Lock
from util import md5_storage_hash
from redis import StrictRedis
from bs4 import BeautifulSoup
from shove import Shove

  except:
    return dmsfield

def get_fast_image(key):
  # This is not terribly fast, but if the archive's image is not fast,
  # this will load much much faster. If the image is cached, it will load
  # at about the same speed.
  # Pros: faster.
  # Cons: not "official" skymorph post-processing. The initial bytes are the same,
  # but the sharpness/contrast improvements are done by the API, not by NASA.
  storage_key = 'fast_%s' % (md5_storage_hash(key))
  store_mutex.acquire()
  if storage_key in store:
    store_mutex.release()
    return store[storage_key]
  store_mutex.release()
  data = [x for x in key.split('|') if x.strip() != '']
  id = data[0]
  x = float(data[12])
  y = float(data[13])
  width = height = IMAGE_SIZE
  x0 = max(0, x - IMAGE_SIZE/2.)
  y0 = max(0, y - IMAGE_SIZE/2.)
  ret = neat_binary.process_from_internet(id, x0, y0, width, height)
  store_mutex.acquire()
  store[storage_key] = ret
  store_mutex.release()
  return ret

def get_image(key):

  storage_key = 'skymorph_%s' % (md5_storage_hash(key))