Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
labnol committed Nov 13, 2013
1 parent d6b548a commit 94dc1ac
Showing 1 changed file with 9 additions and 18 deletions.
27 changes: 9 additions & 18 deletions mirror.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#!/usr/bin/env python
# Copyright 2008 Brett Slatkin
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -104,19 +104,19 @@ def get_by_key_name(key_name):
@staticmethod
def fetch_and_store(key_name, base_url, translated_address, mirrored_url):
"""Fetch and cache a page.
Args:
key_name: Hash to use to store the cached page.
base_url: The hostname of the page that's being mirrored.
translated_address: The URL of the mirrored page on this site.
mirrored_url: The URL of the original page. Hostname should match
the base_url.
Returns:
A new MirroredContent object, if the page was successfully retrieved.
None if any errors occurred or the content could not be retrieved.
"""

logging.debug("Fetching '%s'", mirrored_url)
try:
response = urlfetch.fetch(mirrored_url)
Expand Down Expand Up @@ -154,7 +154,7 @@ def fetch_and_store(key_name, base_url, translated_address, mirrored_url):
if not memcache.add(key_name, new_content, time=EXPIRATION_DELTA_SECONDS):
logging.error('memcache.add failed: key_name = "%s", '
'original_url = "%s"', key_name, mirrored_url)

return new_content

################################################################################
Expand Down Expand Up @@ -209,7 +209,7 @@ def get(self):
class MirrorHandler(BaseHandler):
def get(self, base_url):
assert base_url

# Log the user-agent and referrer, to see who is linking to us.
logging.debug('User-Agent = "%s", Referrer = "%s"',
self.request.user_agent,
Expand Down Expand Up @@ -254,7 +254,7 @@ def get(self, base_url):
entry_point.put()
except (db.Error, apiproxy_errors.Error):
logging.exception("Could not insert EntryPoint")

for key, value in content.headers.iteritems():
self.response.headers[key] = value
if not DEBUG:
Expand All @@ -263,17 +263,8 @@ def get(self, base_url):

self.response.out.write(content.data)


app = webapp2.WSGIApplication([
(r"/", HomeHandler),
(r"/main", HomeHandler),
(r"/([^/]+).*", MirrorHandler)
], debug=DEBUG)


def main():
wsgiref.handlers.CGIHandler().run(app)


if __name__ == "__main__":
main()

0 comments on commit 94dc1ac

Please sign in to comment.