From ae700d67a4239a62e38dfaa76983b7983d0d9ffb Mon Sep 17 00:00:00 2001 From: Douglas Blank Date: Sat, 28 Jul 2018 15:20:22 -0400 Subject: [PATCH] Set defaults to http/5000 for testing --- activitypub/bson/objectid.py | 2 +- activitypub/manager/base.py | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/activitypub/bson/objectid.py b/activitypub/bson/objectid.py index 5035f4f..eaef673 100644 --- a/activitypub/bson/objectid.py +++ b/activitypub/bson/objectid.py @@ -156,7 +156,7 @@ class ObjectId(object): >>> later = ObjectId.from_datetime(gen_time) >>> result = m.database.activities.find({"_id": {"$lt": later}}) >>> result # doctest: +ELLIPSIS - [{'@context': 'https://www.w3.org/ns/activitystreams', '_id': ObjectId('...'), 'attributedTo': 'alyssa', 'id': 'alyssa/note/$attributedTo/note/$id', 'type': 'Note'}] + [{'@context': 'https://www.w3.org/ns/activitystreams', '_id': ObjectId('...'), 'attributedTo': 'alyssa', 'type': 'Note'}] :Parameters: - `generation_time`: :class:`~datetime.datetime` to be used diff --git a/activitypub/manager/base.py b/activitypub/manager/base.py index cab2ca4..acc37b4 100644 --- a/activitypub/manager/base.py +++ b/activitypub/manager/base.py @@ -104,7 +104,7 @@ class Manager(): >>> note = manager.Note( ... **{'sensitive': False, - ... 'attributedTo': 'http://localhost:5005', + ... 'attributedTo': 'http://localhost:5000', ... 'cc': ['http://localhost:5005/followers'], ... 'to': ['https://www.w3.org/ns/activitystreams#Public'], ... 'content': '

$source.content

', @@ -141,10 +141,11 @@ class Manager(): ## Put dependent ones first: self.defaults = { "$DOMAIN": "$SCHEME://$HOST:$PORT", - "$SCHEME": "https", + "$SCHEME": "http", "$HOST": self.host, "$PORT": self.port, - "$UUID": lambda: str(uuid.uuid4()), + "$UUID4": lambda: str(uuid.uuid4()), + "$UUID": lambda: binascii.hexlify(os.urandom(8)).decode("utf-8"), "$NOW": lambda: (datetime.datetime.utcnow() .replace(microsecond=0).isoformat() + "Z"), } @@ -236,7 +237,7 @@ class Manager(): >>> m = Manager() >>> n = m.Note(attributedTo="alyssa", id="23") >>> n.to_dict() - {'@context': 'https://www.w3.org/ns/activitystreams', 'attributedTo': 'alyssa', 'id': 'alyssa/note/23', 'type': 'Note'} + {'@context': 'https://www.w3.org/ns/activitystreams', 'attributedTo': 'alyssa', 'id': '23', 'type': 'Note'} A default can be a $-variable, or the name of a "Class.field_name". """ @@ -250,7 +251,6 @@ class Manager(): "Person.inbox": "$id/inbox", "Person.outbox": "$id/outbox", "Person.url": "$id", - "Note.id": "$attributedTo/note/$id", } def user_agent(self): @@ -292,7 +292,10 @@ class Manager(): val = self.get_item_from_dotted("ap_" + key[1:], obj) else: raise Exception("expansion requires %s" % key[1:]) - string = string.replace(key, str(val)) + if string == key: + string = val + else: + string = string.replace(key, str(val)) return string def topological_sort(self, data): @@ -300,7 +303,7 @@ class Manager(): >>> manager = Manager() >>> manager.Person(id="alyssa").to_dict() - {'@context': 'https://www.w3.org/ns/activitystreams', 'endpoints': {}, 'followers': 'https://localhost:5000/alyssa/followers', 'following': 'https://localhost:5000/alyssa/following', 'id': 'https://localhost:5000/alyssa', 'inbox': 'https://localhost:5000/alyssa/inbox', 'liked': 'https://localhost:5000/alyssa/liked', 'likes': 'https://localhost:5000/alyssa/likes', 'outbox': 'https://localhost:5000/alyssa/outbox', 'type': 'Person', 'url': 'https://localhost:5000/alyssa'} + {'@context': 'https://www.w3.org/ns/activitystreams', 'endpoints': {}, 'followers': 'http://localhost:5000/alyssa/followers', 'following': 'http://localhost:5000/alyssa/following', 'id': 'http://localhost:5000/alyssa', 'inbox': 'http://localhost:5000/alyssa/inbox', 'liked': 'http://localhost:5000/alyssa/liked', 'likes': 'http://localhost:5000/alyssa/likes', 'outbox': 'http://localhost:5000/alyssa/outbox', 'type': 'Person', 'url': 'http://localhost:5000/alyssa'} """ from functools import reduce # Find all items that don't depend on anything: