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


Python md5.new方法代码示例

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


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

示例1: initKimmo

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def initKimmo(self, *args):
		"""
		Initialize the Kimmo engine from the lexicon.  This will get called no matter generate
		or recognize.  (i.e. loading all rules, lexicon, and alternations
		"""
	        # only initialize Kimmo if the contents of the *rules* have changed
		tmprmd5 = md5.new(self.rules.get(1.0, Tkinter.END))
		tmplmd5 = md5.new(self.lexicon.get(1.0, Tkinter.END))
		if (not self.kimmoinstance) or (self.rulemd5 != tmprmd5) or (self.lexmd5 != tmplmd5):
			self.guiError("Creating new Kimmo instance")
			self.kimmoinstance = KimmoControl(self.lexicon.get(1.0, Tkinter.END),self.rules.get(1.0, Tkinter.END),'','',self.debug)
			self.guiError("")
			self.rulemd5 = tmprmd5
			self.lexmd5 = tmplmd5

		if not self.kimmoinstance.ok:
			self.guiError("Creation of Kimmo Instance Failed")
			return
		if not self.kimmoinstance.m.initial_state() :
			self.guiError("Morphology Setup Failed")
		elif self.kimmoinstance.errors:
			self.guiError(self.kimmoinstance.errors)
			self.kimmoinstance.errors = ''
		# self.validate() 
开发者ID:rafasashi,项目名称:razzy-spinner,代码行数:26,代码来源:kimmo.py

示例2: __generate

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def __generate(self):
        """Generate a new value for this ObjectId.
        """
        oid = EMPTY

        # 4 bytes current time
        oid += struct.pack(">i", int(time.time()))

        # 3 bytes machine
        oid += ObjectId._machine_bytes

        # 2 bytes pid
        oid += struct.pack(">H", os.getpid() % 0xFFFF)

        # 3 bytes inc
        ObjectId._inc_lock.acquire()
        oid += struct.pack(">i", ObjectId._inc)[1:4]
        ObjectId._inc = (ObjectId._inc + 1) % 0xFFFFFF
        ObjectId._inc_lock.release()

        self.__id = oid 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:23,代码来源:objectid.py

示例3: request

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def request(self, method, request_uri, headers, content):
        """Modify the request headers"""
        keys = _get_end2end_headers(headers)
        keylist = "".join(["%s " % k for k in keys])
        headers_val = "".join([headers[k] for k in keys])
        created = time.strftime('%Y-%m-%dT%H:%M:%SZ',time.gmtime())
        cnonce = _cnonce()
        request_digest = "%s:%s:%s:%s:%s" % (method, request_uri, cnonce, self.challenge['snonce'], headers_val)
        request_digest  = hmac.new(self.key, request_digest, self.hashmod).hexdigest().lower()
        headers['authorization'] = 'HMACDigest username="%s", realm="%s", snonce="%s", cnonce="%s", uri="%s", created="%s", response="%s", headers="%s"' % (
                self.credentials[0],
                self.challenge['realm'],
                self.challenge['snonce'],
                cnonce,
                request_uri,
                created,
                request_digest,
                keylist) 
开发者ID:mortcanty,项目名称:earthengine,代码行数:20,代码来源:__init__.py

示例4: save_wav

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def save_wav(self, chunk_id, model, body, frame_rate):
        checksum = md5.new(body).hexdigest()
        directory = "%s/%s" % (model, checksum[:2])
        self.create_directories_if_needed(self.path + "/" + directory)

        path = '%s/%s/%s.wav' % (self.path, directory, checksum)
        url = '/static/data/%s/%s.wav' % (directory, checksum)

        wav = wave.open(path, 'w')
        wav.setnchannels(1)
        wav.setsampwidth(2)
        wav.setframerate(frame_rate)
        wav.writeframes(body)
        wav.close()

        return (path, url) 
开发者ID:UFAL-DSG,项目名称:cloud-asr,代码行数:18,代码来源:models.py

示例5: md5_init

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def md5_init(data=None):
    """
    Returns md5. This function is implemented in order to encapsulate hash
    objects in a way that is compatible with python 2.4 and python 2.6
    without warnings.

    Note that even though python 2.6 hashlib supports hash types other than
    md5 and sha1, we are artificially limiting the input values in order to
    make the function to behave exactly the same among both python
    implementations.

    :param data: Optional input string that will be used to update the hash.
    """

    try:
        md5_value = hashlib.new("md5")
    except NameError:
        md5_value = md5.new()
    if data:
        md5_value.update(data)
    return md5_value 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:23,代码来源:VirtIoChannel_guest_send_receive.py

示例6: _md5eval

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def _md5eval(data):
    """
    Returns a md5 hash evaluator. This function is implemented in order to
    encapsulate objects in a way that is compatible with python 2.4 and
    python 2.6 without warnings.

    :param data: Optional input string that will be used to update the object.
    """
    try:
        hsh = hashlib.new('md5')
    except NameError:
        hsh = md5.new()
    if data:
        hsh.update(data)

    return hsh 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:18,代码来源:ppm_utils.py

示例7: image_crop_save

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def image_crop_save(image, new_image, box=None):
    """
    Crop an image and save it to a new image.

    :param image: Full path of the original image
    :param new_image: Full path of the cropped image
    :param box: A 4-tuple defining the left, upper, right, and lower pixel coordinate.
    :return: True if crop and save image succeed
    """
    img = Image.open(image)
    if not box:
        x, y = img.size
        box = (x/4, y/4, x*3/4, y*3/4)
    try:
        img.crop(box).save(new_image)
    except (KeyError, SystemError) as e:
        logging.error("Fail to crop image: %s", e)
        return False
    return True 
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:21,代码来源:ppm_utils.py

示例8: _get_bdstoken

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def _get_bdstoken(self):
        if hasattr(self, 'bdstoken'):
            return self.bdstoken

        resp = self._request('GET', 'http://pan.baidu.com/disk/home',
                             '_get_bdstoken')

        html_string = resp.content

        mod = re.search(r'"bdstoken":"(.+?)"', html_string)
        if mod:
            self.bdstoken = mod.group(1)
            return self.bdstoken
        else:
            print s % (1, 91, ' ! Can\'t get bdstoken')
            sys.exit(1)

        # self.bdstoken = md5.new(str(time.time())).hexdigest()

    #def _sift(self, fileslist, name=None, size=None, time=None, head=None, tail=None, include=None, exclude=None): 
开发者ID:PeterDing,项目名称:iScript,代码行数:22,代码来源:pan.baidu.com.py

示例9: GetEmail

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def GetEmail(prompt):
  """Prompts the user for their email address and returns it.

  The last used email address is saved to a file and offered up as a suggestion
  to the user. If the user presses enter without typing in anything the last
  used email address is used. If the user enters a new address, it is saved
  for next time we prompt.

  """
  last_email_file_name = os.path.expanduser("~/.last_codereview_email_address")
  last_email = ""
  if os.path.exists(last_email_file_name):
    try:
      last_email_file = open(last_email_file_name, "r")
      last_email = last_email_file.readline().strip("\n")
      last_email_file.close()
      prompt += " [%s]" % last_email
    except IOError, e:
      pass 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:21,代码来源:upload.py

示例10: create_incident_progression

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def create_incident_progression(anchor,requests,referers,date):

    hash_name = md5.new(str(anchor)).hexdigest()
    file_name = "incident-progression-{0}.json".format(hash_name)
    app_path = Configuration.spot()
    hdfs_path = "{0}/proxy/oa/storyboard/{1}/{2}/{3}"\
    .format(app_path,date.year,date.month,date.day)

    data = {'fulluri':anchor, 'requests':requests,'referer_for':referers.keys()}
    if HDFSClient.put_file_json(data,hdfs_path,file_name,overwrite_file=True) :
        response = "Incident progression successfuly created"
    else:
        return False 
开发者ID:apache,项目名称:incubator-spot,代码行数:15,代码来源:proxy.py

示例11: incident_progression

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def incident_progression(date,uri):

    app_path = Configuration.spot()
    hdfs_path = "{0}/proxy/oa/storyboard/{1}/{2}/{3}".format(app_path,\
        date.year,date.month,date.day)

    hash_name = md5.new(str(uri)).hexdigest()
    file_name = "incident-progression-{0}.json".format(hash_name)

    if HDFSClient.file_exists(hdfs_path,file_name):
        return json.loads(HDFSClient.get_file("{0}/{1}"\
        .format(hdfs_path,file_name)))
    else:
        return {} 
开发者ID:apache,项目名称:incubator-spot,代码行数:16,代码来源:proxy.py

示例12: _get_filename

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def _get_filename(self, key):
        hash = md5(key.encode("utf8")).hexdigest()
        return os.path.join(self._path, hash) 
开发者ID:jojoin,项目名称:cutout,代码行数:5,代码来源:filecache.py

示例13: _generate_addons_file

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def _generate_addons_file( self ):
        # addon list
        addons = sorted(os.listdir( "." ))
        # final addons text
        addons_xml = u"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<addons>\n"
        # loop thru and add each addons addon.xml file
        for addon in addons:
            try:
                # skip any file or .svn folder
                if ( not os.path.isdir( addon ) or addon == ".svn" ): continue
                # create path
                _path = os.path.join( addon, "addon.xml" )
                # split lines for stripping
                xml_lines = open( _path, "r" ).read().splitlines()
                # new addon
                addon_xml = ""
                # loop thru cleaning each line
                for line in xml_lines:
                    # skip encoding format line
                    if ( line.find( "<?xml" ) >= 0 ): continue
                    # add line
                    addon_xml += unicode( line.rstrip() + "\n", "utf-8" )
                # we succeeded so add to our final addons.xml text
                addons_xml += addon_xml.rstrip() + "\n\n"
            except Exception, e:
                # missing or poorly formatted addon.xml
                print "Excluding %s for %s" % ( _path, e, )
        # clean and add closing tag 
开发者ID:tdw1980,项目名称:tdw,代码行数:30,代码来源:addons_xml_generator.py

示例14: _generate_md5_file

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def _generate_md5_file( self ):
        try:
            # create a new md5 object
            m = md5.new()
        except Exception, e:
            print "An error occurred creating md5 object\n%s" % (e, ) 
开发者ID:tdw1980,项目名称:tdw,代码行数:8,代码来源:addons_xml_generator.py

示例15: http_error_302

# 需要导入模块: import md5 [as 别名]
# 或者: from md5 import new [as 别名]
def http_error_302(self, req, fp, code, msg, headers):
        if headers.has_key('location'):
            newurl = headers['location']
        elif headers.has_key('uri'):
            newurl = headers['uri']
        else:
            return
        newurl = urlparse.urljoin(req.get_full_url(), newurl)

        # XXX Probably want to forget about the state of the current
        # request, although that might interact poorly with other
        # handlers that also use handler-specific request attributes
        new = Request(newurl, req.get_data())
        new.error_302_dict = {}
        if hasattr(req, 'error_302_dict'):
            if len(req.error_302_dict)>10 or \
               req.error_302_dict.has_key(newurl):
                raise HTTPError(req.get_full_url(), code,
                                self.inf_msg + msg, headers, fp)
            new.error_302_dict.update(req.error_302_dict)
        new.error_302_dict[newurl] = newurl

        # Don't close the fp until we are sure that we won't use it
        # with HTTPError.
        fp.read()
        fp.close()

        return self.parent.open(new) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:30,代码来源:urllib2.py


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