-
Notifications
You must be signed in to change notification settings - Fork 65
Adding Fix and Unit tests for UTF-8 Breakages #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4359808
aaa013e
72082ea
f39b84f
3a348c0
84eb5f8
25fe5ff
30c8693
996cf2f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,11 @@ | ||
| from snowplow_tracker._version import __version__ | ||
| from snowplow_tracker.subject import Subject | ||
| from snowplow_tracker.emitters import logger, Emitter, AsyncEmitter, CeleryEmitter, RedisEmitter | ||
| from snowplow_tracker.emitters import Emitter, AsyncEmitter, CeleryEmitter, RedisEmitter | ||
| from snowplow_tracker.self_describing_json import SelfDescribingJson | ||
| from snowplow_tracker.tracker import Tracker | ||
| from contracts import disable_all as disable_contracts, enable_all as enable_contracts | ||
| import logging | ||
|
|
||
| # Set default logging handler to avoid "No handler found" warnings. | ||
| logging.getLogger(__name__).addHandler(logging.NullHandler()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,6 @@ | |
| from snowplow_tracker.self_describing_json import SelfDescribingJson | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
| logger.setLevel(logging.INFO) | ||
|
|
||
| DEFAULT_MAX_LENGTH = 10 | ||
| PAYLOAD_DATA_SCHEMA = "iglu:com.snowplowanalytics.snowplow/payload_data/jsonschema/1-0-4" | ||
|
|
@@ -52,16 +51,6 @@ | |
|
|
||
| new_contract("redis", lambda x: isinstance(x, (redis.Redis, redis.StrictRedis))) | ||
|
|
||
| try: | ||
| # Check whether a custom Celery configuration module named "snowplow_celery_config" exists | ||
| import snowplow_celery_config | ||
| app = Celery() | ||
| app.config_from_object(snowplow_celery_config) | ||
|
|
||
| except ImportError: | ||
| # Otherwise configure Celery with default settings | ||
| app = Celery("Snowplow", broker="redis://guest@localhost//") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what was the motivation behind this? |
||
|
|
||
|
|
||
| class Emitter(object): | ||
| """ | ||
|
|
@@ -172,7 +161,6 @@ def reached_limit(self): | |
| else: | ||
| return self.bytes_queued >= self.byte_limit or len(self.buffer) >= self.buffer_size | ||
|
|
||
| @task(name="Flush") | ||
| def flush(self): | ||
| """ | ||
| Sends all events in the buffer to the collector. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,15 +78,15 @@ def add_json(self, dict_, encode_base64, type_when_encoded, type_when_not_encode | |
| """ | ||
|
|
||
| if dict_ is not None and dict_ != {}: | ||
|
|
||
| json_dict = json.dumps(dict_, ensure_ascii=False) | ||
|
|
||
| if encode_base64: | ||
| encoded_dict = base64.urlsafe_b64encode(json_dict.encode("ascii")) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PR doesn't solve the issue #194 in my local tests Simply changing the encoding on this line to |
||
| if not isinstance(encoded_dict, str): | ||
| try: | ||
| encoded_dict = base64.urlsafe_b64encode(json_dict) | ||
| if not isinstance(encoded_dict, str): | ||
| encoded_dict = encoded_dict.decode("utf-8") | ||
| except UnicodeDecodeError: | ||
| encoded_dict = encoded_dict.decode("utf-8") | ||
| self.add(type_when_encoded, encoded_dict) | ||
|
|
||
| self.add(type_when_encoded, encoded_dict) | ||
| else: | ||
| self.add(type_when_not_encoded, json_dict) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,7 +53,7 @@ | |
| """ | ||
|
|
||
|
|
||
| class Tracker: | ||
| class Tracker(object): | ||
|
|
||
| new_contract("not_none", lambda s: s is not None) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change the existing logging?