Esempio n. 1
0
def namespace(**kwargs):
    """Returns a reconciled dictionary of namespace values built from the 
    arguments you provide.

    :param `sharing`: The sharing mode: *system*, *global*, *app*, or *user*
                      (the default is *user*). 
    :param `owner`: The owner context (optional).
    :param `app`: The app context (optional).
    """
    sharing = kwargs.get('sharing', None)
    if sharing in ["system"]:
        return record({
            'sharing': sharing, 
            'owner': "nobody", 
            'app': "system" })
    if sharing in ["global", "app"]:
        return record({ 
            'sharing': sharing, 
            'owner': "nobody", 
            'app': kwargs.get('app', None)})
    if sharing in ["user", None]:
        return record({
            'sharing': sharing, 
            'owner': kwargs.get('owner', None),
            'app': kwargs.get('app', None)})
    raise ValueError("Invalid value for argument: 'sharing'")
Esempio n. 2
0
def namespace(**kwargs):
    """Returns a reconciled dictionary of namespace values built from the 
    arguments you provide.

    :param `sharing`: The sharing mode: *system*, *global*, *app*, or *user*
                      (the default is *user*). 
    :param `owner`: The owner context (optional).
    :param `app`: The app context (optional).
    """
    sharing = kwargs.get('sharing', None)
    if sharing in ["system"]:
        return record({'sharing': sharing, 'owner': "nobody", 'app': "system"})
    if sharing in ["global", "app"]:
        return record({
            'sharing': sharing,
            'owner': "nobody",
            'app': kwargs.get('app', None)
        })
    if sharing in ["user", None]:
        return record({
            'sharing': sharing,
            'owner': kwargs.get('owner', None),
            'app': kwargs.get('app', None)
        })
    raise ValueError("Invalid value for argument: 'sharing'")
Esempio n. 3
0
def _parse_atom_metadata(content):
    # Hoist access metadata
    access = content.get('eai:acl', None)

    # Hoist content metadata (and cleanup some naming)
    attributes = content.get('eai:attributes', {})
    fields = record({
        'required': attributes.get('requiredFields', []),
        'optional': attributes.get('optionalFields', []),
        'wildcard': attributes.get('wildcardFields', [])})

    return record({'access': access, 'fields': fields})
Esempio n. 4
0
def _parse_atom_metadata(content):
    # Hoist access metadata
    access = content.get('eai:acl', None)

    # Hoist content metadata (and cleanup some naming)
    attributes = content.get('eai:attributes', {})
    fields = record({
        'required': attributes.get('requiredFields', []),
        'optional': attributes.get('optionalFields', []),
        'wildcard': attributes.get('wildcardFields', [])
    })

    return record({'access': access, 'fields': fields})
Esempio n. 5
0
 def test_record(self):
     d = data.record()
     d.update({
         'foo': 5,
         'bar.baz': 6,
         'bar.qux': 7,
         'bar.zrp.meep': 8,
         'bar.zrp.peem': 9
     })
     self.assertEqual(d['foo'], 5)
     self.assertEqual(d['bar.baz'], 6)
     self.assertEqual(d['bar'], {
         'baz': 6,
         'qux': 7,
         'zrp': {
             'meep': 8,
             'peem': 9
         }
     })
     self.assertEqual(d.foo, 5)
     self.assertEqual(d.bar.baz, 6)
     self.assertEqual(d.bar, {
         'baz': 6,
         'qux': 7,
         'zrp': {
             'meep': 8,
             'peem': 9
         }
     })
     self.assertRaises(KeyError, d.__getitem__, 'boris')
Esempio n. 6
0
    def request(self, url, message, **kwargs):
        # Record the start time of the request
        time_begin = datetime.now()
        response = self.handler(url, message, **kwargs)
        response = record(response)

        # Record the end time of the request
        time_end = datetime.now()

        if self.debug:
            tracked_request = {
                "url": url,
                "method": message["method"],
                "headers": message["headers"],
                "body": message.get("body", '')
            }

            body = response.body.read()
            tracked_response = {
                "status": response["status"],
                "reason": response["reason"],
                "headers": response["headers"],
                "body": body
            }
            response["body"] = StringIO(body)

            self.tracker.append({
                "time": time_end - time_begin,
                "request": tracked_request,
                "response": tracked_response
            })

        if 400 <= response.status:
            raise HTTPError(response)
        return response
Esempio n. 7
0
    def request(self, url, message, **kwargs):
        # Record the start time of the request
        time_begin = datetime.now()
        response = self.handler(url, message, **kwargs)
        response = record(response)

        # Record the end time of the request
        time_end = datetime.now()

        if self.debug:
            tracked_request = {
                "url": url,
                "method": message["method"],
                "headers": message["headers"],
                "body": message.get("body", ""),
            }

            body = response.body.read()
            tracked_response = {
                "status": response["status"],
                "reason": response["reason"],
                "headers": response["headers"],
                "body": body,
            }
            response["body"] = StringIO(body)

            self.tracker.append(
                {"time": time_end - time_begin, "request": tracked_request, "response": tracked_response}
            )

        if 400 <= response.status:
            raise HTTPError(response)
        return response
Esempio n. 8
0
 def test_record(self):
     d = data.record()
     d.update({'foo': 5,
               'bar.baz': 6,
               'bar.qux': 7,
               'bar.zrp.meep': 8,
               'bar.zrp.peem': 9})
     self.assertEqual(d['foo'], 5)
     self.assertEqual(d['bar.baz'], 6)
     self.assertEqual(d['bar'], {'baz': 6, 'qux': 7, 'zrp': {'meep': 8, 'peem':9}})
     self.assertEqual(d.foo, 5)
     self.assertEqual(d.bar.baz, 6)
     self.assertEqual(d.bar, {'baz': 6, 'qux': 7, 'zrp': {'meep': 8, 'peem':9}})
     self.assertRaises(KeyError, d.__getitem__, 'boris')
Esempio n. 9
0
def _parse_atom_entry(entry):
    title = entry.get('title', None)

    elink = entry.get('link', [])
    elink = elink if isinstance(elink, list) else [elink]
    links = record((link.rel, link.href) for link in elink)

    # Retrieve entity content values
    content = entry.get('content', {})

    # Host entry metadata
    metadata = _parse_atom_metadata(content)

    # Filter some of the noise out of the content record
    content = record((k, v) for k, v in content.iteritems()
                     if k not in ['eai:acl', 'eai:attributes', 'type'])

    return record({
        'title': title,
        'links': links,
        'access': metadata.access,
        'fields': metadata.fields,
        'content': content
    })
Esempio n. 10
0
def _parse_atom_entry(entry):
    title = entry.get('title', None)

    elink = entry.get('link', [])
    elink = elink if isinstance(elink, list) else [elink]
    links = record((link.rel, link.href) for link in elink)

    # Retrieve entity content values
    content = entry.get('content', {})

    # Host entry metadata
    metadata = _parse_atom_metadata(content)

    # Filter some of the noise out of the content record
    content = record((k, v) for k, v in content.iteritems()
        if k not in ['eai:acl', 'eai:attributes', 'type'])

    return record({
        'title': title,
        'links': links,
        'access': metadata.access,
        'fields': metadata.fields,
        'content': content
    })
Esempio n. 11
0
def make_response_record(body, status=200):
    class _MocBufReader(object):
        def __init__(self, buf):
            if isinstance(buf, str):
                self._buf = buf.encode("utf-8")
            else:
                self._buf = buf

        def read(self, size=None):
            return self._buf

    return record({
        "body": binding.ResponseReader(_MocBufReader(body)),
        "status": status,
        "reason": "",
        "headers": None,
    })
Esempio n. 12
0
 def mock_storage_passwords_create(self, password, username, realm=None):
     title = "{}:{}:".format(realm,
                             username) if realm else ":{}:".format(username)
     password = client.StoragePassword(
         None,
         "storage/passwords/{}".format(title),
         state=record({
             "content": {
                 "clear_password": password,
                 "encr_password": hashlib.md5(password.encode()).digest(),
                 "password": "******",
                 "realm": realm,
                 "username": username,
             },
             "title": title,
         }),
     )
     credentials_store[title] = password
     return password
Esempio n. 13
0
def _filter_content(content, *args):
    if len(args) > 0:
        return record((k, content[k]) for k in args)
    return record((k, v) for k, v in content.iteritems()
                  if k not in ['eai:acl', 'eai:attributes', 'type'])
Esempio n. 14
0
 def request(self, url, message, **kwargs):
     response = self.handler(url, message, **kwargs)
     response = record(response)
     if 400 <= response.status:
         raise HTTPError(response) 
     return response
Esempio n. 15
0
 def request(self, url, message, **kwargs):
     response = self.handler(url, message, **kwargs)
     response = record(response)
     if 400 <= response.status:
         raise HTTPError(response)
     return response
Esempio n. 16
0
def _filter_content(content, *args):
    if len(args) > 0:
        return record((k, content[k]) for k in args)
    return record((k, v) for k, v in content.iteritems()
        if k not in ['eai:acl', 'eai:attributes', 'type'])