Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ repos:
- id: end-of-file-fixer
- id: check-toml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.14
rev: v0.16.5
hooks:
# Run the linter.
- id: ruff
# Run the formatter.
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.20.2
rev: v2.3.1
hooks:
- id: mypy
files: ^(src/cloudevents/|tests/)
Expand Down
34 changes: 17 additions & 17 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,28 +292,28 @@ class YAMLFormat:
"""Example custom format -- implement the Format protocol."""

def read(
self,
event_factory: EventFactory | None,
data: str | bytes,
) -> BaseCloudEvent:
... # Parse YAML into attributes dict, call event_factory(attributes, data)
self,
event_factory: EventFactory | None,
data: str | bytes,
) -> (
BaseCloudEvent
): ... # Parse YAML into attributes dict, call event_factory(attributes, data)

def write(self, event: BaseCloudEvent) -> bytes:
... # Serialize entire event to YAML bytes
def write(
self, event: BaseCloudEvent
) -> bytes: ... # Serialize entire event to YAML bytes

def write_data(
self,
data: dict | str | bytes | None,
datacontenttype: str | None,
) -> bytes:
... # Serialize just the data payload
self,
data: dict | str | bytes | None,
datacontenttype: str | None,
) -> bytes: ... # Serialize just the data payload

def read_data(
self,
body: bytes,
datacontenttype: str | None,
) -> dict | str | bytes | None:
... # Deserialize just the data payload
self,
body: bytes,
datacontenttype: str | None,
) -> dict | str | bytes | None: ... # Deserialize just the data payload

def get_content_type(self) -> str:
return "application/cloudevents+yaml"
Expand Down
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ import requests
# Create a CloudEvent
# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".
attributes = {
"type": "com.example.sampletype1",
"source": "https://example.com/event-producer",
"type": "com.example.sampletype1",
"source": "https://example.com/event-producer",
}
data = {"message": "Hello World!"}
event = CloudEvent(attributes, data)
Expand All @@ -63,8 +63,8 @@ import requests
# Create a CloudEvent
# - The CloudEvent "id" is generated if omitted. "specversion" defaults to "1.0".
attributes = {
"type": "com.example.sampletype2",
"source": "https://example.com/event-producer",
"type": "com.example.sampletype2",
"source": "https://example.com/event-producer",
}
data = {"message": "Hello World!"}
event = CloudEvent(attributes, data)
Expand Down Expand Up @@ -95,20 +95,20 @@ app = Flask(__name__)
# create an endpoint at http://localhost:/3000/
@app.route("/", methods=["POST"])
def home():
# create a CloudEvent
event = from_http_event(HTTPMessage(dict(request.headers), request.get_data()))
# create a CloudEvent
event = from_http_event(HTTPMessage(dict(request.headers), request.get_data()))

# you can access cloudevent fields as seen below
print(
f"Found {event.get_id()} from {event.get_source()} with type "
f"{event.get_type()} and specversion {event.get_specversion()}"
)
# you can access cloudevent fields as seen below
print(
f"Found {event.get_id()} from {event.get_source()} with type "
f"{event.get_type()} and specversion {event.get_specversion()}"
)

return "", 204
return "", 204


if __name__ == "__main__":
app.run(port=3000)
app.run(port=3000)
```

You can find a complete example of turning a CloudEvent into a HTTP request
Expand Down