• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python backends.client函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中mediasync.backends.client函数的典型用法代码示例。如果您正苦于以下问题:Python client函数的具体用法?Python client怎么用?Python client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了client函数的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testServeRemote

    def testServeRemote(self):
        
        msettings['SERVE_REMOTE'] = False
        self.assertEqual(backends.client().media_url(), '/media')

        msettings['SERVE_REMOTE'] = True
        self.assertEqual(backends.client().media_url(), 'http://s3.amazonaws.com/%s' % self.bucket_name)
开发者ID:JDrosdeck,项目名称:django-mediasync,代码行数:7,代码来源:tests.py


示例2: testServeRemote

    def testServeRemote(self):

        msettings["SERVE_REMOTE"] = False
        self.assertEqual(backends.client().media_url(), "/media")

        msettings["SERVE_REMOTE"] = True
        self.assertEqual(backends.client().media_url(), "http://s3.amazonaws.com/%s" % self.bucket_name)
开发者ID:andymccurdy,项目名称:django-mediasync,代码行数:7,代码来源:tests.py


示例3: testServeRemote

 def testServeRemote(self):
     
     settings.DEBUG = False
     settings.MEDIASYNC['SERVE_REMOTE'] = False
     self.assertEqual(backends.client().media_url(), '/media')
     
     settings.DEBUG = True
     settings.MEDIASYNC['SERVE_REMOTE'] = True
     self.assertEqual(backends.client().media_url(), 'http://mediasync_test.s3.amazonaws.com')
开发者ID:apendleton,项目名称:django-mediasync,代码行数:9,代码来源:tests.py


示例4: testMediaURL

 def testMediaURL(self):
     
     try:
         del settings.MEDIASYNC['SERVE_REMOTE']
     except KeyError:
         pass
         
     settings.DEBUG = True
     self.assertEqual(backends.client().media_url(), '/media')
     
     settings.DEBUG = False
     self.assertEqual(backends.client().media_url(), 'http://mediasync_test.s3.amazonaws.com')
开发者ID:apendleton,项目名称:django-mediasync,代码行数:12,代码来源:tests.py


示例5: sync

def sync(client=None, force=False):
    """ 
    Let's face it... pushing this stuff to S3 is messy. A lot of different 
    things need to be calculated for each file and they have to be in a certain 
    order as some variables rely on others.
    """
    # create client connection
    if client is None:
        client = backends.client()

    client.open()
    client.serve_remote = True

    #
    # sync joined media
    #

    for joinfile, sourcefiles in JOINED.iteritems():
        filedata = combine_files(joinfile, sourcefiles, client)
        if filedata is None:
            # combine_files() is only interested in CSS/JS files.
            continue
        filedata, dirname = filedata

        content_type = mimetypes.guess_type(joinfile)[0] or 'application/octet-stream'

        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)

        if client.process_and_put(filedata, content_type, remote_path, force=force):
            print "[%s] %s" % (content_type, remote_path)

    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):

        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))

        if os.path.isdir(dirpath):

            for filename in listdir_recursive(dirpath):

                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)

                content_type = mimetypes.guess_type(filepath)[0] or 'application/octet-stream'

                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload

                filedata = open(filepath, 'rb').read()

                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    print "[%s] %s" % (content_type, remote_path)

    client.close()
开发者ID:duointeractive,项目名称:django-mediasync,代码行数:60,代码来源:__init__.py


示例6: setUp

 def setUp(self):
     msettings['SERVE_REMOTE'] = True
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = (
         'mediasync.processors.closurecompiler.compile',
     )
     self.client = backends.client()
开发者ID:JDrosdeck,项目名称:django-mediasync,代码行数:7,代码来源:tests.py


示例7: setUp

 def setUp(self):
     msettings['BACKEND'] = 'mediasync.tests.tests'
     msettings['PROCESSORS'] = (
         'mediasync.processors.css_minifier',
         'mediasync.processors.js_minifier',
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
开发者ID:richleland,项目名称:django-mediasync,代码行数:8,代码来源:tests.py


示例8: setUp

 def setUp(self):
     settings.DEBUG = False
     settings.MEDIASYNC = {
         'BACKEND': 'mediasync.backends.s3',
         'AWS_BUCKET': 'mediasync_test',
         'AWS_KEY': os.environ['AWS_KEY'],
         'AWS_SECRET': os.environ['AWS_SECRET'],
     }
     self.client = backends.client()
开发者ID:apendleton,项目名称:django-mediasync,代码行数:9,代码来源:tests.py


示例9: setUp

 def setUp(self):
     msettings["SERVE_REMOTE"] = True
     msettings["BACKEND"] = "mediasync.tests.tests"
     msettings["PROCESSORS"] = (
         "mediasync.processors.slim.css_minifier",
         "mediasync.processors.slim.js_minifier",
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
开发者ID:andymccurdy,项目名称:django-mediasync,代码行数:9,代码来源:tests.py


示例10: sync

def sync(client=None, force=False, verbose=True):
    """ Let's face it... pushing this stuff to S3 is messy.
        A lot of different things need to be calculated for each file
        and they have to be in a certain order as some variables rely
        on others.
    """
    from mediasync import backends
    from mediasync.conf import msettings
    from mediasync.signals import pre_sync, post_sync

    # create client connection
    if client is None:
        client = backends.client()

    client.open()
    client.serve_remote = True

    # send pre-sync signal
    pre_sync.send(sender=client)

    #
    # sync joined media
    #

    for joinfile, sourcefiles in msettings['JOINED'].iteritems():
        
        filedata = combine_files(joinfile, sourcefiles, client)
        if filedata is None:
            # combine_files() is only interested in CSS/JS files.
            continue
        filedata, dirname = filedata

        content_type = mimetypes.guess_type(joinfile)[0] or msettings['DEFAULT_MIMETYPE']

        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)

        if client.process_and_put(filedata, content_type, remote_path, force=force):
            if verbose:
                print "[%s] %s" % (content_type, remote_path)

    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):

        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))

        if os.path.isdir(dirpath):

            for filename in listdir_recursive(dirpath):

                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)

                content_type = mimetypes.guess_type(filepath)[0] or msettings['DEFAULT_MIMETYPE']

                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload

                filedata = open(filepath, 'rb').read()

                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    if verbose:
                        print "[%s] %s" % (content_type, remote_path)
    
    # send post-sync signal while client is still open
    post_sync.send(sender=client)
    
    client.close()
开发者ID:andymccurdy,项目名称:django-mediasync,代码行数:73,代码来源:__init__.py


示例11: setUp

 def setUp(self):
     msettings.PROCESSORS = (
         'mediasync.processors.js_minifier',
         lambda fd, ct, rp, r: fd.upper(),
     )
     self.client = backends.client()
开发者ID:duointeractive,项目名称:django-mediasync,代码行数:6,代码来源:tests.py


示例12: testServeRemote

    def testServeRemote(self):
        msettings.SERVE_REMOTE = False
        self.assertEqual(backends.client().media_url(), '/media')

        msettings.SERVE_REMOTE = True
        self.assertEqual(backends.client().media_url(), 'http://mediasync_test.s3.amazonaws.com')
开发者ID:duointeractive,项目名称:django-mediasync,代码行数:6,代码来源:tests.py


示例13: sync

def sync(client=None, force=False):
    """ Let's face it... pushing this stuff to S3 is messy.
        A lot of different things need to be calculated for each file
        and they have to be in a certain order as some variables rely
        on others.
    """
    
    from django.conf import settings
    from mediasync import backends
    import cStringIO
    
    assert hasattr(settings, "MEDIASYNC")
    
    CSS_PATH = settings.MEDIASYNC.get("CSS_PATH", "").strip('/')
    JS_PATH = settings.MEDIASYNC.get("JS_PATH", "").strip('/')
    
    # create client connection
    if client is None:
        client = backends.client()
        
    client.open()
    client.serve_remote = True

    #
    # sync joined media
    #
    
    joined = settings.MEDIASYNC.get("JOINED", {})
    
    for joinfile, sourcefiles in joined.iteritems():
        
        joinfile = joinfile.strip('/')
        
        if joinfile.endswith('.css'):
            dirname = CSS_PATH
        elif joinfile.endswith('.js'):
            dirname = JS_PATH
        else:
            continue # bypass this file since we only join css and js
        
        buffer = cStringIO.StringIO()
        
        for sourcefile in sourcefiles:
            
            sourcepath = os.path.join(client.media_root, dirname, sourcefile)
            if os.path.isfile(sourcepath):
                f = open(sourcepath)
                buffer.write(f.read())
                f.close()
                buffer.write('\n')        
        
        filedata = buffer.getvalue()
        buffer.close()
        
        content_type = mimetypes.guess_type(joinfile)[0] or 'application/octet-stream'
        
        remote_path = joinfile
        if dirname:
            remote_path = "%s/%s" % (dirname, remote_path)
        
        if client.process_and_put(filedata, content_type, remote_path, force=force):
            print "[%s] %s" % (content_type, remote_path)
    
    #
    # sync static media
    #

    for dirname in os.listdir(client.media_root):
        
        dirpath = os.path.abspath(os.path.join(client.media_root, dirname))
        
        if os.path.isdir(dirpath):
           
            for filename in listdir_recursive(dirpath):
                
                # calculate local and remote paths
                filepath = os.path.join(dirpath, filename)
                remote_path = "%s/%s" % (dirname, filename)
                
                content_type = mimetypes.guess_type(filepath)[0] or 'application/octet-stream'
                
                if not is_syncable_file(os.path.basename(filename)) or not os.path.isfile(filepath):
                    continue # hidden file or directory, do not upload
                
                filedata = open(filepath, 'rb').read()
                
                if client.process_and_put(filedata, content_type, remote_path, force=force):
                    print "[%s] %s" % (content_type, remote_path)
    
    client.close()
开发者ID:strogo,项目名称:django-mediasync,代码行数:90,代码来源:__init__.py


示例14: BaseTagNode

import warnings
from django import template
from django.conf import settings
from django.template.defaultfilters import stringfilter
from mediasync.msettings import CSS_PATH, JS_PATH, DOCTYPE, JOINED, SERVE_REMOTE, EMULATE_COMBO, URL_PROCESSOR, CACHE_BUSTER, USE_SSL
from mediasync import backends

# Instance of the backend you configured in settings.py.
client = backends.client()
MEDIA_URL = client.media_url()
SECURE_MEDIA_URL = client.media_url(with_ssl=True)

register = template.Library()

class BaseTagNode(template.Node):
    """
    Base class for all mediasync nodes.
    """
    def __init__(self, path):
        super(BaseTagNode, self).__init__()
        # This is the filename or path+filename supplied by the template call.
        self.path = path

    def is_secure(self, context):
        """
        Looks at the RequestContext object and determines if this page is
        secured with SSL. Linking unencrypted media on an encrypted page will
        show a warning icon on some browsers. We need to be able to serve from
        an encrypted source for encrypted pages, if our backend supports it.

        'django.core.context_processors.request' must be added to
开发者ID:duointeractive,项目名称:django-mediasync,代码行数:31,代码来源:media.py



注:本文中的mediasync.backends.client函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python factories.AssetFactory类代码示例发布时间:2022-05-27
下一篇:
Python translate._函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap