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


Python md5.new方法代码示例

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


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

示例1: md5_hexdigest

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def md5_hexdigest(data):
    """
    Returns the md5 digest of the input data
    @param data: data to be digested(hashed)
    @type data: six.binary_type
    @rtype: six.text_type
    """

    if not (data and isinstance(data, six.text_type)):
        raise Exception("invalid data to be hashed: %s", repr(data))

    encoded_data = data.encode("utf-8")

    if not new_md5:
        m = md5.new()  # nosec
    else:
        m = md5()
    m.update(encoded_data)

    return m.hexdigest() 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:22,代码来源:util.py

示例2: __init__

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def __init__(self, channel, sys_impl=sys, fake_clock=None):
        """Creates a new instance.

        @param channel: The channel to use to connect to the server.
        @param sys_impl: The sys module, which holds references to stdin and stdout.  This is only overwritten for
            tests.
        @param fake_clock: The `FakeClock` instance to use to control time and when threads are woken up.  This is only
            set by tests.

        @type channel: RedictorClient.ClientChannel
        @type fake_clock: FakeClock|None
        """
        StoppableThread.__init__(self, fake_clock=fake_clock)
        self.__channel = channel
        self.__stdout = sys_impl.stdout
        self.__stderr = sys_impl.stderr
        self.__fake_clock = fake_clock

    # The number of seconds to wait for the server to accept the client connection. 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:21,代码来源:util.py

示例3: NewFromJsonDict

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def NewFromJsonDict(data):
    '''Create a new instance based on a JSON dict.

    Args:
      data: A JSON dict, as converted from the JSON in the twitter API
    Returns:
      A twitter.Status instance
    '''
    if 'user' in data:
      user = User.NewFromJsonDict(data['user'])
    else:
      user = None
    return Status(created_at=data.get('created_at', None),
                  favorited=data.get('favorited', None),
                  id=data.get('id', None),
                  text=data.get('text', None),
                  in_reply_to_screen_name=data.get('in_reply_to_screen_name', None),
                  in_reply_to_user_id=data.get('in_reply_to_user_id', None),
                  in_reply_to_status_id=data.get('in_reply_to_status_id', None),
                  truncated=data.get('truncated', None),
                  source=data.get('source', None),
                  user=user) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:24,代码来源:twitter.py

示例4: __init__

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def __init__(self,
               username=None,
               password=None,
               input_encoding=None,
               request_headers=None,
               cache=DEFAULT_CACHE):
    '''Instantiate a new twitter.Api object.

    Args:
      username: The username of the twitter account.  [optional]
      password: The password for the twitter account. [optional]
      input_encoding: The encoding used to encode input strings. [optional]
      request_header: A dictionary of additional HTTP request headers. [optional]
      cache: 
          The cache instance to use. Defaults to DEFAULT_CACHE. Use
          None to disable caching. [optional]
    '''
    self.SetCache(cache)
    self._urllib = urllib2
    self._cache_timeout = Api.DEFAULT_CACHE_TIMEOUT
    self._InitializeRequestHeaders(request_headers)
    self._InitializeUserAgent()
    self._InitializeDefaultParameters()
    self._input_encoding = input_encoding
    self.SetCredentials(username, password) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:27,代码来源:twitter.py

示例5: PostDirectMessage

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def PostDirectMessage(self, user, text):
    '''Post a twitter direct message from the authenticated user

    The twitter.Api instance must be authenticated.

    Args:
      user: The ID or screen name of the recipient user.
      text: The message text to be posted.  Must be less than 140 characters.

    Returns:
      A twitter.DirectMessage instance representing the message posted
    '''
    if not self._username:
      raise TwitterError("The twitter.Api instance must be authenticated.")
    url = 'http://twitter.com/direct_messages/new.json'
    data = {'text': text, 'user': user}
    json = self._FetchUrl(url, post_data=data)
    data = simplejson.loads(json)
    self._CheckForTwitterError(data)
    return DirectMessage.NewFromJsonDict(data) 
开发者ID:kuri65536,项目名称:python-for-android,代码行数:22,代码来源:twitter.py

示例6: _GetPath

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def _GetPath(self, key):
        try:
            hashed_key = md5(key.encode('utf-8')).hexdigest()
        except TypeError:
            hashed_key = md5.new(key).hexdigest()

        return os.path.join(self._root_directory,
                            self._GetPrefix(hashed_key),
                            hashed_key) 
开发者ID:doncat99,项目名称:StockRecommendSystem,代码行数:11,代码来源:_file_cache.py

示例7: create_uuid3

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def create_uuid3(namespace, name):
    """
    Return new UUID based on a hash of a UUID namespace and a string.
    :param namespace: The namespace
    :param name: The string
    :type namespace: uuid.UUID
    :type name: six.text
    :return:
    :rtype: uuid.UUID
    """
    return uuid.uuid3(namespace, six.ensure_str(name)) 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:13,代码来源:util.py

示例8: __wait_for_available_bytes

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def __wait_for_available_bytes(self, overall_deadline):
        """Waits for new bytes to become available from the server.

        Raises `RedirectorError` if no bytes are available before the overall deadline is reached.

        @param overall_deadline: The walltime that new bytes must be received by, or this instance will raise
            `RedirectorError`
        @type overall_deadline: float
        @return: True if new bytes are available, or False if the thread has been stopped.
        @rtype: bool
        """
        # For testing purposes, it is important that we capture the time before we invoke `peek`.  That's because
        # all methods that write bytes will advance the clock... so we can tell if there may be new data by seeing
        # if the time has changed since the captured time.
        last_busy_loop_time = self.__time()
        while self._is_running():
            (num_bytes_available, result) = self.__channel.peek()
            if result != 0:
                raise RedirectorError(
                    "Error while waiting for more bytes from redirect server error=%d"
                    % result
                )
            if num_bytes_available > 0:
                return True
            self._sleep_for_busy_loop(
                overall_deadline, last_busy_loop_time, "more bytes to be read"
            )
            last_busy_loop_time = self.__time()
        return False 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:31,代码来源:util.py

示例9: _is_running

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def _is_running(self):
        """Returns true if this thread is still running.
        @return: True if this thread is still running.
        @rtype: bool
        """
        return self._run_state.is_running()

    # The amount of time we sleep while doing a busy wait loop waiting for the client to connect or for new byte
    # to become available. 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:11,代码来源:util.py

示例10: encryptData

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def encryptData(self, encryptKey, privParameters, dataToEncrypt):
        if DES3 is None:
            raise error.StatusInformation(
                errorIndication=errind.encryptionError
                )

        snmpEngineBoots, snmpEngineTime, salt = privParameters
        
        des3Key, salt, iv = self.__getEncryptionKey(
            encryptKey, snmpEngineBoots
            )

        des3Obj = DES3.new(des3Key, DES3.MODE_CBC, iv)
        
        privParameters = univ.OctetString(salt)

        plaintext =  dataToEncrypt + univ.OctetString((0,) * (8 - len(dataToEncrypt) % 8)).asOctets()
        cipherblock = iv
        ciphertext = null
        while plaintext:
            cipherblock = des3Obj.encrypt(
                univ.OctetString(map(lambda x,y:x^y, univ.OctetString(cipherblock).asNumbers(), univ.OctetString(plaintext[:8]).asNumbers())).asOctets()
                )
            ciphertext = ciphertext + cipherblock
            plaintext = plaintext[8:]

        return univ.OctetString(ciphertext), privParameters
        
    # 5.1.1.3 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:31,代码来源:des3.py

示例11: md5digest

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def md5digest(txt):
    return md5.new(txt).hexdigest() 
开发者ID:apple,项目名称:ccs-pycalendar,代码行数:4,代码来源:stringutils.py

示例12: __init__

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def __init__(self, hash_name='md5'):
        self.stream = StringIO()
        pickle.Pickler.__init__(self, self.stream, protocol=2)
        # Initialise the hash obj
        self._hash = md5.new() # hashlib.new(hash_name) # replaced because python 2.4 doesn't support hashlib 
开发者ID:jtamames,项目名称:SqueezeMeta,代码行数:7,代码来源:hashing.py

示例13: change_user_and_rerun_script

# 需要导入模块: from hashlib import md5 [as 别名]
# 或者: from hashlib.md5 import new [as 别名]
def change_user_and_rerun_script(self, description, handle_error=True):
        """Attempts to re-execute the current script as the owner of the configuration file.

        Note, for some platforms, this will result in the current process being replaced completely with the
        new process.  So, this method may never return from the point of the view of the caller.

        @param description: A description of what the script is trying to accomplish.  This will be used in an
            error message if an error occurs.  It will read "Failing, cannot [description] as the correct user".
        @param handle_error:  If True, if the platform controller raises an `CannotExecuteAsUser` error, this
            method will handle it and print an error message to stderr.  If this is False, the exception is
            not caught and propagated to the caller.

        @type description: str
        @type handle_error: bool

        @return: If the function returns, the status code of the executed process.
        @rtype: int
        """
        try:
            script_args = sys.argv[1:]
            script_binary = None
            script_file_path = None

            # See if this is a py2exe executable.  If so, then we do not have a script file, but a binary executable
            # that contains the script.
            if hasattr(sys, "frozen"):
                script_binary = sys.executable
            else:
                # We use the __main__ symbolic module to determine which file was invoked by the python script.
                # noinspection PyUnresolvedReferences
                import __main__  # type: ignore

                # NOTE: Under some scenarios when running in parallel with pytest __file__ attribute
                # won't be set.
                script_file_path = getattr(__main__, "__file__", None)
                if script_file_path and not os.path.isabs(script_file_path):
                    script_file_path = os.path.normpath(
                        os.path.join(self.__cwd, script_file_path)
                    )

            return self.__controller.run_as_user(
                self.__desired_user, script_file_path, script_binary, script_args
            )
        except CannotExecuteAsUser as e:
            if not handle_error:
                raise e
            print(
                "Failing, cannot %s as the correct user.  The command must be executed using the "
                "same account that owns the configuration file.  The configuration file is owned by "
                "%s whereas the current user is %s.  Changing user failed due to the following "
                'error: "%s". Please try to re-execute the command as %s'
                % (
                    description,
                    self.__desired_user,
                    self.__running_user,
                    e.error_message,
                    self.__desired_user,
                ),
                file=sys.stderr,
            )
            return 1 
开发者ID:scalyr,项目名称:scalyr-agent-2,代码行数:63,代码来源:util.py


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