Skip to content

Commit

Permalink
feat: replace calls to magic with puremagic
Browse files Browse the repository at this point in the history
  • Loading branch information
the-forest-tree authored and the-forest-tree committed Aug 26, 2024
1 parent 0a47d95 commit 9ecb9cd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 31 deletions.
26 changes: 13 additions & 13 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ boto3 = {version = "^1.24.66", optional = true}
simple-salesforce = "^1.12.4"
typing-extensions = "^4.7.1"
beautifulsoup4 = "4.10.0"
puremagic = "^1.27"

[tool.poetry.dev-dependencies]
pytest = "^6.2"
Expand Down
18 changes: 12 additions & 6 deletions src/hrflow_connectors/connectors/carrevolutis/warehouse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import base64
import typing as t
from io import BytesIO
from logging import LoggerAdapter

import magic
import puremagic
from pydantic import Field

from hrflow_connectors.core import (
Expand All @@ -24,11 +25,16 @@ class ReadProfilesParameters(ParametersModel):


def get_content_type(binary_data: bytes):
mime = magic.Magic(mime=True)
content_type = mime.from_buffer(binary_data)
if not content_type:
return "application/octet-stream"
return content_type
inferred = "application/octet-stream"

try:
results = puremagic.magic_stream(BytesIO(binary_data))
if len(results) > 0:
inferred = results[0].mime_type
except puremagic.PureError:
pass

return inferred


def read(
Expand Down
18 changes: 12 additions & 6 deletions src/hrflow_connectors/connectors/jobology/warehouse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import base64
import typing as t
from io import BytesIO
from logging import LoggerAdapter

import magic
import puremagic
from pydantic import Field

from hrflow_connectors.core import (
Expand All @@ -24,11 +25,16 @@ class ReadProfilesParameters(ParametersModel):


def get_content_type(binary_data: bytes):
mime = magic.Magic(mime=True)
content_type = mime.from_buffer(binary_data)
if not content_type:
return "application/octet-stream"
return content_type
inferred = "application/octet-stream"

try:
results = puremagic.magic_stream(BytesIO(binary_data))
if len(results) > 0:
inferred = results[0].mime_type
except puremagic.PureError:
pass

return inferred


def read(
Expand Down
18 changes: 12 additions & 6 deletions src/hrflow_connectors/connectors/meteojob/warehouse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import base64
import typing as t
from io import BytesIO
from logging import LoggerAdapter

import magic
import puremagic
from pydantic import Field

from hrflow_connectors.core import (
Expand All @@ -24,11 +25,16 @@ class ReadProfilesParameters(ParametersModel):


def get_content_type(binary_data: bytes):
mime = magic.Magic(mime=True)
content_type = mime.from_buffer(binary_data)
if not content_type:
return "application/octet-stream"
return content_type
inferred = "application/octet-stream"

try:
results = puremagic.magic_stream(BytesIO(binary_data))
if len(results) > 0:
inferred = results[0].mime_type
except puremagic.PureError:
pass

return inferred


def read(
Expand Down

0 comments on commit 9ecb9cd

Please sign in to comment.