# Path: python2.7libs/hpaste/nethelper.py
# def urlopen_nt(req, fallback_cert=0):
# 	# type: (urllib2.Request, int) -> (int, object)
# 	"""
# 	wrapper around urllib2.urlopen that does not throw HTTPError
# 	and does some additional things like falling back on SSL certs
# 	:param req:
# 	:param fallback_cert:  do not use
# 	:return:
# 	"""
# 	code = -1
# 	rep = None
# 	# print req.get_full_url(), req.get_data(), fallback_cert
# 	try:
# 		if fallback_cert == 0:
# 			rep = urllib2.urlopen(req)
# 		elif fallback_cert == 1:
# 			import certifi
# 			rep = urllib2.urlopen(req, cafile=certifi.where())
# 		elif fallback_cert == 2:
# 			import ssl
# 			rep = urllib2.urlopen(req, context=ssl._create_unverified_context())
# 			log("connected with unverified context", 2)
# 	except urllib2.HTTPError as e:
# 		code = e.code
# 		rep = ErrorReply(code, e.headers, e.msg)
# 	except urllib2.URLError as e:
# 		if fallback_cert < 2:
# 			return urlopen_nt(req, fallback_cert+1)
# 		else:
# 			raise
# 
# 	if code == -1:
# 		code = rep.getcode()
# 	return code, rep
# 
# Path: python2.7libs/hpaste/logger.py
# def simpleLogger(s,level=1):
# def passLogger(s,level=1):


import urllib2
import json
import copy
import re
import base64
from ..nethelper import urlopen_nt
from collectionbase import CollectionBase,CollectionItem,CollectionInconsistentError,CollectionSyncError,CollectionItemInvalidError, \
	CollectionReadonlyError
from ..logger import defaultLogger as log
	from PySide2.QtGui import QPixmap
	from PySide2.QtCore import QBuffer, QByteArray
	from PySide.QtGui import QPixmap
	from PySide.QtCore import QBuffer, QByteArray
	from os import path
			return ()

		res=[]
		for gist in gists:
			files=gist['files']
			try:
				del files['00_HPASTE_SNIPPET']
			except KeyError:
				raise CollectionInconsistentError('impossible error! marker lost')
			#if(len(files)!=1):raise CollectionInconsistentError('each gist must have one marker and one file')
			desc=gist['description']
			nettype=''
			if(':' in desc):
				nettype,desc=desc.split(':',1)

			if(len(files)==1): # zero version implementation
				for filename in files:
					filedata=files[filename]
					rawurl=filedata['raw_url']
					retaccess = CollectionItem.AccessType.public if gist['public'] else CollectionItem.AccessType.private
					newitem=CollectionItem(self, filename, desc, '%s@%s'%(gist['id'], filename), retaccess, self.__readonly, metadata={'raw_url':rawurl, 'nettype':nettype, 'ver':(1, 0)})
					res.append(newitem)
			else:
				# first of all check version
				verfiles = [x for x in files if x.startswith("ver:")]
				if len(verfiles) != 1:
					log("skipping a broken collection item, id:%s" % gist['id'], 2)
					continue
				ver = map(lambda x: int(x), verfiles[0].split(':', 1)[1].split('.'))
				if ver[0] != currentVersion[0]:

# Path: python2.7libs/hpaste/nethelper.py
# def urlopen_nt(req, fallback_cert=0):
# 	# type: (urllib2.Request, int) -> (int, object)
# 	"""
# 	wrapper around urllib2.urlopen that does not throw HTTPError
# 	and does some additional things like falling back on SSL certs
# 	:param req:
# 	:param fallback_cert:  do not use
# 	:return:
# 	"""
# 	code = -1
# 	rep = None
# 	# print req.get_full_url(), req.get_data(), fallback_cert
# 	try:
# 		if fallback_cert == 0:
# 			rep = urllib2.urlopen(req)
# 		elif fallback_cert == 1:
# 			import certifi
# 			rep = urllib2.urlopen(req, cafile=certifi.where())
# 		elif fallback_cert == 2:
# 			import ssl
# 			rep = urllib2.urlopen(req, context=ssl._create_unverified_context())
# 			log("connected with unverified context", 2)
# 	except urllib2.HTTPError as e:
# 		code = e.code
# 		rep = ErrorReply(code, e.headers, e.msg)
# 	except urllib2.URLError as e:
# 		if fallback_cert < 2:
# 			return urlopen_nt(req, fallback_cert+1)
# 		else:
# 			raise
# 
# 	if code == -1:
# 		code = rep.getcode()
# 	return code, rep
# 
# Path: python2.7libs/hpaste/logger.py
# def simpleLogger(s,level=1):
# def passLogger(s,level=1):


# Path: python2.7libs/hpaste/hcollections/githubcollection.py
import urllib2
import json
import copy
import re
import base64
from ..nethelper import urlopen_nt
from collectionbase import CollectionBase,CollectionItem,CollectionInconsistentError,CollectionSyncError,CollectionItemInvalidError, \
	CollectionReadonlyError
from ..logger import defaultLogger as log
	from PySide2.QtGui import QPixmap
	from PySide2.QtCore import QBuffer, QByteArray
	from PySide.QtGui import QPixmap
	from PySide.QtCore import QBuffer, QByteArray
	from os import path

			return ()

		res=[]
		for gist in gists:
			files=gist['files']
			try:
				del files['00_HPASTE_SNIPPET']
			except KeyError:
				raise CollectionInconsistentError('impossible error! marker lost')
			#if(len(files)!=1):raise CollectionInconsistentError('each gist must have one marker and one file')
			desc=gist['description']
			nettype=''
			if(':' in desc):
				nettype,desc=desc.split(':',1)

			if(len(files)==1): # zero version implementation
				for filename in files:
					filedata=files[filename]
					rawurl=filedata['raw_url']
					retaccess = CollectionItem.AccessType.public if gist['public'] else CollectionItem.AccessType.private
					newitem=CollectionItem(self, filename, desc, '%s@%s'%(gist['id'], filename), retaccess, self.__readonly, metadata={'raw_url':rawurl, 'nettype':nettype, 'ver':(1, 0)})
					res.append(newitem)
			else:
				# first of all check version
				verfiles = [x for x in files if x.startswith("ver:")]
				if len(verfiles) != 1:
					log("skipping a broken collection item, id:%s" % gist['id'], 2)
					continue
				ver = map(lambda x: int(x), verfiles[0].split(':', 1)[1].split('.'))
				if ver[0] != currentVersion[0]:

					log("unsupported collection item version, id:%s" % gist['id'], 2)