Example #1
0
    def test_write_binary_file_hunk(self):
        outfile = self.path('out')
        h = FileHunk(self.path(self.name))
        h.save(outfile)

        with open(outfile, 'rb') as f:
            d = f.read()

        assert isinstance(d, str)
        assert d == self.BINARY_DATA
Example #2
0
    def determine_version(self, bundle, env, hunk=None):
        if not hunk:
            if not has_placeholder(bundle.output):
                hunk = FileHunk(bundle.resolve_output(env))
            else:
                # Can cannot determine the version of placeholder files.
                raise VersionIndeterminableError(
                    'output target has a placeholder')

        hasher = self.hasher()
        hasher.update(hunk.data())
        return hasher.hexdigest()[:self.length]
Example #3
0
    def determine_version(self, bundle, env, hunk=None):
        if not hunk:
            if not has_placeholder(bundle.output):
                hunk = FileHunk(bundle.resolve_output(env))
            else:
                # Can cannot determine the version of placeholder files.
                raise VersionIndeterminableError(
                    'output target has a placeholder')

        hasher = self.hasher()
        hasher.update(hunk.data())
        return hasher.hexdigest()[:self.length]
Example #4
0
    def determine_version(self, bundle, ctx, hunk=None):
        if not hunk:
            from webassets.bundle import has_placeholder
            if not has_placeholder(bundle.output):
                hunk = FileHunk(bundle.resolve_output(ctx))
            else:
                # Can cannot determine the version of placeholder files.
                raise VersionIndeterminableError(
                    'output target has a placeholder')

        hasher = self.hasher()
        hasher.update(hunk.data().encode('utf-8'))
        return hasher.hexdigest()[:self.length]
Example #5
0
File: version.py Project: Alpus/Eth
    def determine_version(self, bundle, ctx, hunk=None):
        if not hunk:
            from webassets.bundle import has_placeholder
            if not has_placeholder(bundle.output):
                hunk = FileHunk(bundle.resolve_output(ctx))
            else:
                # Can cannot determine the version of placeholder files.
                raise VersionIndeterminableError(
                    'output target has a placeholder')

        hasher = self.hasher()
        hasher.update(hunk.data().encode('utf-8'))
        return hasher.hexdigest()[:self.length]
Example #6
0
    def determine_version(self, bundle, env, hunk=None):

        if not hunk and not has_placeholder(bundle.output):
            hunks = [
                FileHunk(bundle.resolve_output(env)),
            ]
        elif not hunk:
            src = sum(map(env.resolver.resolve_source, bundle.contents), [])
            hunks = [
                FileHunk(hunk) for hunk in src + bundle.resolve_depends(env)
            ]
        else:
            hunks = [
                hunk,
            ]

        hasher = self.hasher()
        for hunk in hunks:
            hasher.update(hunk.data())
        return hasher.hexdigest()[:self.length]
Example #7
0
 def open(self, out, source_path, **kw):
     self.templates.append(source_path)
     # Write back or the cache would not detect changes
     out.write(FileHunk(source_path).data())
Example #8
0
s3 = FlaskS3(app)

css_assets = Bundle(
    "normalize.css",
    "skeleton.css",
    "custom.css",
    filters="cssmin",
    output="packed.min.%(version)s.css",
)

assets = Environment(app)
assets.manifest = "json"
assets.register("css_all", css_assets)

if not app.config["ASSETS_DEBUG"]:
    css = FileHunk(css_assets.resolve_output())
    app.jinja_env.globals["css_assets_built"] = css.data()

db_client = DynamoDBClient(app.config.get("DYNAMODB_TABLE"))


def initialise_sentry():
    global sentry_initialised
    if os.environ.get("SENTRY_DSN", "") and not sentry_initialised:
        sentry_sdk.init(
            os.environ.get("SENTRY_DSN"),
            integrations=[
                AwsLambdaIntegration(),
                FlaskIntegration(),
                AioHttpIntegration(),
            ],
Example #9
0
 def test_read_binary_file_hunk(self):
     h = FileHunk(self.path(self.name))
     d = h.data() 
     assert isinstance(d, str)
     assert d == self.BINARY_DATA