当前位置: 首页>>代码示例>>Python>>正文


Python zlib.html方法代码示例

本文整理汇总了Python中zlib.html方法的典型用法代码示例。如果您正苦于以下问题:Python zlib.html方法的具体用法?Python zlib.html怎么用?Python zlib.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在zlib的用法示例。


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

示例1: get_compression_options

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def get_compression_options(self) -> Optional[Dict[str, Any]]:
        """Override to return compression options for the connection.

        If this method returns None (the default), compression will
        be disabled.  If it returns a dict (even an empty one), it
        will be enabled.  The contents of the dict may be used to
        control the following compression options:

        ``compression_level`` specifies the compression level.

        ``mem_level`` specifies the amount of memory used for the internal compression state.

         These parameters are documented in details here:
         https://docs.python.org/3.6/library/zlib.html#zlib.compressobj

        .. versionadded:: 4.1

        .. versionchanged:: 4.5

           Added ``compression_level`` and ``mem_level``.
        """
        # TODO: Add wbits option.
        return None 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:25,代码来源:websocket.py

示例2: close

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def close(self, code: int = None, reason: str = None) -> None:
        """Closes this Web Socket.

        Once the close handshake is successful the socket will be closed.

        ``code`` may be a numeric status code, taken from the values
        defined in `RFC 6455 section 7.4.1
        <https://tools.ietf.org/html/rfc6455#section-7.4.1>`_.
        ``reason`` may be a textual message about why the connection is
        closing.  These values are made available to the client, but are
        not otherwise interpreted by the websocket protocol.

        .. versionchanged:: 4.0

           Added the ``code`` and ``reason`` arguments.
        """
        if self.ws_connection:
            self.ws_connection.close(code, reason)
            self.ws_connection = None 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:21,代码来源:websocket.py

示例3: read

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def read(self, size):
    # TODO: Update this to use unconsumed_tail and a StringIO buffer
    # http://docs.python.org/2/library/zlib.html#zlib.Decompress.unconsumed_tail
    # Check if we need to start a new decoder
    if self.decoder and self.decoder.unused_data:
      self.restart_decoder()
    # Use unused data first
    if len(self.unused_buffer) > size:
      part = self.unused_buffer[:size]
      self.unused_buffer = self.unused_buffer[size:]
      return part
    # If the stream is finished and no unused raw data, return what we have
    if self.stream.closed or self.finished:
      self.finished = True
      buf, self.unused_buffer = self.unused_buffer, ''
      return buf
    # Otherwise consume new data
    raw = self.stream.read(io.DEFAULT_BUFFER_SIZE)
    if len(raw) > 0:
      self.unused_buffer += self.decoder.decompress(raw)
    else:
      self.finished = True
    return self.read(size) 
开发者ID:Smerity,项目名称:gzipstream,代码行数:25,代码来源:gzipstreamfile.py

示例4: get_compression_options

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def get_compression_options(self):
        """Override to return compression options for the connection.

        If this method returns None (the default), compression will
        be disabled.  If it returns a dict (even an empty one), it
        will be enabled.  The contents of the dict may be used to
        control the following compression options:

        ``compression_level`` specifies the compression level.

        ``mem_level`` specifies the amount of memory used for the internal compression state.

         These parameters are documented in details here:
         https://docs.python.org/3.6/library/zlib.html#zlib.compressobj

        .. versionadded:: 4.1

        .. versionchanged:: 4.5

           Added ``compression_level`` and ``mem_level``.
        """
        # TODO: Add wbits option.
        return None 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:websocket.py

示例5: close

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def close(self, code=None, reason=None):
        """Closes this Web Socket.

        Once the close handshake is successful the socket will be closed.

        ``code`` may be a numeric status code, taken from the values
        defined in `RFC 6455 section 7.4.1
        <https://tools.ietf.org/html/rfc6455#section-7.4.1>`_.
        ``reason`` may be a textual message about why the connection is
        closing.  These values are made available to the client, but are
        not otherwise interpreted by the websocket protocol.

        .. versionchanged:: 4.0

           Added the ``code`` and ``reason`` arguments.
        """
        if self.ws_connection:
            self.ws_connection.close(code, reason)
            self.ws_connection = None 
开发者ID:tp4a,项目名称:teleport,代码行数:21,代码来源:websocket.py

示例6: read

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def read(self, size):
        """
        Check if we need to start a new decoder
        # TODO: Update this to use unconsumed_tail and a StringIO buffer
        http://docs.python.org/2/library/zlib.html#zlib.Decompress.unconsumed_tail
        """
        while self.decoder and self.decoder.unused_data:
            self.restart_decoder()

        # Use unused data first
        if len(self.unused_buffer) > size:
            part = self.unused_buffer[:size]
            self.unused_buffer = self.unused_buffer[size:]
            return part

        # If the stream is finished and no unused raw data, return what we have
        if self.stream.closed or self.finished:
            self.finished = True
            buf, self.unused_buffer = self.unused_buffer, ''
            return buf

        # Otherwise consume new data
        raw = self.stream.read(io.DEFAULT_BUFFER_SIZE)
        if len(raw) > 0:
            self.unused_buffer += self.decoder.decompress(raw)
        else:
            self.finished = True
        return self.read(size) 
开发者ID:qadium-memex,项目名称:CommonCrawlJob,代码行数:30,代码来源:gzipstream.py

示例7: write_pbm

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def write_pbm(matrix, version, out, scale=1, border=None, plain=False):
    """\
    Serializes the matrix as `PBM <http://netpbm.sourceforge.net/doc/pbm.html>`_
    image.

    :param matrix: The matrix to serialize.
    :param int version: The (Micro) QR code version
    :param out: Filename or a file-like object supporting to write binary data.
    :param scale: Indicates the size of a single module (default: 1 which
            corresponds to 1 x 1 pixel per module).
    :param int border: Integer indicating the size of the quiet zone.
            If set to ``None`` (default), the recommended border size
            will be used (``4`` for QR Codes, ``2`` for a Micro QR Codes).
    :param bool plain: Indicates if a P1 (ASCII encoding) image should be
            created (default: False). By default a (binary) P4 image is created.
    """
    row_iter = matrix_iter(matrix, version, scale, border)
    width, height = get_symbol_size(version, scale=scale, border=border)
    with writable(out, 'wb') as f:
        write = f.write
        write('{0}\n'
              '# Created by {1}\n'
              '{2} {3}\n'\
              .format(('P4' if not plain else 'P1'), CREATOR, width, height).encode('ascii'))
        if not plain:
            for row in row_iter:
                write(bytearray(_pack_bits_into_byte(row)))
        else:
            for row in row_iter:
                write(b''.join(str(i).encode('ascii') for i in row))
                write(b'\n') 
开发者ID:a4k-openproject,项目名称:plugin.program.openwizard,代码行数:33,代码来源:writers.py

示例8: check_origin

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def check_origin(self, origin: str) -> bool:
        """Override to enable support for allowing alternate origins.

        The ``origin`` argument is the value of the ``Origin`` HTTP
        header, the url responsible for initiating this request.  This
        method is not called for clients that do not send this header;
        such requests are always allowed (because all browsers that
        implement WebSockets support this header, and non-browser
        clients do not have the same cross-site security concerns).

        Should return ``True`` to accept the request or ``False`` to
        reject it. By default, rejects all requests with an origin on
        a host other than this one.

        This is a security protection against cross site scripting attacks on
        browsers, since WebSockets are allowed to bypass the usual same-origin
        policies and don't use CORS headers.

        .. warning::

           This is an important security measure; don't disable it
           without understanding the security implications. In
           particular, if your authentication is cookie-based, you
           must either restrict the origins allowed by
           ``check_origin()`` or implement your own XSRF-like
           protection for websocket connections. See `these
           <https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html>`_
           `articles
           <https://devcenter.heroku.com/articles/websocket-security>`_
           for more.

        To accept all cross-origin traffic (which was the default prior to
        Tornado 4.0), simply override this method to always return ``True``::

            def check_origin(self, origin):
                return True

        To allow connections from any subdomain of your site, you might
        do something like::

            def check_origin(self, origin):
                parsed_origin = urllib.parse.urlparse(origin)
                return parsed_origin.netloc.endswith(".mydomain.com")

        .. versionadded:: 4.0

        """
        parsed_origin = urlparse(origin)
        origin = parsed_origin.netloc
        origin = origin.lower()

        host = self.request.headers.get("Host")

        # Check to see that origin matches host directly, including ports
        return origin == host 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:57,代码来源:websocket.py

示例9: check_origin

# 需要导入模块: import zlib [as 别名]
# 或者: from zlib import html [as 别名]
def check_origin(self, origin):
        """Override to enable support for allowing alternate origins.

        The ``origin`` argument is the value of the ``Origin`` HTTP
        header, the url responsible for initiating this request.  This
        method is not called for clients that do not send this header;
        such requests are always allowed (because all browsers that
        implement WebSockets support this header, and non-browser
        clients do not have the same cross-site security concerns).

        Should return True to accept the request or False to reject it.
        By default, rejects all requests with an origin on a host other
        than this one.

        This is a security protection against cross site scripting attacks on
        browsers, since WebSockets are allowed to bypass the usual same-origin
        policies and don't use CORS headers.

        .. warning::

           This is an important security measure; don't disable it
           without understanding the security implications. In
           particular, if your authentication is cookie-based, you
           must either restrict the origins allowed by
           ``check_origin()`` or implement your own XSRF-like
           protection for websocket connections. See `these
           <https://www.christian-schneider.net/CrossSiteWebSocketHijacking.html>`_
           `articles
           <https://devcenter.heroku.com/articles/websocket-security>`_
           for more.

        To accept all cross-origin traffic (which was the default prior to
        Tornado 4.0), simply override this method to always return true::

            def check_origin(self, origin):
                return True

        To allow connections from any subdomain of your site, you might
        do something like::

            def check_origin(self, origin):
                parsed_origin = urllib.parse.urlparse(origin)
                return parsed_origin.netloc.endswith(".mydomain.com")

        .. versionadded:: 4.0

        """
        parsed_origin = urlparse(origin)
        origin = parsed_origin.netloc
        origin = origin.lower()

        host = self.request.headers.get("Host")

        # Check to see that origin matches host directly, including ports
        return origin == host 
开发者ID:tp4a,项目名称:teleport,代码行数:57,代码来源:websocket.py


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