~jerith/entropy-store/arbitrary-object-id

« back to all changes in this revision

Viewing changes to entropy/util.py

  • Committer: Tristan Seligmann
  • Date: 2009-06-08 05:26:43 UTC
  • Revision ID: mithrandi@mithrandi.za.net-20090608052643-xi55lrco5k4io095
Add some tests for hashing and fix bugs in the error path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from twisted.internet import defer
2
 
from twisted.python.util import mergeFunctionMetadata
3
 
 
4
 
from xmantissa.offering import InstalledOffering
5
 
 
6
 
# XXX: private import, replace with better API ASAP
7
 
# We probably need to wait for Twisted ticket #886 to be closed.
8
 
from twisted.web.client import _makeGetterFactory, HTTPClientFactory, getPage
9
 
 
10
 
 
11
 
def getAppStore(siteStore):
12
 
    """
13
 
    Retrieve the Entropy app store.
14
 
    """
15
 
    offering = siteStore.findUnique(InstalledOffering, InstalledOffering.offeringName == u'Entropy')
16
 
    appStore = offering.application.open()
17
 
    return appStore
18
 
 
19
 
 
20
 
def deferred(f):
21
 
    def _wrapper(*a, **kw):
22
 
        return defer.execute(f, *a, **kw)
23
 
    return mergeFunctionMetadata(f, _wrapper)
24
 
 
25
 
def getPageWithHeaders(uri):
26
 
    """
27
 
    Fetch a resource.
28
 
 
29
 
    This function is only necessary because L{twisted.web.client.getPage} is a
30
 
    really awful API that doesn't give us access to vital response entity
31
 
    headers such as Content-Type.
32
 
    """
33
 
    factory = _makeGetterFactory(str(uri), HTTPClientFactory)
34
 
    return factory.deferred.addCallback(lambda data: (data, factory.response_headers))